Introduction

If OpenAI's and Google's latest demo's are any hint, we are racing to a future in which talking with voice assistants and language apps may be as common as chatting with a friend.

In essence, we are dealing with a new era of human-machine communication, the one several sci-fi authors and movie producers have captured in their art.

Unlike with typical software systems, which involve simple navigation or button-clicking, we find ourselves in a more convenient and easier place; after all, we are dealing with human language.

As it turns out, human language-based communication with our helpful assistants is easy, though not simple.

Language is rarely simple, as it has so much nuance. However, in this case, the framing of the question greatly affects the articulation, style, and clarity of the answers.

When you click a button, you get standard or generally expected answers. However, now your experience in using an AI assistant, as well as a friend's experience with similar questions, can be drastically different.

In fact, the quality of the responses generated by a pretrained and aligned LLM is directly related to the quality of the prompts or instructions provided by you, the user. Using the right methodology to craft and customize prompts can greatly enhance output quality and relevance.

The title of this article mentions "26 principles". These principles are detailed in a paper — "Principled Instructions Are All You Need for Questioning LLaMA-1/2, GPT-3.5/4". [1]

These principles talk about key prompt design techniques that are applicable across a variety of use cases and domains. They are easy enough to incorporate and can form a part of everyone's prompting vocabulary and style.

As a motivating example, let's look at a side-by-side comparison of prompts written without principles and those applying the principles. (Figure 1).

The difference between the two is evident. In the example, tweaking the prompts can lead to detailed and more easy to understand explanation of the same concept.

None
Figure1: Illustration example of prompts and corresponding responses before and after applying principles. Left is the original promotes and their responses from GPT-4, right is the principled prompts and the associated responses.

However, the benefits do not end there. Tweaking prompts can also improve the accuracy of the results, especially in mathematical and logical reasoning questions.

What are the principles?

At a broad level, the principles suggest the usage of certain words and phrases, introduce key ideas like incorporating role descriptions, adding examples, providing directions for the output, emphasizing certain prompt structures and incorporating iteration.

Not all principles apply in all scenarios, and they can, in fact, be combined in various ways depending on the use case.

These principles can be divided into two broad categories and grouped under: 10 High Level Approaches and 5 Specialized Prompts.

First let's take a look at the Approaches. Each approach groups several principles together. For each principle, one or more examples are provided.

Approach 1 : Usage ( or avoidance ) of special words and phrases

Principle: get straight to the point.

If you prefer more concise answers, no need to be polite with LLM. There is no need to add phrases like "please", "if you don't mind", "thank you", "I would like to", etc., and get straight to the point.

Instead of "Could you kindly describe the structure of a human cell, please?" simply say "the structure of a human cell."

Principle : Employ affirmative directives such as "do," while steering clear of negative language like "don't".

"How do buildings remain stable during earthquakes?"

Principle: When you need clarity or a deeper understanding of a topic, idea, or any piece of information, utilize the following prompts:

  1. Explain to me like I'm 11 years old: how does encryption work?

2. Explain [insert specific topic] in simple terms.

3. Explain to me like I'm 11 years old.

4. Explain to me as if I'm a beginner in [field].

5. Explain to me as if I'm an expert in [field].

"Write the [essay/text/paragraph] using simple English like you're explaining something to a 5-year-old".

Principle: Incorporate the following phrases: "Your task is" and "You MUST".

"Your task is to explain the water cycle to your friend. You MUST use simple language."

Approach 2: Reward or threat

Principle: Add "I'm going to tip $xxx for a better solution".

"I'm going to tip $300K for a better solution! Explain the concept of dynamic programming and provide an example use case."

Principle: Incorporate the following phrases: "You will be penalized".

"Your task is to explain the water cycle to your friend. You will be penalized if you fail to use simple language."

Approach 3: Chain of Thought— think step by step

This is one of the most important phrases for those that love math.It forces the model to engage in multi-step reasoning.

Principle: Use Leading words like writing "think step by step".

"Write a Python code to loop through 10 numbers and sum all of them. let's think step by step."

Approach 4 : Assign Role

Principle: Assign a role to the Large Language Models (LLMs).

"If you were an expert economist, how would you answer this: What are the key differences between a capitalist and a socialist economic system?"

Approach 5 : Include the audience

Principle: Integrate the intended audience in the prompt, e.g., the audience is an expert in the field.

"Construct an overview of how smartphones work, intended for seniors who have never used one before."

Approach 6: Incorporate iteration

Principle: Break down complex tasks into a sequence of simpler prompts in an interactive conversation.

A complex prompt can be broken up into 3 parts like below:

"P1: Distribute the negative sign to each term inside the parentheses of the following equation: 2x + 3y — (4x — 5y)

P2: Combine like terms for 'x' and 'y' separately.

P3: Provide the simplified expression after combining the terms."

Principle: Allow the model to elicit precise details and requirements from you by asking you questions until it has enough information to provide the needed output (for example, "From now on, I would like you to ask me questions to…").

"From now on, ask me questions until you have enough information to create a personalized fitness routine."

Approach 7 : Provide examples

Principle : Implement example-driven prompting (Use few-shot prompting).

"Translate the following English sentence to French: "The sky is blue." "

(Response: "Le ciel est bleu.")

"Translate the following English sentence to Spanish: "I love books." "

(Response: "Amo los libros.")

Principle: Combine Chain-of-thought (Cot) with few-Shot prompts.

"Divide 10 by 2. First, take 10 and divide it by 2. The result is 5."

"Divide 20 by 4. First, take 20 and divide it by 4. The result is 5.

"Main Question: "Divide 30 by 6. First, take 30 and divide it by 6. The result is…?

Approach 8 : Incorporate specific formats

