什么是 prompts, completions, tokens and meta-learning /in-context-learning

Literally any text can be used as a prompt (prompts) - enter some text and get some text. Although we know that GPT-3's handling of random strings is very interesting, it is better to write an effective hint to really let GPT understand what we want it to do.

Prompts

Prompt is how to let GPT-3 know what you want it to do. It's like programming, but in plain English. So, you have to know what you want to do and express it using words and plain text, no coding required.

The main thing to remember when you write Prompts is to let GPT-3 know what text should appear next, including instructions and examples to provide context to help the model figure out the best possible Completion. Also, the quality of writing is important - for example, spelling, unclear text, and the number of examples provided all affect the quality of completion.

Another key factor is the size of the prompt. While the prompt can be any text, the prompt and the generated completions combined must be less than 2,048 tokens. We'll discuss markup later in this chapter, but that's about 1,500 words.

Thus, hints can be any text, and there are no hard and fast rules that you must follow when writing code. However, there are some guidelines for constructing hint text that can help achieve the best results.

Prompts type


We'll dive into how to write different hint types, which are as follows:

  • Zero-shot prompts (zero-shot prompts)
  • One-shot prompts (one-shot prompts)
  • Few-shot prompts (Multiple prompts)

Zero-shot prompts (zero-shot prompts)


Zero-shot prompts are the simplest type of prompt. It just provides a task description or some text to get GPT-3 started. Again, it could be really any text: a question, the beginning of a story, instructions — anything, but the clearer your prompt text, the easier it is for GPT-3 to understand what should come next. The following is an example of a zero-shot prompt that generates an email message. Completion will start where the hint left off - in this case, after Subject::

Write an email to my friend Jay from me Steve thanking him for covering my shift this past Friday. Tell him to let me know if I can ever return the favor.
Subject:

The following screenshots are from Playground, a web-based testing tool. Note that the original prompt text is bold, and Completion is displayed as regular text:

Figure 1.1 – Zero-shot prompt example
Figure 1.1 – Zero-shot prompt example

As can be seen, zero prompts are just a few sentences or a short description of the task without any examples. Sometimes that's all GPT-3 needs to get the job done. Other times, you may need to include one or more examples. A prompt that provides a single example is called a one-time prompt.

One-shot prompts (one-shot prompts)

One-shot prompts provide an example that GPT-3 can use to learn how to best complete the task. Here's an example of a one-time prompt that provides a task description (first line) and a single example (second line):

A list of actors in the movie Star Wars 
1. Mark Hamill: Luke Skywalker

Just from the description and an example, GPT-3 knows what the task is and should accomplish it. In this example, the task is to generate a list of actors from the movie "Star Wars". The following screenshot shows what is generated from this prompt:

Figure 1.2 – One-shot prompt example 

One-shot prompts are great for lists and universally understood patterns. But sometimes you need more than one example. In this case, you will use the hint several times.

few-shot prompt  (multiple prompts)


The few-shot prompt  provides multiple samples - usually 10 to 100. Multiple examples are useful to show the pattern that GPT-3 should continue. Few-shot hints and more examples may improve the quality of completion, as hints give GPT-3 more to learn from.

Below is an example of multiple prompts that generate a simulated dialog. Note that these examples provide a back-and-forth conversation with what might have been said in the conversation:

This is a conversation between Steve, the author of the book Exploring GPT-3 and someone who is reading the book.
Reader: Why did you decide to write the book?
Steve: Because I'm super fascinated by GPT-3 and emerging technology in general.
Reader: What will I learn from this book?
Steve: The book provides an introduction to GPT-3 from OpenAI. You'll learn what GPT-3 is and how to get started using it.
Reader: Do I need to be a coder to follow along?
Steve: No. Even if you've never written a line of code before, you'll be able to follow along just fine.
Reader: 

In the screenshot below, you can see GPT-3 continuing the simulated conversation it started in the example provided in the prompt:

Figure 1.3 – Few-shot prompt example

Now that you understand the different prompt types, let's look at some other prompt examples.

Prompts example
OpenAI API can handle various tasks. Possibilities range from generating original stories to performing complex text analysis, and everything in between. To familiarize yourself with the kinds of tasks GPT-3 can perform, OpenAI provides many examples of hints. You can find example Prompts in the Playground and OpenAI documentation.

In the Playground, samples are called Presets. The following screenshot shows some of the available Presets:

Figure 1.4 – Presets

