# Sample foundation model prompts for common tasks #

Try these samples to learn how different prompts can guide foundation models to do common tasks\.

## How to use this topic ##

Explore the sample prompts in this topic:

<!-- <ul> -->

 *  Copy and paste the prompt text and input parameter values into the Prompt Lab in IBM watsonx\.ai
 *  See what text is generated\.
 *  See how different models generate different output\.
 *  Change the prompt text and parameters to see how results vary\.

<!-- </ul> -->

There is no one right way to prompt foundation models\. But patterns have been found, in academia and industry, that work fairly reliably\. Use the samples in this topic to build your skills and your intuition about prompt engineering through experimentation\.

This video provides a visual method to learn the concepts and tasks in this documentation\.

**Video chapters**  
\[ 0:11 \] Introduction to prompts and Prompt Lab  
\[ 0:33 \] Key concept: Everything is text completion  
\[ 1:34 \] Useful prompt pattern: Few\-shot prompt  
\[ 1:58 \] Stopping criteria: Max tokens, stop sequences  
\[ 3:32 \] Key concept: Fine\-tuning  
\[ 4:32 \] Useful prompt pattern: Zero\-shot prompt  
\[ 5:32 \] Key concept: Be flexible, try different prompts  
\[ 6:14 \] Next steps: Experiment with sample prompts  

## Samples overview ##

You can find samples that prompt foundation models to generate output that supports the following tasks:

