Prompt research and techniques for large models

Prompt writing for large models

Introduction

Prompt is yesgiven AI **Model instruction, **a short text input , used to guide the AI ​​model to generate specific answers or perform specific tasks.

Prompt is how you communicate with the language model. A good prompt can allow AI to understand your needs more accurately and give more useful answers.

composition

The composition and disassembly of Prompt mainly includes the following six elements:

  1. Task: Task is the core of Prompt. It usually starts with a verb and clearly expresses the task or goal you want ChatGPT to complete. This can include generating text, giving advice, writing content, etc. There can be multiple tasks to clearly define your needs.
  2. Context: Context provides background information related to the task to ensure that ChatGPT understands the background and constraints of the problem. This includes the user's background information, success criteria, environment, etc. Context is critical to the clarity and effectiveness of tasks.
  3. Examples: Examples are sections that provide specific examples or frameworks to guide ChatGPT to generate more accurate output. Providing examples improves the quality of your output by clearly demonstrating the required content and format. But you don't need to provide an example every time. Sometimes you can let ChatGPT generate it by itself.
  4. Persona: Persona clearly specifies the role or identity played by ChatGPT and Bard (if fictional characters are involved). This can be a specific person or a fictional character, helping to tailor the tone and content to fit the needs of the specific character.
  5. Format: The format part visualizes the appearance and structure of your desired output, such as tables, lists, paragraphs, etc. Explicitly specifying the format of the output ensures that the content generated by ChatGPT matches your expectations.
  6. Tone: Tone defines the tone or style of the output text, such as formal, informal, humorous, etc. Specifying the tone helps ensure that ChatGPT's responses match the desired emotion and style requirements.

By properly organizing these six elements, you can create a clear and concise prompt that effectively guides ChatGPT to generate text output that meets expectations.

When creating a Prompt, here are some concrete examples showing how to use the six elements above:

1. Task:

  • Generate an article about solar power generation.
  • Give me some advice on how to lower the carbon footprint of your life.
  • Write a thank you note to express your gratitude to your client.

2. Context:

  • As a student, you are writing a research paper on climate change and hope to gain insight into renewable energy sources.
  • You are an environmental activist who needs actionable plans to reduce plastic pollution.
  • You are reviewing a business cooperation and need a thank you letter to emphasize the importance of the cooperation.

3. Examples:

  • As an example, provide some statistics about solar energy, or the opening paragraph of a similar article.
  • As an example, list some environmentally friendly measures such as reducing the use of plastics, using renewable energy, etc.
  • Provide some already written thank you letter paragraphs for reference.

4. Persona:

  • Please answer as a volunteer for an environmental organization.
  • Please answer as a scientist.
  • Please answer as a CEO of a company.

5. Format:

  • Please write an essay in paragraph form, including a title, introduction, body, and conclusion.
  • Please formulate a list of suggestions for reducing your carbon footprint.
  • Please write a thank you letter in a formal letter format, including date, address, title, etc.

6. Tone:

  • Use a formal tone and avoid slang or colloquialisms.
  • Please use a relaxed tone and add humor as appropriate.
  • Use a grateful tone of voice to express sincere gratitude.

These examples highlight how Prompts can be composed according to specific needs to ensure that ChatGPT understands the task, context, examples, roles, format and tone and generates content accordingly. By properly matching these elements, ChatGPT can be guided to generate text responses that meet the requirements.

technology

Zero-Shot

Zero-Shot Prompting refers to the ability to complete specified downstream tasks directly through text prompts in a large language model (LLM) without additional fine-tuning or training.

The main idea is:

  • First train a general large-scale language model, learn the basic rules of language, and master a wealth of common sense and knowledge.
  • Then, without changing the model parameters, only soft prompts are used to guide the model to complete specific tasks.
  • The model generates output corresponding to the task based on prompts and acquired knowledge.

For example, we can give ChatGPT a short prompt, such as 描述某部电影的故事情节, and it can generate a summary of the plot without requiring special training related to movies.