Examples of prompts are also available in the OpenAI documentation. The OpenAI documentation is excellent, including many great Prompt examples, and links to open and test them in the Playground. The screenshot below shows an example of a hint from the OpenAI documentation. Note the Open this example in Playground link below the hint example. You can open hints in Playground using this link:

https://platform.openai.com/docs/guides/completion/prompt-design

Figure 1.5 – OpenAI documentation provides examples of hints

Now that you understand hints, let's talk about how GPT-3 uses them to generate completions.

Completions

Similarly, completions refer to the text generated and returned based on prompts/input. GPT-3 was not trained on any type of NLP - it is a general language processing system. However, GPT-3 can use prompts to complete a given task. This is called Meta-learning.

Meta-learning
For most NLP systems, when training the underlying ML model, the data provided is used to instruct the model how to complete a specific NLP task. Therefore, in order to improve the effect on a given NLP task, the model must be retrained to obtain a new version of the model. But GPT-3 is different because it doesn't need to be retrained for any specific task. It is designed to recognize patterns in the text of prompts and to continue the pattern by using the underlying generic model. This approach is called Meta-learning because the hints are used to teach GPT-3 how to generate the best completions without retraining. So, in fact, GPT-3 can be programmed for different types of tasks with different prompt types (zero prompt, one prompt, and many prompts), and you can provide a large number of instructions in the prompt - up to 2,048 identifiers (tokens).

Identifiers (Tokens)

When a hint is input to GPT-3, it is broken down into identifiers (Tokens). An identifier is a numeric representation of a word, or more commonly a part of a word. Numbers are used for identifiers rather than words or sentences because they can be processed more efficiently. This enables GPT-3 to handle relatively large amounts of text. That said, as you know, hints and generated completions together still have a limit of 2,048 identifiers (about 1,500 words).

You can stay within the limit of the number of identifiers by estimating the number of identifiers that will be used in your hints and completions. On average, for English words, every four characters represent an identifier. So just add the number of characters in the prompt to the length of the response and divide the sum by four. This will give you an idea of ​​how many identifiers you need. This is helpful if you want to know how many identifiers are needed for many tasks.

Another way to get the number of identifiers is to use the identifier count indicator in the playground. It's located just below the large text input in the lower right corner. The enlarged area in the screenshot below shows the number of identifiers. If you hover over the numbers, you'll also see the total count when you're done. For our example, prompt Do or do not. There is no try. - Quote from Master Yada - use 10 identifiers and 64 completion identifiers:

Figure 1.6 - token count

While understanding identifiers is important to staying under the 2,048 identifier limit, it's also important to understand them because the number of identifiers can be pegged to OpenAI's fees. An overall identifier usage report is available for your account at https://beta.openai.com/account/usage. The following screenshot shows a sample usage report.

Figure 1.7 - Usage statistics

Besides identifier usage, another thing that affects the costs associated with using GPT-3 is the engine you choose to process hints. Engine refers to the language model that will be used. The main difference between the engines is the size of the associated models. Larger models can accomplish more complex tasks, but smaller models are more efficient. Therefore, depending on the complexity of the task, you can reduce costs significantly by using a smaller model. The screenshot below shows model pricing at launch. As you can see, the cost can vary greatly:

other

Playground-related parameter description

  • temperature:  This affects the "randomness" of the responses you get. What sampling temperature to use, between 0 and 2. Higher values ​​(like 0.8) will make the output more random, while lower values ​​(like 0.2) will make the output more focused and deterministic. We generally recommend changing this or top_p but not both.
  • top_p : An alternative to temperature sampling, called kernel sampling, where the model considers the results of labels with top_p probability quality. So 0.1 means that only tokens constituting the top 10% of probability masses are considered. We generally recommend changing either this value or the temperature, but not both.
  • Maximum length : How long the AI's response can be.
  • Show Probabilities : This will highlight various words to show you how the AI ​​considered and selected them based on likelihood.
  • Frequency/Presence penalty : Change the likelihood of the AI ​​reusing words or discussing the same topics over and over again

Mode 

  • Completion : This is the default mode, which lets the AI ​​complete your dialogue where your input left off.
  • insert : This mode uses the [insert] tag to fill in an empty spot of your choice.
  • edit : Rather than serving entirely new content, this mode modifies existing content according to your specifications (e.g., "Rewrite this in a pirate voice" or "Remove 'like' and other filler words.")
  • Chat : chat mode

The difference between ChatGPT and OpenAI Playground