<!-- <ul> -->

 *  [Classification](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#classification)
 *  [Extraction](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#extraction)
 *  [Generation](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#generation)
 *  [Question answering (QA)](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#qa)
 *  [Summarization](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#summarization)
 *  [Code generation and conversion](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#code)
 *  [Dialogue](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#dialogue)

<!-- </ul> -->

The following table shows the foundation models that are used in task\-specific samples\. A checkmark indicates that the model is used in a sample for the associated task\.

<!-- <table> -->

Table 1\. Models used in samples for certain tasks

| Model                      | Classification | Extraction | Generation | QA | Summarization | Coding | Dialogue |
| -------------------------- | -------------- | ---------- | ---------- | -- | ------------- | ------ | -------- |
| flan\-t5\-xxl\-11b         | ✓              |            |            | ✓  |               |        |          |
| flan\-ul2\-20b             | ✓              | ✓          |            | ✓  |               |        |          |
| gpt\-neox\-20b             | ✓              |            | ✓          |    | ✓             |        |          |
| granite\-13b\-chat\-v1     |                |            |            |    |               |        | ✓        |
| granite\-13b\-instruct\-v1 |                |            | ✓          | ✓  |               |        |          |
| granite\-13b\-instruct\-v2 |                | ✓          | ✓          | ✓  |               |        |          |
| llama\-2 chat              |                |            |            |    |               |        | ✓        |
| mpt\-7b\-instruct2         | ✓              |            |            |    | ✓             |        |          |
| mt0\-xxl\-13b              | ✓              |            |            | ✓  |               |        |          |
| starcoder\-15\.5b          |                |            |            |    |               | ✓      |          |

<!-- </table ""> -->

The following table summarizes the available sample prompts\.

<!-- <table> -->

Table 2\. List of sample prompts

| Scenario                                                                                                                             | Prompt editor | Prompt format    | Model                                                                | Decoding | Notes                                                                                                               |
| ------------------------------------------------------------------------------------------------------------------------------------ | ------------- | ---------------- | -------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------- |
| [Sample 1a: Classify a message](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample1a)                                                                       | Freeform      | Zero\-shot       | • mt0\-xxl\-13b  <br>• flan\-t5\-xxl\-11b  <br>• flan\-ul2\-20b      | Greedy   | • Uses the class names as stop sequences to stop the model after it prints the class name                           |
| [Sample 1b: Classify a message](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample1b)                                                                       | Freeform      | Few\-shot        | • gpt\-neox\-20b  <br>• mpt\-7b\-instruct                            | Greedy   | • Uses the class names as stop sequences                                                                            |
| [Sample 1c: Classify a message](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample1c)                                                                       | Structured    | Few\-shot        | • gpt\-neox\-20b  <br>• mpt\-7b\-instruct                            | Greedy   | • Uses the class names as stop sequences                                                                            |
| [Sample 2a: Extract details from a complaint](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample2a)                                           | Freeform      | Zero\-shot       | • flan\-ul2\-20b  <br>• granite\-13b\-instruct\-v2                   | Greedy   |                                                                                                                     |
| [Sample 3a: Generate a numbered list on a particular theme](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample3a)               | Freeform      | Few\-shot        | • gpt\-neox\-20b                                                     | Sampling | • Generates formatted output  <br>• Uses two newline characters as a stop sequence to stop the model after one list |
| [Sample 3b: Generate a numbered list on a particular theme](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample3b)               | Structured    | Few\-shot        | • gpt\-neox\-20b                                                     | Sampling | • Generates formatted output\.  <br>• Uses two newline characters as a stop sequence                                |
| [Sample 3c: Generate a numbered list on a particular theme](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample3c)               | Freeform      | Zero\-shot       | • granite\-13b\-instruct\-v1  <br>• granite\-13b\-instruct\-v2       | Greedy   | • Generates formatted output                                                                                        |
| [Sample 4a: Answer a question based on an article](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample4a)                                 | Freeform      | Zero\-shot       | • mt0\-xxl\-13b  <br>• flan\-t5\-xxl\-11b  <br>• flan\-ul2\-20b      | Greedy   | • Uses a period "\." as a stop sequence to cause the model to return only a single sentence                         |
| [Sample 4b: Answer a question based on an article](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample4b)                                 | Structured    | Zero\-shot       | • mt0\-xxl\-13b  <br>• flan\-t5\-xxl\-11b  <br>• flan\-ul2\-20b      | Greedy   | • Uses a period "\." as a stop sequence  <br>• Generates results for multiple inputs at once                        |
| [Sample 4c: Answer a question based on a document](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample4c)                                 | Freeform      | Zero\-shot       | • granite\-13b\-instruct\-v2                                         | Greedy   |                                                                                                                     |
| [Sample 4d: Answer general knowledge questions](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample4d)                                       | Freeform      | Zero\-shot       | • granite\-13b\-instruct\-v1                                         | Greedy   |                                                                                                                     |
| [Sample 5a: Summarize a meeting transcript](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample5a)                                               | Freeform      | Zero\-shot       | • flan\-t5\-xxl\-11b  <br>• flan\-ul2\-20b  <br>• mpt\-7b\-instruct2 | Greedy   |                                                                                                                     |
| [Sample 5b: Summarize a meeting transcript](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample5b)                                               | Freeform      | Few\-shot        | • gpt\-neox\-20b                                                     | Greedy   |                                                                                                                     |
| [Sample 5c: Summarize a meeting transcript](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample5c)                                               | Structured    | Few\-shot        | • gpt\-neox\-20b                                                     | Greedy   | • Generates formatted output  <br>• Uses two newline characters as a stop sequence to stop the model after one list |
| [Sample 6a: Generate programmatic code from instructions](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample6a)                   | Freeform      | Few\-shot        | • starcoder\-15\.5b                                                  | Greedy   | • Generates programmatic code as output  <br>• Uses <end of code> as a stop sequence                          |
| [Sample 6b: Convert code from one programming language to another](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample6b) | Freeform      | Few\-shot        | • starcoder\-15\.5b                                                  | Greedy   | • Generates programmatic code as output  <br>• Uses <end of code> as a stop sequence                          |
| [Sample 7a: Converse in a dialogue](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample7a)                                                               | Freeform      | Custom structure | • granite\-13b\-chat\-v1                                             | Greedy   | • Generates dialogue output like a chatbot  <br>• Uses a special token that is named END\_KEY as a stop sequence    |
| [Sample 7b: Converse in a dialogue](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-samples.html?context=cdpaas&locale=en#sample7b)                                                               | Freeform      | Custom structure | • llama\-2 chat                                                      | Greedy   | • Generates dialogue output like a chatbot  <br>• Uses a model\-specific prompt format                              |

<!-- </table ""> -->

## Classification ##

Classification is useful for predicting data in distinct categories\. Classifications can be binary, with two classes of data, or multi\-class\. A classification task is useful for categorizing information, such as customer feedback, so that you can manage or act on the information more efficiently\.

### Sample 1a: Classify a message ###

Scenario: Given a message that is submitted to a customer\-support chatbot for a cloud software company, classify the customer's message as either a question or a problem\. Depending on the class assignment, the chat is routed to the correct support team for the issue type\.

**Model choice**  
Models that are instruction\-tuned can generally complete this task with this sample prompt\. Suggestions: mt0\-xxl\-13b, flan\-t5\-xxl\-11b, or flan\-ul2\-20b

**Decoding**  
Greedy\. The model must return one of the specified class names; it cannot be creative and make up new classes\.

**Stopping criteria**  

<!-- <ul> -->

 *  Specify two stop sequences: "Question" and "Problem"\. After the model generates either of those words, it should stop\.
 *  With such short output, the Max tokens parameter can be set to 5\.

<!-- </ul> -->

**Prompt text**  
Paste this zero\-shot prompt text into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

    Classify this customer message into one of two classes: Question, Problem.
    
    Class name: Question
    Description: The customer is asking a technical question or a how-to question 
    about our products or services.
    
    Class name: Problem
    Description: The customer is describing a problem they are having. They might 
    say they are trying something, but it's not working. They might say they are 
    getting an error or unexpected results.
    
    Message: I'm having trouble registering for a new account.
    Class name:

### Sample 1b: Classify a message ###

Scenario: Given a message that is submitted to a customer\-support chatbot for a cloud software company, classify the customer's message as either a question or a problem description\. Based on the class type, the chat can be routed to the correct support team\.

**Model choice**  
With few\-shot examples of both classes, most models can complete this task well, including: gpt\-neox\-20b and mpt\-7b\-instruct\.

**Decoding**  
Greedy\. The model must return one of the specified class names; it cannot be creative and make up new classes\.

**Stopping criteria**  

<!-- <ul> -->

 *  Specify two stop sequences: "Question" and "Problem"\. After the model generates either of those words, it should stop\.
 *  With such short output, the Max tokens parameter can be set to 5\.

<!-- </ul> -->

**Prompt text**  
Paste this few\-shot prompt text into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

    Message: When I try to log in, I get an error.
    Class name: Problem
    
    Message: Where can I find the plan prices?
    Class name: Question
    
    Message: What is the difference between trial and paygo?
    Class name: Question
    
    Message: The registration page crashed, and now I can't create a new account.
    Class name: Problem
    
    Message: What regions are supported?
    Class name: Question
    
    Message: I can't remember my password.
    Class name: Problem
    
    Message: I'm having trouble registering for a new account.

### Sample 1c: Classify a message ###

Scenario: Given a message that is submitted to a customer\-support chatbot for a cloud software company, classify the customer's message as either a question or a problem description\. Based on the class type, the chat can be routed to the correct support team\.

**Model choice**  
With few\-shot examples of both classes, most models can complete this task well, including: gpt\-neox\-20b and mpt\-7b\-instruct\.

**Decoding**  
Greedy\. The model must return one of the specified class names, not be creative and make up new classes\.

**Stopping criteria**  

<!-- <ul> -->

 *  Specify two stop sequences: "Question" and "Problem"\. After the model generates either of those words, it should stop\.
 *  With such short output, the Max tokens parameter can be set to 5\.

<!-- </ul> -->

**Set up section**  
Paste these headers and examples into the **Examples** area of the **Set up** section:

<!-- <table> -->

Table 2\. Classification few\-shot examples

| **Message:**                                                           | **Class name:** |
| ---------------------------------------------------------------------- | --------------- |
| `When I try to log in, I get an error.`                                | `Problem`       |
| `Where can I find the plan prices?`                                    | `Question`      |
| `What is the difference between trial and paygo?`                      | `Question`      |
| `The registration page crashed, and now I can't create a new account.` | `Problem`       |
| `What regions are supported?`                                          | `Question`      |
| `I can't remember my password.`                                        | `Problem`       |

<!-- </table ""> -->

**Try section**  
Paste this message in the **Try** section:

    I'm having trouble registering for a new account.

Select the model and set parameters, then click **Generate** to see the result\.

## Extracting details ##

Extraction tasks can help you to find key terms or mentions in data based on the semantic meaning of words rather than simple text matches\.

### Sample 2a: Extract details from a complaint ###

Scenario: Given a complaint from a customer who had trouble booking a flight on a reservation website, identify the factors that contributed to this customer's unsatisfactory experience\.

**Model choices**  
flan\-ul2\-20b, granite\-13b\-instruct\-v2

**Decoding**  
Greedy\. We need the model to return words that are in the input; the model cannot be creative and make up new words\.

**Stopping criteria**  
The list of extracted factors will not be long, so set the Max tokens parameter to 50\.

**Prompt text**  
Paste this zero\-shot prompt text into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

    From the following customer complaint, extract all the factors that 
    caused the customer to be unhappy.
    
    Customer complaint:
    I just tried to book a flight on your incredibly slow website. All 
    the times and prices were confusing. I liked being able to compare 
    the amenities in economy with business class side by side. But I 
    never got to reserve a seat because I didn't understand the seat map. 
    Next time, I'll use a travel agent!
    
    Numbered list of all the factors that caused the customer to be unhappy:

## Generating natural language ##

Generation tasks are what large language models do best\. Your prompts can help guide the model to generate useful language\.

### Sample 3a: Generate a numbered list on a particular theme ###

Scenario: Generate a numbered list on a particular theme\.

**Model choice**  
gpt\-neox\-20b was trained to recognize and handle special characters, such as the newline character, well\. This model is a good choice when you want your generated text to be formatted a specific way with special characters\.

**Decoding**  
Sampling\. This is a creative task\. Set the following parameters:

<!-- <ul> -->

 *  Temperature: 0\.7
 *  Top P: 1
 *  Top K: 50
 *  Random seed: 9045 (To get different output each time you click **Generate**, specify a different value for the Random seed parameter or clear the parameter\.)

<!-- </ul> -->

**Stopping criteria**  

<!-- <ul> -->

 *  To make sure the model stops generating text after one list, specify a stop sequence of two newline characters\. To do that, click the **Stop sequence** text box, press the Enter key twice, then click **Add sequence**\.
 *  The list will not be very long, so set the Max tokens parameter to 50\.

<!-- </ul> -->

**Prompt text**  
Paste this few\-shot prompt text into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

    What are 4 types of dog breed?
    1. Poodle
    2. Dalmatian
    3. Golden retriever
    4. Bulldog
    
    What are 3 ways to incorporate exercise into your day?
    1. Go for a walk at lunch
    2. Take the stairs instead of the elevator
    3. Park farther away from your destination
    
    What are 4 kinds of vegetable?
    1. Spinach
    2. Carrots
    3. Broccoli
    4. Cauliflower
    
    What are the 3 primary colors?
    1. Red
    2. Green
    3. Blue
    
    What are 3 ingredients that are good on pizza?

### Sample 3b: Generate a numbered list on a particular theme ###

Scenario: Generate a numbered list on a particular theme\.

**Model choice**  
gpt\-neox\-20b was trained to recognize and handle special characters, such as the newline character, well\. This model is a good choice when you want your generated text to be formatted in a specific way with special characters\.

**Decoding**  
Sampling\. This scenario is a creative one\. Set the following parameters:

<!-- <ul> -->

 *  Temperature: 0\.7
 *  Top P: 1
 *  Top K: 50
 *  Random seed: 9045 (To generate different results, specify a different value for the Random seed parameter or clear the parameter\.)

<!-- </ul> -->

**Stopping criteria**  

<!-- <ul> -->

 *  To make sure that the model stops generating text after one list, specify a stop sequence of two newline characters\. To do that, click in the **Stop sequence** text box, press the Enter key twice, then click **Add sequence**\.
 *  The list will not be long, so set the Max tokens parameter to 50\.

<!-- </ul> -->

**Set up section**  
Paste these headers and examples into the **Examples** area of the **Set up** section:

<!-- <table> -->

Table 3\. Generation few\-shot examples

| **`Input:`**                                             | **`Output:`**                                                                                                     |
| -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `What are 4 types of dog breed?`                         | `1. Poodle 2. Dalmatian 3. Golden retriever 4. Bulldog`                                                           |
| `What are 3 ways to incorporate exercise into your day?` | `1. Go for a walk at lunch 2. Take the stairs instead of the elevator 3. Park farther away from your destination` |
| `What are 4 kinds of vegetable?`                         | `1. Spinach 2. Carrots 3. Broccoli 4. Cauliflower`                                                                |
| `What are the 3 primary colors?`                         | `1. Red 2. Green 3. Blue`                                                                                         |

<!-- </table ""> -->

**Try section**  
Paste this input in the **Try** section:

    What are 3 ingredients that are good on pizza?

Select the model and set parameters, then click **Generate** to see the result\.

### Sample 3c: Generate a numbered list on a particular theme ###

Scenario: Ask the model to play devil's advocate\. Describe a potential action and ask the model to list possible downsides or risks that are associated with the action\.

**Model choice**  
Similar to gpt\-neox\-20b, the granite\-13b\-instruct model was trained to recognize and handle special characters, such as the newline character, well\. The granite\-13b\-instruct\-v2 oe granite\-13b\-instruct\-v1 model is a good choice when you want your generated text to be formatted in a specific way with special characters\.

**Decoding**  
Greedy\. The model must return the most predictable content based on what's in the prompt; the model cannot be too creative\.

**Stopping criteria**  
The summary might run several sentences, so set the Max tokens parameter to 60\.

**Prompt text**  
Paste this prompt text into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

    You are playing the role of devil's advocate. Argue against the proposed plans. List 3 detailed, unique, compelling reasons why moving forward with the plan would be a bad choice. Consider all types of risks.
    
    Plan we are considering:
    Extend our store hours.
    Three problems with this plan are:
    1. We'll have to pay more for staffing.
    2. Risk of theft increases late at night.
    3. Clerks might not want to work later hours.
    
    Plan we are considering:
    Open a second location for our business.
    Three problems with this plan are:
    1. Managing two locations will be more than twice as time-consuming than managed just one.
    2. Creating a new location doesn't guarantee twice as many customers.
    3. A new location means added real estate, utility, and personnel expenses.
    
    Plan we are considering:
    Refreshing our brand image by creating a new logo.
    Three problems with this plan are:

## Question answering ##

Question\-answering tasks are useful in help systems and other scenarios where frequently asked or more nuanced questions can be answered from existing content\.

To help the model return factual answers, implement the retrieval\-augmented generation pattern\. For more information, see [Retrieval\-augmented generation](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-rag.html)\.

### Sample 4a: Answer a question based on an article ###

Scenario: The website for an online seed catalog has many articles to help customers plan their garden and ultimately select which seeds to purchase\. A new widget is being added to the website to answer customer questions based on the contents of the article the customer is viewing\. Given a question that is related to an article, answer the question based on the article\.

**Model choice**  
Models that are instruction\-tuned, such as mt0\-xxl\-13b, flan\-t5\-xxl\-11b, or flan\-ul2\-20b, can generally complete this task with this sample prompt\.

**Decoding**  
Greedy\. The answers must be grounded in the facts in the article, and if there is no good answer in the article, the model should not be creative and make up an answer\.

**Stopping criteria**  
To cause the model to return a one\-sentence answer, specify a period "\." as a stop sequence\. The Max tokens parameter can be set to 50\.

**Prompt text**  
Paste this zero\-shot prompt text into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

    Article:
    ###
    Tomatoes are one of the most popular plants for vegetable gardens. 
    Tip for success: If you select varieties that are resistant to 
    disease and pests, growing tomatoes can be quite easy. For 
    experienced gardeners looking for a challenge, there are endless 
    heirloom and specialty varieties to cultivate. Tomato plants come 
    in a range of sizes. There are varieties that stay very small, less 
    than 12 inches, and grow well in a pot or hanging basket on a balcony 
    or patio. Some grow into bushes that are a few feet high and wide, 
    and can be grown is larger containers. Other varieties grow into 
    huge bushes that are several feet wide and high in a planter or 
    garden bed. Still other varieties grow as long vines, six feet or 
    more, and love to climb trellises. Tomato plants do best in full 
    sun. You need to water tomatoes deeply and often. Using mulch 
    prevents soil-borne disease from splashing up onto the fruit when you 
    water. Pruning suckers and even pinching the tips will encourage the 
    plant to put all its energy into producing fruit.
    ###
    
    Answer the following question using only information from the article. 
    Answer in a complete sentence, with proper capitalization and punctuation. 
    If there is no good answer in the article, say "I don't know".
    
    Question: Why should you use mulch when growing tomatoes?
    Answer:

You can experiment with asking other questions too, such as:

<!-- <ul> -->

 *  How large do tomato plants get?
 *  Do tomato plants prefer shade or sun?
 *  Is it easy to grow tomatoes?

<!-- </ul> -->

Try out\-of\-scope questions too, such as:

<!-- <ul> -->

 *  How do you grow cucumbers?

<!-- </ul> -->

### Sample 4b: Answer a question based on an article ###

Scenario: The website for an online seed catalog has many articles to help customers plan their garden and ultimately select which seeds to purchase\. A new widget is being added to the website to answer customer questions based on the contents of the article the customer is viewing\. Given a question related to a particular article, answer the question based on the article\.

**Model choice**  
Models that are instruction\-tuned, such as mt0\-xxl\-13b, flan\-t5\-xxl\-11b, or flan\-ul2\-20b, can generally complete this task with this sample prompt\.

**Decoding**  
Greedy\. The answers must be grounded in the facts in the article, and if there is no good answer in the article, the model should not be creative and make up an answer\.

**Stopping criteria**  
To cause the model to return a one\-sentence answer, specify a period "\." as a stop sequence\. The Max tokens parameter can be set to 50\.

**Set up section**  
Paste this text into the **Instruction** area of the **Set up** section:

    Article:
    ###
    Tomatoes are one of the most popular plants for vegetable gardens. 
    Tip for success: If you select varieties that are resistant to 
    disease and pests, growing tomatoes can be quite easy. For 
    experienced gardeners looking for a challenge, there are endless 
    heirloom and specialty varieties to cultivate. Tomato plants come 
    in a range of sizes. There are varieties that stay very small, less 
    than 12 inches, and grow well in a pot or hanging basket on a balcony 
    or patio. Some grow into bushes that are a few feet high and wide, 
    and can be grown is larger containers. Other varieties grow into 
    huge bushes that are several feet wide and high in a planter or 
    garden bed. Still other varieties grow as long vines, six feet or 
    more, and love to climb trellises. Tomato plants do best in full 
    sun. You need to water tomatoes deeply and often. Using mulch 
    prevents soil-borne disease from splashing up onto the fruit when you 
    water. Pruning suckers and even pinching the tips will encourage the 
    plant to put all its energy into producing fruit.
    ###
    
    Answer the following question using only information from the article. 
    Answer in a complete sentence, with proper capitalization and punctuation. 
    If there is no good answer in the article, say "I don't know".

**Try section**  
In the **Try** section, add an extra test row so you can paste each of these two questions in a separate row:

    Why should you use mulch when growing tomatoes?

    How do you grow cucumbers?

Select the model and set parameters, then click **Generate** to see two results\.

### Sample 4c: Answer a question based on a document ###

Scenario: You are creating a chatbot that can answer user questions\. When a user asks a question, you want the agent to answer the question with information from a specific document\.

**Model choice**  
Models that are instruction\-tuned, such as granite\-13b\-instruct\-v2, can complete the task with this sample prompt\.

**Decoding**  
Greedy\. The answers must be grounded in the facts in the document, and if there is no good answer in the article, the model should not be creative and make up an answer\.

**Stopping criteria**  
Use a Max tokens parameter of 50\.

**Prompt text**  
Paste this zero\-shot prompt text into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

    Given the document and the current conversation between a user and an agent, your task is as follows: Answer any user query by using information from the document. The response should be detailed.
    
    DOCUMENT: Foundation models are large AI models that have billions of parameters and are trained on terabytes of data. Foundation models can do various tasks, including text, code, or image generation, classification, conversation, and more. Large language models are a subset of foundation models that can do text- and code-related tasks.
    DIALOG: USER: What are foundation models?

### Sample 4d: Answer general knowledge questions ###

Scenario: Answer general questions about finance\.

**Model choice**  
The granite\-13b\-instruct\-v1 model can be used for multiple tasks, including text generation, summarization, question and answering, classification, and extraction\.

**Decoding**  
Greedy\. This sample is answering questions, so we don't want creative output\.

**Stopping criteria**  
Set the **Max tokens parameter** to 200 so the model can return a complete answer\.

**Prompt text**  
The model was tuned for question\-answering with examples in the following format:

`
`  
*content of the question*  
\`<\|assistant\|>  
*new line for the model's answer*  

You can use the exact syntax `
` and `
` in the lines before and after the question or you can replace the values with equivalent terms, such as `User` and `Assistant`\.

If you're using version 1, do not include any trailing white spaces after the `<\assistant\>` label, and be sure to add a new line\.

Paste this prompt text into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

    

    Tell me about interest rates
    


After the model generates an answer, you can ask a follow\-up question\. The model uses information from the previous question when it generates a response\.

    

    Who sets it?
    


The model retains information from a previous question when it answers a follow\-up question, but it is not optimized to support an extended dialogue\.

Note: When you ask a follow\-up question, the previous question is submitted again, which adds to the number of tokens that are used\.

## Summarization ##

Summarization tasks save you time by condensing large amounts of text into a few key pieces of information\.

### Sample 5a: Summarize a meeting transcript ###

Scenario: Given a meeting transcript, summarize the main points as meeting notes so those notes can be shared with teammates who did not attend the meeting\.

**Model choice**  
Models that are instruction\-tuned can generally complete this task with this sample prompt\. Suggestions: flan\-t5\-xxl\-11b, flan\-ul2\-20b, or mpt\-7b\-instruct2\.

**Decoding**  
Greedy\. The model must return the most predictable content based on what's in the prompt; the model cannot be too creative\.

**Stopping criteria**  
The summary might run several sentences, so set the Max tokens parameter to 60\.

**Prompt text**  
Paste this zero\-shot prompt text into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

    Summarize the following transcript.
    Transcript:
    00:00   [alex]  Let's plan the team party!
    00:10   [ali]   How about we go out for lunch at the restaurant?
    00:21   [sam]   Good idea.
    00:47   [sam]   Can we go to a movie too?
    01:04   [alex]  Maybe golf?
    01:15   [sam]   We could give people an option to do one or the other.
    01:29   [alex]  I like this plan. Let's have a party!
    Summary:

### Sample 5b: Summarize a meeting transcript ###

Scenario: Given a meeting transcript, summarize the main points as meeting notes so those notes can be shared with teammates who did not attend the meeting\.

**Model choice**  
With few\-shot examples, most models can complete this task well\. Try: gpt\-neox\-20b\.

**Decoding**  
Greedy\. The model must return the most predictable content based on what's in the prompt, not be too creative\.

**Stopping criteria**  

<!-- <ul> -->

 *  To make sure that the model stops generating text after the summary, specify a stop sequence of two newline characters\. To do that, click in the **Stop sequence** text box, press the Enter key twice, then click **Add sequence**\.
 *  Set the Max tokens parameter to 60\.

<!-- </ul> -->

**Prompt text**  
Paste this few\-shot prompt text into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

    Transcript:
    00:00   [sam]   I wanted to share an update on project X today.
    00:15   [sam]   Project X will be completed at the end of the week.
    00:30   [erin]  That's great!
    00:35   [erin]  I heard from customer Y today, and they agreed to buy our product.
    00:45   [alex]  Customer Z said they will too.
    01:05   [sam]   Great news, all around.
    Summary:
    Sam shared an update that project X will be complete at the end of the week. 
    Erin said customer Y will buy our product. And Alex said customer Z will buy 
    our product too.
    
    Transcript:
    00:00   [ali]   The goal today is to agree on a design solution.
    00:12   [alex]  I think we should consider choice 1.
    00:25   [ali]   I agree
    00:40   [erin]  Choice 2 has the advantage that it will take less time.
    01:03   [alex]  Actually, that's a good point.
    01:30   [ali]   So, what should we do?
    01:55   [alex]  I'm good with choice 2.
    02:20   [erin]  Me too.
    02:45   [ali]   Done!
    Summary:
    Alex suggested considering choice 1. Erin pointed out choice two will take 
    less time. The team agreed with choice 2 for the design solution.
    
    Transcript:
    00:00   [alex]  Let's plan the team party!
    00:10   [ali]   How about we go out for lunch at the restaurant?
    00:21   [sam]   Good idea.
    00:47   [sam]   Can we go to a movie too?
    01:04   [alex]  Maybe golf?
    01:15   [sam]   We could give people an option to do one or the other.
    01:29   [alex]  I like this plan. Let's have a party!
    Summary:

### Sample 5c: Summarize a meeting transcript ###

Scenario: Given a meeting transcript, summarize the main points in a bulleted list so that the list can be shared with teammates who did not attend the meeting\.

**Model choice**  
gpt\-neox\-20b was trained to recognize and handle special characters, such as the newline character, well\. This model is a good choice when you want your generated text to be formatted in a specific way with special characters\.

**Decoding**  
Greedy\. The model must return the most predictable content based on what's in the prompt; the model cannot be too creative\.

**Stopping criteria**  

<!-- <ul> -->

 *  To make sure that the model stops generating text after one list, specify a stop sequence of two newline characters\. To do that, click in the **Stop sequence** text box, press the Enter key twice, then click **Add sequence**\.
 *  Set the Max tokens parameter to 60\.

<!-- </ul> -->

**Set up section**  
Paste these headers and examples into the **Examples** area of the **Set up** section:

<!-- <table> -->

Table 4\. Summarization few\-shot examples

| **`Transcript:`**                                                                                                                                                                                                                                                                                                                                                    | **`Summary:`**                                                                                                                                                                  |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `00:00 [sam] I wanted to share an update on project X today. 00:15 [sam] Project X will be completed at the end of the week. 00:30 [erin] That's great! 00:35 [erin] I heard from customer Y today, and they agreed to buy our product. 00:45 [alex] Customer Z said they will too. 01:05 [sam] Great news, all around.`                                             | `- Sam shared an update that project X will be complete at the end of the week - Erin said customer Y will buy our product - And Alex said customer Z will buy our product too` |
| `00:00 [ali] The goal today is to agree on a design solution. 00:12 [alex] I think we should consider choice 1. 00:25 [ali] I agree 00:40 [erin] Choice 2 has the advantage that it will take less time. 01:03 [alex] Actually, that's a good point. 01:30 [ali] So, what should we do? 01:55 [alex] I'm good with choice 2. 02:20 [erin] Me too. 02:45 [ali] Done!` | `- Alex suggested considering choice 1 - Erin pointed out choice two will take less time - The team agreed with choice 2 for the design solution`                               |

<!-- </table ""> -->

**Try section**  
Paste this message in the **Try** section:

    00:00   [alex]  Let's plan the team party!
    00:10   [ali]   How about we go out for lunch at the restaurant?
    00:21   [sam]   Good idea.
    00:47   [sam]   Can we go to a movie too?
    01:04   [alex]  Maybe golf?
    01:15   [sam]   We could give people an option to do one or the other.
    01:29   [alex]  I like this plan. Let's have a party!

Select the model and set parameters, then click **Generate** to see the result\.

## Code generation and conversion ##

Foundation models that can generate and convert programmatic code are great resources for developers\. They can help developers to brainstorm and troubleshoot programming tasks\.

### Sample 6a: Generate programmatic code from instructions ###

Scenario: You want to generate code from instructions\. Namely, you want to write a function in the Python programming language that returns a sequence of prime numbers that are lower than the number that is passed to the function as a variable\.

**Model choice**  
Models that can generate code, such as starcoder\-15\.5b, can generally complete this task when a sample prompt is provided\.

**Decoding**  
Greedy\. The answer must be a valid code snippet\. The model cannot be creative and make up an answer\.

**Stopping criteria**  
To stop the model after it returns a single code snippet, specify `<end of code>` as the stop sequence\. The Max tokens parameter can be set to 1,000\.

**Prompt text**  
Paste this code snippet into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

    Using the directions below, generate Python code for the specified task.
    
    Input:
    # Write a Python function that prints 'Hello World!' string 'n' times.
    
    Output:
    def print_n_times(n):
        for i in range(n):
            print("Hello World!")
    
    <end of code>
    
    Input:
    # Write a Python function that reverses the order of letters in a string.
    # The function named 'reversed' takes the argument 'my_string', which is a string. It returns the string in reverse order.
    
    Output:

The output contains Python code similar to the following snippet:

    def reversed(my_string):
        return my_string[::-1]

Be sure to test the generated code to verify that it works as you expect\.

For example, if you run `reversed("good morning")`, the result is `'gninrom doog'`\.

Note: The StarCoder model might generate code that is taken directly from its training data\. As a result, generated code might require attribution\. You are responsible for ensuring that any generated code that you use is properly attributed, if necessary\.

### Sample 6b: Convert code from one programming language to another ###

Scenario: You want to convert code from one programming language to another\. Namely, you want to convert a code snippet from C\+\+ to Python\.

**Model choice**  
Models that can generate code, such as starcoder\-15\.5b, can generally complete this task when a sample prompt is provided\.

**Decoding**  
Greedy\. The answer must be a valid code snippet\. The model cannot be creative and make up an answer\.

**Stopping criteria**  
To stop the model after it returns a single code snippet, specify `<end of code>` as the stop sequence\. The Max tokens parameter can be set to 300\.

**Prompt text**  
Paste this code snippet into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

This prompt includes an example input and output pair\. The input is C\+\+ code and the output is the equivalent function in Python code\.

The C\+\+ code snippet to be converted is included next\. It is a function that counts the number of arithmetic progressions with the sum `S` and common difference of `D`, where `S` and `D` are integer values that are passed as parameters\.

The final part of the prompt identifies the language that you want the C\+\+ code snippet to be converted into\.

    Translate the following code from C++ to Python.
    
    C++:
    #include "bits/stdc++.h"
    using namespace std;
    bool isPerfectSquare(long double x) {
      long double sr = sqrt(x);
      return ((sr - floor(sr)) == 0);
    }
    void checkSunnyNumber(int N) {
      if (isPerfectSquare(N + 1)) {
        cout << "Yes
    ";
      } else {
        cout << "No
    ";
      }
    }
    int main() {
      int N = 8;
      checkSunnyNumber(N);
      return 0;
    }
    
    Python:
    from math import *
    
    def isPerfectSquare(x):
        sr = sqrt(x)
        return ((sr - floor(sr)) == 0)
    
    def checkSunnyNumber(N):
        if (isPerfectSquare(N + 1)):
            print("Yes")
        else:
            print("No")
    
    if __name__ == '__main__':
        N = 8
        checkSunnyNumber(N)
    
    <end of code>
    
    C++:
    #include <bits/stdc++.h>
    using namespace std;
    int countAPs(int S, int D) {
      S = S * 2;
      int answer = 0;
      for (int i = 1; i <= sqrt(S); i++) {
        if (S % i == 0) {
          if (((S / i) - D * i + D) % 2 == 0)
            answer++;
          if ((D * i - (S / i) + D) % 2 == 0)
            answer++;
        }
      }
      return answer;
    }
    int main() {
      int S = 12, D = 1;
      cout << countAPs(S, D);
      return 0;
    }
    
    Python:

The output contains Python code similar to the following snippet:

    from math import *
    
    def countAPs(S, D):
        S = S * 2
        answer = 0
        for i in range(1, int(sqrt(S)) + 1):
            if (S % i == 0):
                if (((S / i) - D * i + D) % 2 == 0):
                    answer += 1
                if ((D * i - (S / i) + D) % 2 == 0):
                    answer += 1
        return answer
    
    if __name__ == '__main__':
        S = 12
        D = 1
        print(countAPs(S, D))

The generated Python code functions the same as the C\+\+ function included in the prompt\.

Test the generated Python code to verify that it works as you expect\.

Remember, the StarCoder model might generate code that is taken directly from its training data\. As a result, generated code might require attribution\. You are responsible for ensuring that any generated code that you use is properly attributed, if necessary\.

## Dialogue ##

Dialogue tasks are helpful in customer service scenarios, especially when a chatbot is used to guide customers through a workflow to reach a goal\.

### Sample 7a: Converse in a dialogue ###

Scenario: Generate dialogue output like a chatbot\.

**Model choice**  
Like other foundation models, granite\-13b\-chat can be used for multiple tasks\. However, it is optimized for carrying on a dialogue\.

**Decoding**  
Greedy\. This sample is answering general knowledge, factual questions, so we don't want creative output\.

**Stopping criteria**  

<!-- <ul> -->

 *  A helpful feature of the model is the inclusion of a special token that is named `END_KEY` at the end of each response\. When some generative models return a response to the input in fewer tokens than the maximum number allowed, they can repeat patterns from the input\. This model prevents such repetition by incorporating a reliable stop sequence for the prompt\. Add `END_KEY` as the stop sequence\.
 *  Set the **Max tokens parameter** to 200 so the model can return a complete answer\.

<!-- </ul> -->

**Prompt text**  
The model expects the input to follow a specific pattern\.

Start the input with an instruction\. For example, the instruction might read as follows:

Participate in a dialogue with various people as an AI assistant\. As the Assistant, you are upbeat, professional, and polite\. You do your best to understand exactly what the human needs and help them to achieve their goal as best you can\. You do not give false or misleading information\. If you don't know an answer, you state that you don't know or aren't sure about the right answer\. You prioritize caution over usefulness\. You do not answer questions that are unsafe, immoral, unethical, or dangerous\.

Next, add lines to capture the question and answer pattern with the following syntax:

Human:  
*content of the question*  
Assistant:  
*new line for the model's answer*  

You can replace the terms *Human* and *Assistant* with other terms\.

If you're using version 1, do not include any trailing white spaces after the *Assistant:* label, and be sure to add a new line\.

Paste the following prompt text into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

    Participate in a dialogue with various people as an AI assistant. As the Assistant, you are upbeat, professional, and polite. You do your best to understand exactly what the human needs and help them to achieve their goal as best you can. You do not give false or misleading information. You prioritize caution over usefulness. You do not answer questions that are unsafe, immoral, unethical, or dangerous.
    
    Human: How does a bill become a law?
    Assistant:

After the initial output is generated, continue the dialogue by asking a follow\-up question\. For example, if the output describes how a bill becomes a law in the United States, you can ask about how laws are made in other countries\.

    Human: What about in Canada?
    Assistant:

A few notes about using this sample with the model:

<!-- <ul> -->

 *  The prompt input outlines the chatbot scenario and describes the personality of the AI assistant\. The description explains that the assistant should indicate when it doesn't know an answer\. It also directs the assistant to avoid discussing unethical topics\.
 *  The assistant is able to respond to a follow\-up question that relies on information from an earlier exchange in the same dialogue\.
 *  The model expects the input to follow a specific pattern\.
 *  The generated response from the model is clearly indicated by the keyword `END_KEY`\. You can use this keyword as a stop sequence to help the model generate succinct responses\.

<!-- </ul> -->

### Sample 7b: Converse in a dialogue ###

Scenario: Generate dialogue output like a chatbot\.

**Model choice**  
Like other foundation models, Llama 2 (in both the 70 billion and 13 billion sizes) can be used for multiple tasks\. But both Llama 2 models are optimized for dialogue use cases\. The llama\-2\-70b\-chat and llama\-2\-13b\-chat are the only models in watsonx\.ai that are fine\-tuned for the `



` prompt format\. For more information about this prompt format, see [How to prompt Llama 2](https://huggingface.co/blog/llama2#how-to-prompt-llama-2)\.

**Decoding**  
Greedy\. This sample is answering general knowledge, factual questions, so we don't want creative output\.

**Stopping criteria**  
Set the Max tokens parameter to 100\.

The template for Llama 2 uses an end\-of\-string (EOS) token (`
`) to delimit the end of the agent's response\. The model output stops generating text when the `
` EOS token is encountered\.

**Prompt text**  
Paste this prompt text into the freeform prompt editor in Prompt Lab, select the model, set parameters, and then click **Generate** to see the result\.

    
 

    You are a helpful assistant. Begin each response with the phrase "Dear user, ". If you are unsure about an answer, truthfully say "I don't know"

    
    I have a question about the Earth.

    Dear user, go on.
    

    
    How many moons are there?
    


After the initial output is generated, continue the dialogue to ask about more planets, wrapping your user messages in the same `
` structure\. You don't need to add an `
` token to the start of follow\-up questions\.

The output looks something like this:

    
 

    You are a helpful assistant. Begin each response with the phrase "Dear user, ". If you are unsure about an answer, truthfully say "I don't know"

    
    I have a question about the Earth.

    Dear user, go on.
    

    
    How many moons are there?
    

    Dear user, the Earth has one natural satellite, commonly referred to as the Moon. 
    

    
    What about Saturn?
    

    Dear user, Saturn has a total of 62 confirmed moons, as well as numerous smaller moonlets and ring particles. The largest moon of Saturn is Titan, which is the second-largest moon in the solar system, after Jupiter's moon Ganymede. 
    

    
    And Mars?
    

    Dear user, Mars has two small natural satellites, Phobos and Deimos. Both moons are thought to be captured asteroids, and are irregularly shaped and very small, with diameters of about 22 kilometers and 12 kilometers respectively.

Notice a few important points about the output that the model generates as you go:

<!-- <ul> -->

 *  The so\-called *system instruction*, in the `

` tags, continues to influence the output at each dialogue turn without having to repeat the system instruction\. In other words, the *assistant responses* continue to be prepended with "Dear user, "\.
 *  In true dialogue fashion, the assistant response to the *user input* "How many moons are there?" takes into account the previous user input "I have a question about the Earth\." and returns the number of moons orbiting Earth\.
 *  Also in proper dialogue form, the assistant responses continue to follow the topic of the conversation, which is the number of moons\. (Otherwise, the generated output to the vague user message "And Mars?" could wander off in any direction\.)
 *  Caution: Newline (carriage\-return) characters especially, and spaces to a lesser extent, in the prompt text can have a dramatic impact on the output generated\.
 *  When you use Llama 2 for chat use cases, follow the recommended prompt template format as closely as possible\. Do not use the `



` prompt format when you use Llama 2 for any other tasks besides chat\.

<!-- </ul> -->

**Parent topic:**[Prompt Lab](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-lab.html)

<!-- </article "role="article" "> -->