What is Prompt Engineering? A very detailed guide to Prompt Engineering

Tip Engineering (Prompt Engineering) is aPrompt word(Prompt) and generation strategy, so as to obtain better engineering technology for model return results. In general, its implementation logic is as follows:
What is Prompt Engineering? A very detailed guide to Prompt Engineering
(Note: The example image is from the Cohere official website)
In simple terms, the operating mechanism of the big model is “Next word prediction ". The prompt input by the user is the context obtained by the large model. The large model will continue to write according to the user's input and return the result. Therefore, the quality of the input prompt will greatly affect the quality of the model's return results and the degree of satisfaction of user needs. The general principle is "The clearer the needs expressed by the user, the more likely the model will return higher quality results. ”.
Prompt Category
It is difficult to simply categorize user prompts, as their needs are rich and varied. In general, we divide user needs into the following categories:
• Information Query:Users consult the big model and get the information they need through QA, such as: "What is the capital of Iceland?"
 instruction:Users give instructions and want the big model to perform specific tasks, such as: "Help me write a C++ code for fast sorting."
• A prompt with context:This type of prompt is usually provided by the user with relevant background information, and the model is required to return answers to relevant questions, suggestions, etc. For example: "NBA latest game report: The latest game results show that in the Eastern Conference Finals, the Heat currently leads the Celtics 3:1, while the Western Conference Finals have ended with the Nuggets defeating the Lakers 4:0 to win the Western Conference Championship. Based on the above information, which team do you think is most likely to win the NBA championship?"
• Consulting opinions and suggestions:Users ask the model for opinions and suggestions on specific topics, or consult solutions, such as: "I want to start an AI design company. Please give me some advice on starting a company."
• Comparison Class:The user gives different options and asks the model to choose the better one and give reasons. For example: "What are the advantages and disadvantages of Tensorflow and Pytorch?"
• role play:This type of prompt covers a wide range of situations. It is mainly because users use the model as a copilot and hope that the model can flexibly play different roles to meet different needs. For example: "If you were a cat girl, you would always reply to me with cute words. Now I will start a conversation with you..." 
 prompt components
(I) Instructions
Instructions are the most commonly used prompt components. Their main function is to tell the model what operations to perform. Although the concept is simple, it is still relatively complex in practice. The following are some simple and complex instruction examples.
What is Prompt Engineering? A very detailed guide to Prompt Engineering
(II) Main contents
The main content refers to the text content that the model is processing. The main content is usually used with instructions. The following examples are from translation, summary and other scenarios:
What is Prompt Engineering? A very detailed guide to Prompt Engineering
(III) Sample
Good prompts also often include some example samples (one-shot or few-shot) learning, which means that some input and output pairs need to be added.
What is Prompt Engineering? A very detailed guide to Prompt Engineering
Through few-sample learning, the model has changed from guessing how to generate to clearly learning to generate according to examples, which fully demonstrates the ability of the model. It can generate correct answers through few-sample learning without special training.
(IV) Clear Prompt
It acts as a quick start for model output and helps the model fix the required output. It can be used as a prefix for model generation, or it can guide the model to think and give answers step by step according to the requirements.
What is Prompt Engineering? A very detailed guide to Prompt Engineering
Principles of writing good prompts
The most important principle for writing a good prompt is to express your needs as clearly and specifically as possible. Specifically, the principles include:
• Clarity:Be clear and specific enough about what you want the model to return to you, and then be more specific about your requirements at the end, avoiding vague expressions.
• To provide context and examples:Provide more sufficient context information to allow the model to better understand the relevant background. If examples can be provided, the model can perform better (similar to in-context learning in traditional LLM)
• Setting Boundaries:State the range of answers you want the model to answer, and try to minimize the amount of hallucinations the model generates.
• Segmentation needs:Maybe your requirement is actually a complex requirement, such as "Help me write a paper about xx", you can further subdivide the requirement, such as "[background information] Please help me write the outline", "[background information] Please help me write the introduction", ...
• Iterative Optimization:Many times we may get disappointing results. Don’t be discouraged. We suggest you try to modify the wording to encourage the model to generate better answers, or just click “Regenerate” and you may get a pleasant surprise.
• Give options and ask the model to explain:The model may not necessarily make the right choice, but it can make better results based on the candidate items than generating them directly from scratch. The model will also give its reasons, and users can judge the rationality of the content based on the reasons.
• Motivational model reflection and ideas:You can use some words in the prompt to encourage the model to give reasons, which will help us better analyze the results generated by the model. At the same time, the generation of the thinking process will also help it generate higher quality results. Please refer to the relevant technology of thinking chain.
• Give room for error:If the model cannot complete the specified task, provide the model with an alternative path, such as asking questions about the text and adding a "no answer" response if the answer does not exist.
Typical framework for a good prompt
There are many different types of prompts, but following the above principles, we have summarized a more practical framework that can help users obtain higher quality model generation results with a higher probability. When designing a prompt, it is recommended to include the following:
• identity:What role do you want the big model to play to solve your current problem? Big models have strong role-playing capabilities and often perform better than direct answers.
• instruction:Be clear about what you want the big model to do, don't be vague.
• Context:If possible, provide as much context as possible.
• Reason: Explain in detail why you want the model to do this, your motivation, the desired results, etc., so that the big model can better understand your ideas and execute your requirements.
What's Next
In short, prompt engineering is an emerging discipline that requires users to try and practice repeatedly, but it is not that difficult. It is more like a "How to SpeakThe art of learning is just a matter of practice.
statement:The content is collected from various media platforms such as public websites. If the included content infringes on your rights, please contact us by email and we will deal with it as soon as possible.
TutorialEncyclopedia

How to restore old photos? Share the tutorial of restoring old photos with AI in one click

2024-3-20 10:10:52

TutorialEncyclopedia

Generate a website in 3 minutes with just text! The first ChatGPT version website development platform

2024-3-21 9:53:34

Search