diff --git a/docs/portal-guide/model/agent-system-operators/prompter.md b/docs/portal-guide/model/agent-system-operators/prompter.md index d23d189523..0e229e0b12 100644 --- a/docs/portal-guide/model/agent-system-operators/prompter.md +++ b/docs/portal-guide/model/agent-system-operators/prompter.md @@ -39,12 +39,16 @@ Your prompt template should include at least one instance of the placeholder `{d **2.** Use the pop-up that appears on the right-hand sidebar to define the template text. For this example, let’s use the following text: ``` -Please label the sentiment towards the movie of the given movie review. The sentiment label should be "positive" or "negative" {data.text.raw} +Please label the sentiment towards the movie of the given movie review. The sentiment label should be "positive" or "negative". ### Text: {data.text.raw} ### Sentiment: ``` ![zero-shot prompting](/img/agent-system-operators/prompter_1.png) -Note that we also include the `{data.text.raw}` placeholder to meet the requirements of the **Prompter** template. +Note that: + +- The template text is a single-line statement. +- We included the `{data.text.raw}` placeholder to meet the requirements of the **Prompter** template. +- We placed the instructions at the beginning of the template text and used the ["###" delimiter](https://docs.clarifai.com/portal-guide/model/model-types/text-to-text/#training-data) to separate the instruction and context. The delimiter is important when giving instructions to llms because it signifies the beginning and end of different sections within the text. This ensures clarity and facilitates easy parsing and processing during the prediction phase. **3.** You can then connect the prompter model to a text-to-text model like [GPT-4](https://clarifai.com/openai/chat-completion/models/GPT-4). @@ -55,8 +59,7 @@ To observe it in action, navigate to the workflow's individual page and click th For example, you could input the following as your input text: ``` -Text: I’ll bet the video game is a lot more fun than the film. -Sentiment: +I’ll bet the video game is a lot more fun than the film ``` Click the **Submit** button. @@ -66,7 +69,7 @@ Once the model has completed processing your input, you'll see the results, star In this case, the prompt text becomes: ``` -Please label the sentiment towards the movie of the given movie review. The sentiment label should be "positive" or "negative" Text: I’ll bet the video game is a lot more fun than the film. Sentiment: +Please label the sentiment towards the movie of the given movie review. The sentiment label should be "positive" or "negative". ### Text: I’ll bet the video game is a lot more fun than the film. ### Sentiment: ``` And the output becomes: @@ -74,8 +77,10 @@ And the output becomes: ``` Negative ``` + ![zero-shot prompting output](/img/agent-system-operators/prompter_2.png) + Note that in the above zero-shot prompt, we did not give the model any examples of text alongside their classifications. The model already knows what "sentiment" means without needing any extra information—that's how its zero-shot abilities work. ## Few-Shot Prompting @@ -88,12 +93,6 @@ For example, few-shot prompting can be used to train an LLM to classify new type Let’s demonstrate how you can create a few-shot prompter on the [workflow builder](https://docs.clarifai.com/portal-guide/workflows/workflow-builder/) for a text classification task. -:::tip - -Your prompt template should include at least one instance of the placeholder `{data.text.raw}`. When you input your text data at inference time, all occurrences of `{data.text.raw}` within the template will be replaced with the provided text. - -::: - **1.** Search for the **Prompter** template option in the left-hand sidebar of the workflow builder and drag it onto the empty workspace. **2.** Use the pop-up that appears on the right-hand sidebar to define the template text. @@ -101,20 +100,12 @@ Your prompt template should include at least one instance of the placeholder `{d For this example, let’s use the following text: ``` -Please label the sentiment towards the movie of the given movie review. The sentiment label should be "positive" or "negative". -Text: (lawrence bounces) all over the stage, dancing, running, sweating, mopping his face and generally displaying the wacky talent that brought him fame in the first place. -Sentiment: positive - -Text: despite all evidence to the contrary, this clunker has somehow managed to pose as an actual feature movie, the kind that charges full admission and gets hyped on tv and purports to amuse small children and ostensible adults. -Sentiment: negative - -Text: for the first time in years, de niro digs deep emotionally, perhaps because he's been stirred by the powerful work of his co-stars. -Sentiment: positive -\n{data.text.raw} +Please label the sentiment towards the movie of the given movie review. The sentiment label should be "positive" or "negative". ### Text: (lawrence bounces) all over the stage, dancing, running, sweating, mopping his face and generally displaying the wacky talent that brought him fame in the first place. ### Sentiment: positive. ### Text: Despite all evidence to the contrary, this clunker has somehow managed to pose as an actual feature movie, the kind that charges full admission and gets hyped on tv and purports to amuse small children and ostensible adults. ### Sentiment: negative. ### Text: For the first time in years, de niro digs deep emotionally, perhaps because he's been stirred by the powerful work of his co-stars. ### Sentiment: positive. ### Text: {data.text.raw} ### Sentiment: ``` + ![few-shot prompting](/img/agent-system-operators/prompter_4.png) -Note that we also include the `{data.text.raw}` placeholder to meet the requirements of the **Prompter** template. +Note that just like in the zero-shot prompting example above, we included the `{data.text.raw}` placeholder and the "###" delimiter in the template text. **3.** You can then connect the prompter model to a text-to-text model like [GPT-4](https://clarifai.com/openai/chat-completion/models/GPT-4). @@ -125,8 +116,7 @@ To observe it in action, navigate to the workflow's individual page and click th For example, you could input the following as your input text: ``` -Text: I'll bet the video game is a lot more fun than the film. -Sentiment: +I'll bet the video game is a lot more fun than the film ``` Click the **Submit** button. @@ -135,13 +125,14 @@ Once the model has completed processing your input, you'll see the results, star In this case, the prompter text becomes: ``` -Please label the sentiment towards the movie of the given movie review. The sentiment label should be "positive" or "negative". Text: (lawrence bounces) all over the stage, dancing, running, sweating, mopping his face and generally displaying the wacky talent that brought him fame in the first place. Sentiment: positive Text: despite all evidence to the contrary, this clunker has somehow managed to pose as an actual feature movie, the kind that charges full admission and gets hyped on tv and purports to amuse small children and ostensible adults. Sentiment: negative Text: for the first time in years, de niro digs deep emotionally, perhaps because he''s been stirred by the powerful work of his co-stars. Sentiment: positive \nText: I'll bet the video game is a lot more fun than the film. Sentiment: +Please label the sentiment towards the movie of the given movie review. The sentiment label should be "positive" or "negative". ### Text: (lawrence bounces) all over the stage, dancing, running, sweating, mopping his face and generally displaying the wacky talent that brought him fame in the first place. ### Sentiment: positive. ### Text: Despite all evidence to the contrary, this clunker has somehow managed to pose as an actual feature movie, the kind that charges full admission and gets hyped on tv and purports to amuse small children and ostensible adults. ### Sentiment: negative. ### Text: For the first time in years, de niro digs deep emotionally, perhaps because he''s been stirred by the powerful work of his co-stars. ### Sentiment: positive. ### Text: I'll bet the video game is a lot more fun than the film ### Sentiment: ``` And the output becomes: ``` negative ``` + ![few-shot prompting output](/img/agent-system-operators/prompter_3.png) Note that in the above few-shot prompt, we provided a few examples to guide the model to perform better. The demonstrations enabled in-context learning and acted as conditioning for successive examples in which we wanted the model to produce a response we desired. @@ -154,40 +145,32 @@ The prompt template can be used for a variety of prompting methods. Let's delve ## Task-Specific Prompt -Here is an example of a text classification task with a task-specific prompt. +Here is an example of a text classification task with a task-specific prompt. ``` -Human: You are a customer service agent that is classifying emails by type. - -Input: - -Hi -- My Mixmaster4000 is producing a strange noise when I operate it. It also smells a bit smoky and plasticky, like burning electronics. I need a replacement. - - -Categories are: -(A) Pre-sale question -(B) Broken or defective item -(C) Billing question -(D) Other (please explain) +### Instruction: You are a customer service agent that is classifying emails by type. ### Input: Hi -- My Mixmaster4000 is producing a strange noise when I operate it. It also smells a bit smoky and plasticky, like burning electronics. I need a replacement. Categories are: (A) Pre-sale question (B) Broken or defective item (C) Billing question (D) Other (please explain) ### Assistant: My answer is ( +``` -Assistant: My answer is ( +Response: -Response: B) Broken or defective item ``` +B) Broken or defective item +``` + ## Translation -Here is an example of a prompt for a text translation task. +Here is an example of a prompt text for a text translation task. ``` -Instruction: -{Translate the following phrase into French} - -Input: -{I miss you} +Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request. ### Instruction: Translate the following phrase into French. ### Input: I miss you ### Response: +``` Response: -{Je te manque} + ``` +Je te manque +``` + ## Pre-Encoded Knowledge QA This involves utilizing the model's built-in pre-encoded knowledge base to respond to questions. The model is provided with a large collection of facts and relationships, which it uses to generate answers when given prompts or questions. @@ -197,11 +180,13 @@ The pre-existing knowledge base equips the model with the ability to answer ques Here is an example. ``` -Instruction: -{What did Albert Einstein win the Nobel Prize for?} +Below is an instruction that describes a task. Write a response that appropriately completes the request. ### Instruction: How did Julius Caesar die? ### Response: +``` Response: -{The law of the photoelectric effect} + +``` +Julius Caesar was assassinated by a group of up to 60 conspirators, led by Gaius Cassius Longinus and Marcus Junius Brutus, in the Senate House on the Ides of March (15 March) of 44 BC. ``` ## Close-Book QA @@ -213,19 +198,7 @@ This stands in contrast to open-book QA, where the LLM can access and process ex Here is an example of a close-book QA with a model specific prompt. ``` -Below is a document, followed by a question. Answer the question using information in the document. Respond using only information in the document below. Do not provide any other information that is not in the docuemnt. - -Input: - -{{DOCUMENT}} - -Instruction: - -{{QUESTION}} - -Response: - -{{ANSWER}} +Below is a document, followed by a question. Answer the question using information in the document. Respond using only information in the document below. Do not provide any other information that is not in the document. ### Input: {{DOCUMENT}} ### Instruction: {{QUESTION}} ### Response: ``` ## Text Extraction @@ -233,13 +206,6 @@ Response: Here is an example of a prompt for a text extraction task. ``` -Please precisely copy any email addresses from the following text -and then write them, one per line. Only write an email address if it's precisely spelled out in the input text. -If there are no email addresses in the text, write "N/A". Do not say anything else. - -Input: -{{TEXT}} - -Response: +Please precisely copy any email addresses from the following text and then write them, one per line. Only write an email address if it's precisely spelled out in the input text. If there are no email addresses in the text, write "N/A". Do not say anything else. ### Input: {{TEXT}}. ### Response: ``` diff --git a/static/img/agent-system-operators/prompter_2.png b/static/img/agent-system-operators/prompter_2.png index 82a1f7331c..e180ba6cd9 100644 Binary files a/static/img/agent-system-operators/prompter_2.png and b/static/img/agent-system-operators/prompter_2.png differ diff --git a/static/img/agent-system-operators/prompter_3.png b/static/img/agent-system-operators/prompter_3.png index bcbf518ac4..17b53cfc23 100644 Binary files a/static/img/agent-system-operators/prompter_3.png and b/static/img/agent-system-operators/prompter_3.png differ