Artificial Intelligence
7 mins

Prompt Engineering - Improving AI Responses Through Better Prompts

Prompt engineering is critical for eliciting useful responses from large language models like ChatGPT. Using clear instructions, providing context, and asking follow-up questions help improve the AI responses.

Large language models like ChatGPT have exploded in popularity recently. These models can generate amazingly human-like text when prompted correctly. But getting useful responses out of them requires careful prompt engineering. In this post, we'll explore what prompt engineering is and why it's become so important for improving AI capabilities.

What is Prompt Engineering?

Prompt engineering refers to the process of crafting the prompts fed into large language models. A well-designed prompt acts like instructions for the AI, guiding it to generate the desired output. Prompt engineering involves techniques like:

  • Using clear, simple language
  • Providing relevant context and examples
  • Asking follow-up questions to refine the response

The goal is to prime the model to continue in the right direction and produce accurate, relevant responses.

Why Prompt Engineering Matters

With the right prompts, large language models can pull information from their vast training data and conversational abilities. But without proper prompting, their responses may be nonsensical or unreliable.

Prompt engineering is becoming crucial for unlocking these models' true potential. However, there are still challenges around consistency. The same request can elicit different responses depending on how the prompt is phrased. Without proper prompting, large language models' responses may be nonsensical or unreliable, failing to provide useful information. More research is needed to make models robust across different prompt formulations.

Exciting Research Areas

Some exciting areas of prompt engineering research include:

1. Few-shot learning

Few shot learning involves providing a prompt containing a few examples that demonstrate a new task, allowing models to learn from just a small number of demonstrations. This differs from Zero-shot learning (providing a prompt without any examples to teach a completely new task or skill) or One-shot learning (giving just a single demonstration example in the prompt to learn a new task). In few shot learning a few conversational exchanges could teach a model how to summarize dialogues much better than zero or one shot learning can.

Example:

Prompt: Here are two conversations with summaries:

Conversation 1:Person 1: Hello! How are you today?Person 2: I'm doing great thanks! How about yourself?Person 1: I'm also good. Did you have a nice weekend?Person 2: Yes it was great thanks, very relaxing. How was yours?Summary: Two people have a brief pleasant conversation about their weekends.

Conversation 2:
Person 1: Ugh I'm so stressed about this project at work.
Person 2: Oh no, what's the project? Maybe I can help.
Person 1: It's this big presentation I have to put together by Friday. I don't know how I'll get it done in time.
Person 2: You've got this! Just take it one step at a time.
Summary: One person is stressed about completing a work project and the other provides encouragement.

Please summarize this conversation:
Person 1: Did you watch the big game last night?
Person 2: Yes it was incredible! I can't believe they pulled off that last minute score.

2. Compositional prompting

Here multiple instructions are combined in a single prompt to have the model exhibit different skills in one response. You could ask a model to summarize a text from a specific perspective, in a particular tone or in multiple languages by composing those directives in the prompt.

Example:

Prompt: Please summarize this text from the perspective of an excited sports announcer:[insert text about the 5th Ashes Test at The Oval]

3. Incorporating reasoning

Some models can now generate chains of logic leading to their final response when prompted, showing their reasoning process. This makes it seem like the model is "thinking out loud" before answering and helps improve the quality of the answer.

Example:

Prompt: What is the capital of France? Please provide your step-by-step reasoning.

Response:

Step 1: France is located in Europe.
Step 2: As one of the largest and most influential European countries, France is likely to have a well-known capital city.
Step 3: From my knowledge, the famous city of Paris is located in France.
Step 4: Prominent European capitals like London and Rome are the largest cities in their respective countries.
Step 5: Therefore, given Paris is the largest and most notable city in France, it is likely to be the French capital.

The capital of France is Paris.

4. Adding linguistic structure

Prompts can reference syntactic features like sentence structure or document elements like section headings to provide more context for the AI. Models can be trained to understand these relationships between words.

Example : 

Prompt: The following travel blog post is organized with subheadings. Please summarize the key points made in each section:

Introduction Asia is the largest and most populous continent on Earth. It contains over 4.5 billion people spread across 49 countries. There is immense diversity across Asia in terms of language, culture, religion, geography, and history. Traveling around Asia is an enriching way to experience this diversity.

Transportation Public transportation systems make it easy to get around major Asian cities without a car. High speed rail networks in countries like China, Japan, and South Korea provide efficient travel between cities and regions. Budget airlines offer affordable short-haul flights connecting many parts of Southeast Asia.

Food Asian cuisine is world-famous for dishes like ramen, dumplings, curries, noodles, and dim sum. Street food is ubiquitous, delicious, and very inexpensive. Thailand, Singapore, Malaysia, and Taiwan are considered some of the best food destinations in Asia. Night markets offer a wide array of snacks and local specialties.

Lodging Hostels provide cheap, social lodging for backpackers across Asia. Capsule hotels offer compact, affordable rooms. Guesthouses and homestays enable a local cultural experience. High-end hotels can be found in major metropolises and tourist hotspots.

Response:

Introduction - Asia has immense cultural, geographic, and historical diversity that makes it an enriching travel destination.

Transportation - Public transit and high speed rail make getting around Asia efficient and affordable.

Food - Famous for street food and dishes like noodles, Asia offers exceptional culinary experiences.

Lodging - Accommodation options range from hostels to luxury hotels.

The Future of Prompt Engineering

As large language models continue to advance, prompt engineering will only grow more critical. Developing the expertise to effectively prompt AI has often been likened to "writing code" for these systems. Striking the right balance of manual and automated prompting will be key going forward. For instance, a prompt could inform the model that a passage is organised into paragraphs discussing different topics. This added structure helps the AI grasp the overall meaning and relationships within the text.

Moving forward, striking the right balance between human-crafted prompts and more automated prompt optimization techniques will be key. Mastering prompt engineering is the next step in leveraging the knowledge stored in our most capable AI systems.

October 10, 2023

Read our latest

Blog posts