Prompting

Every now and then we can find new news about generative artificial intelligence (generative AI). Much of this is due to the so-called Large Language Models (LLM), which are transforming the technology landscape.

In order to use these models, we usually have some mechanism to introduce the commands to be executed by the model, which is called prompting. Prompting is the process of providing an input (or ‘prompt’) to a language model to obtain a desired output. In other words, it is the command we send to the model to interpret and act. Far from being straightforward, prompting can become an art and is crucial to maximizing the effectiveness of LLMs and sometimes requires a deep understanding of how language models work and how they interpret different types of input.

Apart from prompt, other words we may encounter are:

Prompt engineering: is the practice of working at the prompt until we get what we are looking for in the format we are looking for and for this we have different “tools”.

Prompt template: refers to when we use templates, usually in file format, containing examples of how we want to get the result later, usually working with single-shot or few-shop techniques that we will see later. It is like training the model, to teach it how we want to obtain the result.

Syntax Hacking: depending on the model used, we will see that the answers obtained vary if we use certain words or synonyms of these. Even depending on the language used, the models may respond in different ways. Working on how the question is phrased can vary a lot the answer. We will see examples later.

Zero-shot: these are prompts where we ask directly what we want to obtain, without giving further explanations or examples (hence the name). They are useful for simple questions or questions that do not require a specific format, although it is advisable to take into account some aspects that we will discuss later. Some examples could be: What is the recipe for paella? What are the names of the bones of the hand?

Single-shot: In this case, we give clues to the type of answer we expect, we give context by giving an example, e.g.

Prompt: "Describe the following object: 'apple' as a round, often red or green fruit that grows on trees and is edible. Now, describe: 'banana'."

Model response: "Banana is an elongated, curved fruit, usually yellow when ripe, that can be peeled and eaten."

Few-shot: This is similar to Single-shot but with prompt we give you more than one example.

Prompting techniques

Using any of the following techniques we can adjust the answers offered by the model in our favor:

Technique 1: Direct and specific questions.

Description: A common prompting technique is to ask direct and specific questions of the model. Language models are often most effective at providing useful answers when the question is clear and detailed.

Practical Example: Instead of asking “tell me about photosynthesis,” one might ask “what is the detailed chemical process of photosynthesis?”

Technique 2: Keyword use

Description: Incorporating relevant keywords into the prompt can help guide the model toward generating a more focused and relevant response.

Practical Example: Instead of saying “I need help with school,” use specific keywords such as “I need help with my math homework on quadratic equations.”

Technique 3: Providing context

Description: Giving clear and concise context can be extremely beneficial in eliciting more accurate responses.

Practical Example: Instead of asking “explain math to me,” provide context: “explain how to do division for an 11-year-old to understand.”

Technique 4: Limiting the scope of the response

Description: Limiting the scope of the response can be useful for more specific information.

Practical Example: Instead of asking “tell me about the universe”, you can ask “tell me about the structure of the solar system”.

How prompting affects results

Prompting affects not only the relevance of the response, but also other factors such as the length and complexity of the generated text. A clear and specific prompt can help elicit a concise and to-the-point response, while a vague or ambiguous prompt can lead to long and confusing responses.

Comparing well-constructed prompts with poorly constructed prompts can provide a clear understanding of how small modifications to the input can make a big difference.

Example:

Bad Prompt: “Tell me some history.”

Good Prompt: “Explain the importance of the Treaty of Versailles in World War I.”

The good prompt here is specific, direct, and contains relevant keywords and context, guiding the model to a more accurate and useful response.

Understanding how slight changes in prompts can affect responses is crucial to optimizing the use of language models. Specificity, context, tone, clarity and other factors play a significant role in determining the nature and usefulness of the response generated by models such as ChatGPT. This knowledge is essential for those seeking to extract maximum value from these advanced language models.It is important to keep in mind that while changes in prompts can improve the accuracy and relevance of responses, they can also limit the scope of the response and exclude potentially valuable information. Finding a balance between specificity and comprehensiveness is essential to obtain the best possible response.

By changing a single word in a prompt, results can vary dramatically.

Example:

Prompt 1: “Tell me a children’s story.”

Prompt 2**: “Tell me a horror story for children”. The resulting stories will have completely different tones and content due to the change of a single word.

Let’s look at some cases of prompts and how we could adjust them to improve the answers(I encourage the reader to try the prompts with their favorite models and see how they react to each of them):

Case 1: Specificity in the questions

Example:

Prompt 1: “Can you tell me about Albert Einstein?”

Prompt 2: “Can you tell me about Albert Einstein’s contributions to theoretical physics?”

In the first case, the answer will probably include a wide range of information about Einstein, including his personal life, education, and career. In contrast, the second prompt focuses the question on a specific area, Einstein’s contributions to theoretical physics, which will likely result in a more technical and detailed answer about his theories and discoveries in that field.

Case 2: Change in question formulation.

Example:

Prompt 1: “How can I improve my writing?”

Prompt 2: “Can you give me some practical exercises to improve my writing?”

Both prompts seek to improve writing, but the first is more general and could generate a variety of tips and techniques. The second, however, specifically asks for practical exercises, which will direct the response toward a list of specific activities and tasks to improve writing.

Case 3: Additional context in the prompt.

Example:

Prompt 1: “Tell me about the whales.”

Prompt 2: “Tell me about whale communication.”

Adding additional context, such as “communication between” at the second prompt, drastically changes the focus of the response. Instead of a general description about whales, the model will provide specific information about how whales communicate with each other.

Case 4: Changes in prompt tone.

Example:

Prompt 1: “Tell me a historical fact.”

Prompt 2: “Tell me a funny historical fact.”

The change in tone from neutral to looking for something “funny” may also affect the model’s response. In the second case, the response will be oriented to historical facts that have an element of humor or curiosity.

Case 5: Clarity and accuracy

Example:

Prompt 1: “Help with plants.”

Prompt 2: “I need help choosing suitable plants for a garden in an arid climate.”

Clarity and precision in the prompt are crucial. The first prompt is ambiguous and could generate a variety of plant-related responses. The second prompt is clear and specific, ensuring a useful and relevant answer on how to choose plants for an arid climate.

Case 6: Temporal specificity.

Example:

Prompt 1: “Tell me about the evolution of telephones.”

Prompt 2: “Tell me about the evolution of telephones in the 1980s.”

Temporal specificity, as shown in the second prompt, will direct the response toward phones developed and used in the 1980s, providing a more focused response on that era.

As we can see, depending on how the commands are formulated, the responses can vary drastically, so it is advisable to know the specificities of each model and how they react to each of the commands we give them.