Selected from Microsoft Blog
Translated by Machine Heart
Machine Heart Editorial Team
With large models available, the next step is to design the Prompt.
In recent months, large models like ChatGPT and GPT-4 have been released. These models exhibit powerful emergent capabilities, but the results generated by the models can be random, varying in quality, partly due to the design of the Prompt.
Many people liken the Prompt to a spell for large models, significantly influencing how the model generates content. Choosing the right Prompt has become a focus for every AI researcher. Recently, Microsoft released a tutorial that introduces some advanced techniques in Prompt design and engineering, covering system messages, few-shot learning, non-chat scenarios, and more.
Each section contains technical explanations and example demonstrations. Let’s take a look at the specific content.
What You Should Know About Prompts
System messages are included at the beginning of the Prompt to provide context, instructions, or other information relevant to the use case. Users can describe what the model should and shouldn’t answer through system messages and define the format of the model’s replies.
The example below shows the system message and the response generated by the model:
Typically, a system message can also be like this:
-
In the table above, Assistant is a large language model trained by OpenAI.
-
Assistant is an intelligent chatbot designed to help users answer questions. The model is required to use only the given context to answer questions, and if it is unsure of the answer, it can say, “I don’t know.”
-
Assistant is an intelligent chatbot that can help users answer tax-related questions.
-
For example, you are an Assistant tasked with extracting entities from text. The user will paste a string of text, and you will respond with a JSON object containing the entities extracted from the text.
This is an example of the output format:
{"name": "","company": "","phone_number": ""}
That concludes the introduction to system messages. However, an important detail is that even well-designed system messages can still lead to the model generating erroneous responses that contradict the instructions in the system message.
A common method to adapt language models to new tasks is through few-shot learning. Few-shot learning provides a set of training samples as part of the Prompt to give the model additional context.
A series of interactions between the user and Assistant (written in a new Prompt format) can serve as examples for few-shot learning. These examples can guide the model to respond in a certain way, simulate specific behaviors, and provide seed answers to common questions.
The basic structure of a Prompt.
Non-Conversation Scenarios
Although the primary application scenario for current large models is dialogue generation, they can also be used in non-conversation scenarios. For example, for sentiment analysis, you might use the following Prompt:
Generally speaking, the order in which information appears in the Prompt is important. Since GPT-like models are constructed in a specific way, this construction defines how the model processes the input. Research shows that telling the model what task you want it to perform at the beginning of the Prompt, followed by other contextual information or examples, can help the model produce higher quality outputs.
Repeat Instructions at the End
Models are easily influenced by the latest bias, and in such cases, the information at the end of the Prompt may have a greater impact on the output than the information at the beginning. Therefore, repeating instructions at the end of the Prompt is worth trying.
This refers to including a few words or phrases at the end of the Prompt to obtain model responses that conform to the desired format. For example, using a Prompt like “Here’s a bulleted list of key points:
– ” can help ensure the output format is a bullet list.
Adding syntax to the Prompt, such as punctuation, headings, etc., makes the output easier to parse.
In the example below, different sources of information or steps are separated (in this case by —). This allows the use of — as a stopping condition for generation. Additionally, some headings or special variables appear in uppercase for distinction.
Breaking tasks down into smaller steps often leads to better performance from large language models (LLMs).
Note that syntax is used here to distinguish between different parts and initialize the output. In this simple example, breaking the task down from one step into two steps does not produce a significant difference, but when trying to do this with large blocks of text containing many factual statements, breaking the task down can make a significant difference.
Chain of Thought Prompting
This is a variation of the task decomposition technique. In this approach, instead of breaking the task down into smaller steps, the model is instructed to respond step by step and present all the involved steps. This can reduce inaccuracies in results and make it easier to evaluate the model’s responses.
In this method, it is suggested to provide the model with real data. Generally speaking, the closer the raw data is to the final answer, the less work the model has to do, which means the less likely the model is to make mistakes. In the example below, the system message provides the latest articles and then asks the model to give some early customers, to which the model accurately provided the answer.
In addition, Microsoft also introduced other tips about Prompts in this guide, and everyone can check the original text for more information.
Original link: https://learn.microsoft.com/en-us/azure/cognitive-services/openai/concepts/advanced-prompt-engineering?pivots=programming-language-chat-completions#specifying-the-output-structure

© THE END
For reprints, please contact this public account for authorization
For submissions or inquiries: [email protected]