Chat GPT is a tool that allows you to interact with GPT-3.5 in real time through a chat interface. You can use it to generate text by giving it hints, and it will generate text based on the information you provide.

OpenAI Playground is a web-based tool that allows you to experiment with GPT-3 and other OpenAI models in a more interactive and flexible manner. It provides various options and settings that you can use to customize the behavior of the model, such as the size of the model, the type of output, etc.

In general, Chat GPT is a good choice if you just want to generate text quickly by providing hints, while OpenAI Playground is more for more advanced users who want to experiment with different settings and options to customize the behavior of the model.
Chat GPT uses GPT 3.5 and Playground uses GPT 3. However, Chat GPT is currently in free research preview and you can use it for free. After the hat's free research preview period expires, you will no longer have free access to the model. If you want to continue using Chat GPT, you need to sign up for a paid subscription.

The use of Chat GPT also means that your input and output will be saved. So do not enter personal or sensitive information.

Playground is a user-friendly interface for interacting with GPT-3, a large-scale neural network-based language generation model developed by OpenAI. On the other hand, ChatGPT is a smaller version of GPT-3, designed for conversational language understanding and generation tasks. In other words, Playground is a tool that uses GPT-3, while ChatGPT is a specific version of GPT-3 optimized for chatbot-like interactions.

In the end, the difference between the two is that "Playground" is a Playground, while Chat GPT is a standalone application. A space where you can play with parameters and see how it affects token usage and output performance, so you can see what parameters to choose after implementing GPT 3 into your project using the API.

How do bloggers use playgrounds

The following is the playground address, you can play by yourself, but it's just the beginning for free.

https://platform.openai.com/playground

tip works

Prompt engineering is a concept in artificial intelligence , especially natural language processing (NLP). In hint engineering, the description of the task is embedded in the input. For example, instead of implicitly giving certain parameters to the model, they are directly input in the form of questions. Prompt engineering typically works by converting one or more tasks into a prompt-based dataset and training a language model through so-called "prompt-based learning " . Prompt engineering can work from a large "frozen" pretrained language model in which only representations for the prompts are learned, so-called "prefix-tuning" or "prompt tuning".

Language models GPT-2 and GPT-3 are important steps in hint engineering. In 2021, multi-task hint engineering using multiple NLP datasets showed promising performance on new tasks. In the example of few-shot learning, cues containing thought chains show better reasoning ability in language models. In zero-shot learning, preserving sentences in the prompts that encourage thought chains (such as "let's think step by step") may improve the performance of language models on multi-step reasoning problems. The wide availability of these tools has been driven by the release of several open-source notes and community-led image synthesis projects.

A description of processing cues reports that in February 2022, more than 2,000 public cues from about 170 datasets were available.

In 2022, machine learning models such as DALL-E , Stable Diffusion , Midjourney , etc. will be publicly released. These models take textual cues as input and use them to generate images, which has influenced a new breed of hint engineering related to Vincent diagram cues.

Chain of thought ( Chain-of-thought )


Chain -of- thought prompting (CoT) improves the reasoning ability of LLMs by prompting them to generate a sequence of intermediate steps that lead to the final answer to a multi-step question. The technology was first proposed by Google researchers in 2022.

LLMs trained on large amounts of text using deep learning methods can generate output similar to human-generated text. Although LLM performs well on various natural language tasks, it still faces difficulties on some reasoning tasks that require logical thinking and multiple steps to solve, such as arithmetic or common sense reasoning problems. To address this challenge, the CoT hint-hint model generates intermediate reasoning steps before giving the final answer to a multi-step question. 

For example, given the question "Q: There are 23 apples in the cafeteria. If they use 20 for lunch and buy 6 more, how many apples do they have?", a CoT prompt might prompt the LLM to mimic "A: The cafeteria Originally there were 23 apples" to answer. They used 20 for lunch. So they have 23 - 20 = 3. They buy 6 more apples, so they have 3 + 6 = 9. The answer is 9. "

Thought-chain prompting improved LLM average performance on arithmetic and general knowledge tasks compared to standard prompting methods. When applied to the 540B parametric language model PaLM, the CoT hints significantly helped the model perform on par with task-specific fine-tuned models on multiple tasks, even setting a then-state-of-the-art inference benchmark on the GSM8K math model.

CoT hints are an emerging property of model size, which means it works better with larger, more powerful language models. Models on the CoT inference dataset can be fine-tuned to further enhance this capability and inspire better interpretability.