Zero-Shot Prompting technology relies on pre-trained language models, which may be subject to limitations and biases of the training data set. Its output may sometimes be inaccurate or inconsistent with

expected. This may require further fine-tuning of the model or the addition of more prompt text to correct.

Few-shot

Few-shot Prompting is an extension of Zero-shot Prompting, which refers to using a very small number of task-related examples to assist prompts, allowing the model to adapt to new tasks faster.

The key idea is:

  • Still based on pre-trained general language models
  • Use soft prompts to guide models through new tasks
  • Provide 1-2 additional relevant examples as supplementary tips

For example:

Task: Generate an article about solar energy.

Example:

  1. Example 1: Solar energy is a clean energy source that converts solar energy into electricity through solar panels.
  2. Example 2: Solar panels are often installed on roofs and can provide renewable energy to homes.
  3. Example 3: Solar energy is an important way to reduce greenhouse gas emissions.

Task description: Based on these examples, write an article about solar energy, focusing on how it works, its applications, and its impact on the environment.

COT

The paper shows that it is only effective when used in models with 100B or more parameters. If it is a small sample model, this method will not be effective.

The thinking chain prompt is to decompose a multi-step reasoning problem into many intermediate steps, allocate more calculations, generate more tokens, and then splice these answers together for solution.

Insert image description here
Insert image description here

COT-SC

Let the model generate multiple thought chains, and then take the one with the most answers as the final result.

In fact, to repeat the operation multiple times and select the one with the highest probability, you need to use scripts to assist in completing this function.

Self-consistency is an improvement on the CoT method. Compared with CoT which only samples the answer once, SC adopts the idea of ​​multiple sampling and finally selects the consistent answer as the final answer. The basis for the establishment of SC is the article's belief that a complex reasoning problem can be solved in many different ways, and the correct answer can eventually be obtained. Humans may have different ideas when thinking about the same problem, but in the end they may reach the same conclusion. It can be understood as "one question with many solutions" and "all roads lead to Rome". SC performance has been further improved compared to CoT.

Insert image description here

By sampling answers multiple times, the result with the highest consistency is finally selected as the final result, which can largely avoid errors caused by the randomness of LLM.

UNTIL

The Tree of Thoughts (ToT) framework is used to improve the reasoning capabilities of language models (LMs). This framework is an adaptation of the popular “Chain of Thought” approach

Generalization allows the model to conduct more exploration and strategic foresight in the process of solving problems.

ToT allows the model to self-evaluate different options to decide the next action, and to look forward or look back when necessary to make global choices.

In the 24-point game, GPT-4 using chain thinking prompts only solved 4% of the tasks, while the success rate using the ToT method reached 74%

The application in other scenarios is not very big.

GoT

GoT has three operations:

  • Aggregation

  • Refining

  • Generation

Aggregation refers to the integration of several ideas into a better idea. The graph shows multiple nodes pointing to the same node;

Refining refers to the reflection of the node itself and continuous improvement of its own content. The graph shows a node pointing back to itself;

Generation refers to the generation of one or more new ideas through a node. The graph is represented by a node pointing to one or more nodes.

Insert image description here

ReAct

It is the same as the Agent in langchain

Use LLM to generate inference trajectories and task-specific actions in an interleaved manner, enabling greater synergy between the two.

Inference trajectories help the model generalize, track and update action plans, and handle exceptions, while operations allow it to interact with external sources (such as a knowledge base or the environment) to gather additional information. We apply our method, named ReAct, to a variety of language and decision-making tasks and demonstrate its effectiveness on state-of-the-art baselines, as well as improved human interpretability and trustworthiness over methods without reasoning or action components. .

Specifically, in terms of question answering (HotpotQA) and fact verification (Fever), ReAct overcomes the common illusion and error propagation problems in chain-of-thought reasoning by interacting with the simple Wikipedia API and generates human-like task solution trajectories , easier to interpret than the baseline without traces of inference.

Insert image description here

Guess you like

Origin blog.csdn.net/qq128252/article/details/133775725
Recommended