Principle: When formatting your prompt, start with '###Instruction###', followed by either '###Example###' or '###Question###' if relevant.

Subsequently, present your content. Use one or more line breaks to separate instructions, examples, questions, context, and input data.

"###Instruction### Translate a given word from English to French. ###Question### What is the French word for "book"?"

Principle: Use Delimiters.

"Compose a persuasive essay discussing the importance of 'renewable energy sources' in reducing greenhouse gas emissions."

Approach 9 : Control style

Principle: Use the phrase "Answer a question given in a natural, human-like manner" in your prompts.

"Write a paragraph about healthy food. Answer a question given in a natural, human-like manner."

Principle: Add to your prompt the following phrase "Ensure that your answer is unbiased and avoids relying on stereotypes."

"How do cultural backgrounds influence the perception of mental health? Ensure that your answer is unbiased and avoids relying on stereotypes."

Principle: Repeat a specific word or phrase multiple times within a prompt.

"Evolution, as a concept, has shaped the development of species. What are the main drivers of evolution, and how has evolution affected modern humans?"

Principle: Use output primers, which involve concluding your prompt with the beginning of the desired output. Utilize output primers by ending your prompt with the start of the anticipated response.

"Describe the principle behind Newton's First Law of Motion. Explanation:"

Approach 10 : Clarity

Principle: Clearly state the requirements that the model must follow in order to produce content,in the form of the keywords, regulations, hint, or instructions

"Create a packing list for a beach vacation, including the following keywords "sunscreen," "swimsuit," and "beach towel" as essential items."

Next we will look at prompting words or techniques for specific usage scenarios.

Usecase 1— Test Yourself

To inquire about a specific topic or idea or any information and you want to test your understanding, you can use the following phrase:

Teach me any [theorem/topic/rule name] and include a test at the end, and let me know if my answers are correct after I respond, without providing the answers beforehand.

"Teach me about the KVL law and include a test at the end, and let me know if my answers are correct after I respond, without providing the answers beforehand."

Usecase 2 — Write Detailed Text

To write an essay /text /paragraph /article or any type of text that should be detailed:

Write a detailed [essay/text/paragraph] for me on [topic] in detail by adding all the information necessary.

"Write a detailed paragraph for me on the evolution of smartphones in detail by adding all the information necessary."

To write any text, such as an essay or paragraph, that is intended to be similar to a provided sample, include the following instructions:

Use the same language based on the provided paragraph[/title/text /essay/answer].

"The gentle waves whispered tales of old to the silvery sands, each story a fleeting memory of epochs gone by." Use the same language based on the provided text to portray a mountain's interaction with the wind

Usecase 3 — Text reviewer

To correct/change specific text without changing its style:

Try to revise every paragraph sent by users. You should only improve the user's grammar and vocabulary and make sure it sounds natural. You should maintain the original writing style, ensuring that a formal paragraph remains formal

"Try to revise every text sent by users. You should only improve the user's grammar and vocabulary and make sure it sounds natural. You should maintain the original writing style, ensuring that a formal paragraph remains formal. Paragraph: Renewable energy is really important for our planet's future. It comes from natural."

Usecase 4 — Coding Prompt

When you have a complex coding prompt that may be in different files:

From now and on whenever you generate code that spans more than one file, generate a [programming language] script that can be run to automatically create the specified files or make changes to existing files to insert the generated code. [your question]

"Generate code that spans more than one file, and generate a Python script that can be run to automatically create the specified files for a Django project with two basic apps for different functionalities."

Usecase 5 — Content writer

When you want to initiate or continue a text using specific words, phrases, or sentences, utilize the following prompt:

I'm providing you with the beginning [song lyrics / story / paragraph / essay…]: [Insert lyrics / words / sentence]. Finish it based on the words provided. Keep the flow consistent.

I'm providing you with the beginning of a fantasy tale: "The misty mountains held secrets no man knew." Finish it based on the words provided. Keep the flow consistent.

Final Thoughts

At a high level, this article details principles in the form of approaches that incorporate basic prompt design ideas : Conciseness and clarity of the prompt, the inclusion of relevant detail including domain-specific vocabulary, ensuring the task to be performed by the LLM is clearly defined, including examples of inputs and outputs, avoiding biased statements, and using iterative or incremental prompting.

Our understanding of prompt crafting and tuning is ongoing. As more use cases for LLM become clear, the prompts and prompting methods will evolve, including the creation of large and complex prompts. This will go beyond the quick prompts we use to get tasks done.

Prompt libraries with well scripted prompts for repetitive tasks have been come popular. The prompt library released by Anthropic is extremely large [2].

Additionally, the use of LLM Agents that essentially incorporate specialized prompts and external tools like search, are leading to a new programming paradigm, making prompting important for both end users and developers alike.

For developers, there are mechanisms to optimize prompts based on use cases, and metrics like the library DSPy. [3].

In his newsletter, "The Batch" Andrew Ng speaks about how Mega Prompts designed by development teams that go beyond a few sentences, and can be one or two pages long. [4]

Clearly, we are scratching the surface in human-machine natural language communication and need to "delve" deeper into this space

Hope you enjoyed the article. Would love to hear your thoughts!

References

[1] Bsharat, Sondos Mahmoud, Aidar Myrzakhan, and Zhiqiang Shen. "Principled Instructions Are All You Need for Questioning LLaMA-1/2, GPT-3.5/4." arXiv preprint arXiv:2312.16171 (2023).

[2] https://docs.anthropic.com/en/prompt-library/library

[3] https://github.com/stanfordnlp/dspy

[4] https://www.deeplearning.ai/the-batch/issue-249/

None

This story is published under Generative AI Publication.

Connect with us on Substack, LinkedIn, and Zeniteq to stay in the loop with the latest AI stories. Let's shape the future of AI together!

None