Published: Jun 15, 2023

Be clear and specific in your instructions

One of the most fundamental lessons we glean from programming and interacting with computers is the importance of clarity and specificity in instructions. Computers require precise directions—a fact that often dawns on us as a revelation in a well-structured computer science course. This principle is amusingly and brilliantly demonstrated in the Harvard CS50 Course here.

The next few sections give you tips and techniques to make your prompts clearer and more precise, followed by some real examples you can try.

An LLM Is Not a Human

In human communication, we value brevity; language is often clearer when succinct, and verbiage is generally considered a detriment to style. However, this doesn’t hold true when we communicate and provide instructions to machines. Here, it’s essential to describe tasks with rich detail.

For instance, consider the case where you ask a language model to “write a short text about xy.” In such situations, providing a specific word count or indicating the number of sentences can make a world of difference. ‘Short’ is a relative term; without precise specifications, the generated text might be too short or longer than intended. Be explicit. If you require a specific writing style, describe it clearly, specifying the desired tone and language for the output text. Yes, it will require some experimentation, but that’s an integral part of any engineering process (see Test and Refine).

Now, you wouldn’t typically provide exhaustive instructions detailing every step of a task to another person—at least, not if you’re reasonable. They might think you’ve lost your marbles. But a Language Learning Model (LLM) or a general generative model thrives on detailed instructions, which it can follow meticulously.

Bear in mind that, at its core, a model predicts the next word or token based on the preceding words and given conditions. In mathematical terms, this is a distribution—imagine a field of words from which the model selects. The conditions you supply, along with the words the model has already chosen, restrict the area from which it can pick subsequent words. To translate this into “math speak,”: as you provide more conditions, the probability density around a particular area in the distribution increases, and the model selects a word by sampling around this densest area.

Practical Examples: The Art of Detailing

A critical aspect of crafting clear and specific instructions lies in providing detailed information, considering not only what you want to achieve but also how you want it to be achieved. Let’s break it down with some examples.

Example 1: “Write about the Industrial Revolution.”

This instruction is vague and leaves much open to interpretation. The output could vary greatly, discussing anything from the causes and effects of the Industrial Revolution, to its timeline, key players, or its impact on specific countries. Here’s a more explicit version:

“Write a concise 500-word essay about the Industrial Revolution, focusing specifically on its impact on the socioeconomic structure in Britain. Use a formal academic tone, and ensure to discuss at least three key changes it brought about.”

With this revised prompt, the model has a clear idea of the topic, the length of the essay, the tone of language to use, and the key points to touch on.

Example 2: “Write a poem about love.”

Poetry comes in many forms and styles, and love is a broad theme. A more specific instruction could be:

“Compose a 14-line sonnet about the enduring nature of love, using a romantic and lyrical tone. Ensure to use the traditional Shakespearean rhyme scheme of ABABCDCDEFEFGG.”

This refined prompt provides specific information about the form, theme, length, tone, and even the rhyme scheme of the desired poem.

Example 3: “Summarize this article.”

Again, this instruction is fairly ambiguous. A better alternative might be:

“Summarize the attached scientific article into a 200-word abstract, highlighting the main research question, methodology, findings, and conclusion. Write in a clear, layman’s language suitable for a non-specialist audience.”

This detailed prompt gives clear instructions on what the summary should include, its length, and the intended audience’s language level.

By paying close attention to the specifics in your prompts, you increase the probability of getting the desired results from your language model. As with any engineering process, crafting these instructions will require some fine-tuning and testing, but with practice, it becomes second nature.

Enhance Clarity and Safety with Boundary Indicators

To significantly improve the model’s performance, it’s crucial to make it clear where the model should anticipate input. This can be achieved through the use of boundary indicators such as quotes, hyphens, brackets, and so forth. This technique not only enhances clarity but also provides a safety measure against prompt injection.

Practical Examples of Boundary Indicators

Example 1: Using Brackets

You could use brackets to specify where an answer should be placed, making it clear where the model’s output should start and end.

Prompt without boundary indicators: "Translate the following English sentence to Spanish: Good Morning."

Prompt with boundary indicators: "Translate the following English sentence to Spanish: [Good Morning]. Place the translation within the brackets."

The model will understand that its output should replace ”[Good Morning]”, thus creating a clear boundary for the expected output.

Example 2: Using Quotes

Quotes can be useful to specify a phrase that needs manipulation or transformation.

Prompt without boundary indicators: "Please rewrite the sentence I am not unhappy in a positive way."

Prompt with boundary indicators: "Please rewrite the sentence "I am not unhappy" in a positive way."

With quotes, the model can clearly identify the phrase to be rewritten.

Example 3: Classification

Hyphens can act as effective boundary indicators, especially for short-form instructions. For example you are a middle school teacher and you want to use a large language model to classify each word in a long text by it’s part of speech. Then a simple prompt without any delimiters would be

Please classify the words by their part of speech: 'text'

And with a delimiter such as curly brackets you could be much clearer and guard against prompt injection like so:

Please classify the words in the text enclosed 
by curly brackets by their parts of speech.
{text}

Other popular delimiters are triple quotes or hyphens.

Example 3: Using Hyphens

Hyphens can be used to distinctly separate different sections of a prompt, which is particularly useful when asking for several pieces of information.

Prompt without boundary indicators: "Provide a brief summary and an interesting fact about the Battle of Hastings."

In this case, it might be unclear whether the interesting fact should be part of the summary or separate.

Prompt with boundary indicators: "Provide a brief summary about the Battle of Hastings - and then provide an interesting fact."

Here, the hyphen helps to separate the two different tasks, making it clear that the summary and the interesting fact are two distinct responses.

In this example, the hyphen as a boundary indicator helps to clarify the structure of the prompt and thus better guides the model’s responses.

OliPrompts.com © 2024