Basics of LLMs

Large Language Models (LLMs) like ChatGPT have gained rapidly in popularity since ChatGPT was made public at the end of 2022. Since then the fundamental technology behind LLMs, specifically the ability to converse with the user using ‘natural language’ (languages used by humans rather than by computer systems), have made the technology more accessible and has expanded the functionalities.

How do LLMs function

LLMs operate based on word association within a given context. This means that the more training data is available on a given subject, the clearer these associations can be quantified. These associations are quantified using statistics, allowing the model to determine the most likely word to occur next in a text, based on the existing text (the context) and its training data. For example, the word ‘lion’ is likely to be associated with the word ‘king’ when asking a question about wildlife, as a lion is often referred to as the ‘king of the jungle’. However, if a question is asked about zoos, the more likely word association would be with the word ‘captivity’, as that is more likely to occur in that context. The result is that these models predict the most likely combination of words, regardless of whether the information this collection of words represents is true. In short, they have no innate understanding of the meaning behind the words and no understanding of what is true or false, only what is likely or unlikely.

How to ask the perfect question

prompt engineering noun COMPUTING:

The process of designing prompts (= instructions giving to an artificial intelligence by a human using natural language rather than computer language) that will give the best possible results or answers.

Choosing the right words, providing the right amount of context, and emphasizing the right part of the prompt is crucial. This is what's called 'prompt engineering'. In the following sections, we provide some tips on how to better engineer your prompts to LLMs. Of course, what makes a prompt 'good' depends on the task, and on the model - these are some basic concepts. If you're looking for tips on how to prompt image generators, see here.

Basic Tips

Length and Precision

To start, two terms are important:tokensandcontext length. Tokens are the individual words or punctuation marks a LLM breaks text up into, in order to understand it in its statistical way. Context length is the amount of tokens a LLM can remember at once. (For example, if a LLM's context length is 15.000, it can remember 15.000 words and punctuation marks before it begins to forget some.) Often this context length includes both input and output. Because of this, it is important to keep prompts efficient to keep up as little of the context length as possible; make them too long, and the quality of the output diminishes. Writing efficient prompts might also make the model run faster. However, make sure to not make your prompts 'too' efficient, since important information that makes the model understand your prompt better might be missing.

Besides modifying the input length, it is also possible to modify the length of a LLM's output. LLMs are inherently poor at mathematics, as they only understand associations between words, and not how to apply mathematics to these words or interact with these words numerically. Hence, specifying a certain text length (e.g. a word count) might not produce the result you want. Instead, you could try using words like 'concisely' or 'extensively', or to provide a 'Top 10' of answers (which works acceptably well as this is a rather standardized ‘top’ length).

Clarity

Because LLMs don't have an inherent understanding of meaning, it might be helpful to use more specific words, since they can less easily be misinterpreted. For example, you might ask a model about 'domestic dogs' instead of just 'dogs' if you're only interested in the pet kind. In addition, the output will be improved by outlining what type of response you're looking for.

Vague prompt: “Tell me about dogs.”

Clear prompt: “Provide a detailed description of the characteristics, behaviour, and care required for domestic dogs.”

When submitting a text to be translated or summarized to a LLM, also ensure that there is a clear separation between the prompt and the text to be translated or summarized. This way you avoid the model misunderstanding what should be considered the instruction and what is to be considered the ‘object’.

Context

Besides specifying the output wanted, it can also be helpful to clarify the input provided.

Vague prompt: “Translate the following text: ‘Hello, how are you?’”

Clear prompt: “Translate the following text from English to French: ‘Hello, how are you?’”

In the first example above, the desired output is clear: we want a translation of the sentence provided. However, context is missing on the language the sentence is in, and what language we want to translate it to.

This contextualising of input becomes especially important now that LLMs are developing and are gaining access to more information sources. For example, if we upload an Excel file and want a model to analyse some information from it, it is important that it understands the file's content (e.g., what do the columns represent, what are the units). Properly labelling your data within your files and ensuring they are well-organised also improves the understanding a LLM has of your data.

Role-play and audiences

One tip we give to responsibly use a LLM is to use it as a study buddy. These models are quite good at modifying the style of their output to match a certain role they're given. In the example below we introduce the role (‘tutor’), the tone (‘friendly’) and the personality (‘helpful’) in the prompt, as well as the context (‘field of genetics’) and the level of difficulty (‘university’). Each of these instructions modifies the model and directs it to a certain section of its training data, increasing the accuracy and usefulness of the model for the task set.

Example: “You are a friendly and helpful tutor in the field of genetics at a university. Can you explain the process of mitosis to me?”

Besides giving the model a role, you could modify its output by specifying a target audience.

Example: “Explain the concept of circular agriculture, using words a 12-year old can understand.”

Highlighting specific information

There are two ways to ensure a greater weight is given to the most important information or instructions from your prompt. You could use capital letters ('tell me about DOMESTIC dogs'), or pay attention to the order of your paragraph. As humans we pay most attention to the first and last sentences, and as LLMs are trained on human data a LLM tends to do the same. Therefore, it might help to repeat the most important instructions on e.g. text length at both the start and the end of the prompt.

Using custom instructions

In ChatGPT, you can set specific instructions for your account. You can provide information about you as a user, and about the tone and role of ChatGPT in its output. This can help improve the context and style of responses. This feature can be found in the account settings, and when enabled apply the concept of a clear context and role-playing to any subsequent conversation with ChatGPT.

Advanced tips

Providing examples

Sometimes it is helpful to provide a model with some extra 'training data' by giving an example of the type of output you expect. Providing one example is called 'one-shot prompting'. In 'few-shot prompting', you provide multiple examples.

Example prompt: “The slogan for McDonalds is ‘I’m Loving It’. What could be a slogan for Wageningen University?”

Chain-of-thought prompting

LLMs are currently still lacking a strong reasoning capacity, e.g. in logic puzzles. One way of increasing your chances of getting an accurate output is by asking about their chain of thought. For example, you could add a sentence like “Explain your reasoning step-by-step”. This forces the model to split the main task up into smaller sections, reducing the context length per task and increasing the accuracy. The effect of this method is only limited, however.

Reflection

A final technique you could apply is reflection. If, after providing clear and precise instructions, the output is not what you expect, you might ask the model to evaluate its own output based on the original prompt given. Adding a sentence like “Could you verify that your output matches all the criteria from the previous prompt, and correct the output if it is found not to be in agreement?” could improve the output's accuracy.