A common example of in-context learning is chain-of-thought prompting

The papers proposed by the chain of thinking are as follows

  1.  Wei, Jason; Wang, Xuezhi; Schuurmans, Dale; Bosma, Maarten; Ichter, Brian; Xia, Fei; Chi, Ed H.; Le, Quoc V.; Zhou, Denny (31 October 2022). "Chain-of-Thought Prompting Elicits Reasoning in Large Language Models"arXiv:2201.11903.
  2. ^ Wei, Jason; Zhou. "Language Models Perform Reasoning via Chain of Thought"ai.googleblog.com. Retrieved 10 March 2023.

malicious use

Hint injection is a family of related computer security vulnerabilities that allow a trained machine learning model, such as a large language model, to follow instructions provided by a malicious user by having them follow instructions given by a human, in contrast to the intended operation of an instruction-following system, The machine learning model only follows trusted instructions (hints) provided by the machine learning model operator.

Hint injection can be viewed as a code injection attack using adversarial hint engineering. In 2022, the NCC Group will prompt injection into a new class of vulnerabilities characterized as AI/ML systems.

Around 2023, hint injection appears in minor vulnerabilities against ChatGPT and similar chatbots, such as revealing hidden initial hints in the system, or tricking chatbots into engaging in conversations that violate the chatbot content policy .

Meta-learning

        Meta-learning: In the context of language models, the model develops a wide range of skills and pattern recognition capabilities at training time, and then uses these capabilities at inference time to quickly adapt or recognize desired tasks. The inner loop and outer loop in the figure below are called meta-learning together.

it means the model develops a broad set of skills and pattern recognition abilities at training time, and then uses those abilities at inference time to rapidly adapt to or recognize the desired task

Figure 1.1: Language model meta-learning. During unsupervised pre-training, language models develop a wide range of skills and pattern recognition capabilities. It then uses these capabilities at inference time to quickly adapt or identify desired tasks. We use the term "in-context learning" to describe the inner loop of this process, which occurs on each sequence's forward pass. The sequences in this figure are not meant to represent the data the model will see during pre-training, but to show that sometimes repeated subtasks are embedded within a single sequence.

  

      In the context of language models, this is sometimes called "zero-shot transfer", but the term can be ambiguous: the method is "zero-shot" in the sense that no gradient updates are performed, but it usually involves providing inference- Temporal demonstration of the model, so it's not really learning from zero examples. To avoid this confusion, we use the term "meta-learning" to describe the inner-loop/outer-loop structure of the general approach, and the term "contextual learning" to refer to the inner loop of meta-learning. We further specialize the description as "zero-shot," "one-shot," or "few-shot," depending on how many demonstrations are provided at inference time. These terms are intended to be useful for models learning new tasks from scratch at inference time. Whether to simply recognize the patterns seen during training remains agnostic - an important question, but "meta-learning" is designed to cover both possibilities and simply describes the inner-outer loop structure .

1In the context of language models this has sometimes been called “zero-shot transfer”, but this term is potentially ambiguous: the method is “zero-shot” in the sense that no gradient updates are performed, but it often involves providing inference-time demonstrations to the model, so is not truly learning from zero examples. To avoid this confusion, we use the term “meta-learning” to capture the inner-loop / outer-loop structure of the general method, and the term “in context-learning” to refer to the inner loop of meta-learning. We further specialize the description to “zero-shot”, “one-shot”, or “few-shot” depending on how many demonstrations are provided at inference time. These terms are intended to remain agnostic on the question of whether the model learns new tasks from scratch at inference time or simply recognizes patterns seen during training – this is an important issue which we discuss later in the paper, but “meta-learning” is intended to encompass both possibilities, and simply describes the inner-outer loop structure.

in-context learning

We use the term "in-context learning" to describe the inner loop of this process, which occurs in the forward pass of each sequence

In-context learning is the inner loop in the graph, which refers to what the model learns during the forward pass of each sequence data input.

Figure 1.1: Language model meta-learning. During unsupervised pre-training, language models develop a wide range of skills and pattern recognition capabilities. It then uses these capabilities at inference time to quickly adapt or identify desired tasks. We use the term "in-context learning" to describe the inner loop of this process, which occurs on each sequence's forward pass. The sequences in this figure are not meant to represent the data the model will see during pre-training, but to show that sometimes repeated subtasks are embedded within a single sequence.

Guess you like

Origin blog.csdn.net/keeppractice/article/details/129912317
Recommended