0 / 0
Tips for writing foundation model prompts: prompt engineering
Last updated: Oct 09, 2024
Tips for writing foundation model prompts: prompt engineering

Part art, part science, prompt engineering is the process of crafting prompt text to best effect for a given model and parameters. When it comes to prompting foundation models, there isn't just one right answer. There are usually multiple ways to prompt a foundation model for a successful result.

Use the Prompt Lab to experiment with crafting prompts.

  • For help using the prompt editor, see Prompt Lab.
  • Try the samples that are available from the Sample prompts tab.
  • Learn from documented samples. See Sample prompts.

As you experiment, remember these tips. The tips in this topic will help you successfully prompt most text-generating foundation models.

 

Tip 1: Always remember that everything is text completion

Your prompt is the text you submit for processing by a foundation model.

The Prompt Lab in IBM watsonx.ai is not a chatbot interface. For most models, simply asking a question or typing an instruction usually won't yield the best results. That's because the model isn't answering your prompt, the model is appending text to it.

This image demonstrates prompt text and generated output:

  • Prompt text: "I took my dog "
  • Generated output: "to the park."

Text completion in Prompt Lab

 

Tip 2: Include all the needed prompt components

Effective prompts usually have one or more of the following components: instruction, context, examples, and cue.

Instruction

An instruction is an imperative statement that tells the model what to do. For example, if you want the model to list ideas for a dog-walking business, your instruction could be: "List ideas for starting a dog-walking business:"

Context

Including background or contextual information in your prompt can nudge the model output in a desired direction. Specifically, (tokenized) words that appear in your prompt text are more likely to be included in the generated output.

Examples

To indicate the format or shape that you want the model response to be, include one or more pairs of example input and corresponding desired output showing the pattern you want the generated text to follow. (Including one example in your prompt is called one-shot prompting, including two or more examples in your prompt is called few-shot prompting, and when your prompt has no examples, that's called zero-shot prompting.)

Note that when you are prompting models that have been fine-tuned, you might not need examples.

Cue

A cue is text at the end of the prompt that is likely to start the generated output on a desired path. (Remember, as much as it seems like the model is responding to your prompt, the model is really appending text to your prompt or continuing your prompt.)

 

Tip 3: Include descriptive details

The more guidance, the better. Experiment with including descriptive phrases related to aspects of your ideal result: content, style, and length. Including these details in your prompt can cause a more creative or more complete result to be generated.

For example, you could improve upon the sample instruction given previously:

  • Original: "List ideas for starting a dog-walking business"
  • Improved: "List ideas for starting a large, wildly successful dog-walking business"

 

Example

Before

In this image, you can see a prompt with the original, simple instruction. This prompt doesn't produce great results.

Example prompt text with just a simple instruction

After

In this image, you can see all the prompt components: instruction (complete with descriptive details), context, example, and cue. This prompt produces a much better result.

Example prompt text with an instruction, context, an example, and a cue

You can experiment with this prompt in the Prompt Lab yourself:

Model: gpt-neox-20b

Decoding: Sampling

  • Temperature: 0.7
  • Top P: 1
  • Top K: 50
  • Repetition penalty: 1.02

Stopping criteria:

  • Stop sequence: Two newline characters
  • Min tokens: 0
  • Max tokens: 80

Prompt text:

Copy this prompt text and paste it into the freeform prompt editor in Prompt Lab, then click Generate to see a result.

With no random seed specified, results will vary each time you submit the prompt.

Based on the following industry research, suggest ideas for starting a large, wildly
successful dog-walking business.

Industry research:
***
The most successful dog-walking businesses cater to owners' needs and desires while
also providing great care to the dogs. For example, owners want flexible hours, a
shuttle to pick up and drop off dogs at home, and personalized services, such as
custom meal and exercise plans. Consider too how social media has permeated our lives.
Web-enabled interaction provide images and video that owners will love to share online,
which is great advertising for the business.
***

Ideas for starting a lemonade business:
- Set up a lemonade stand
- Partner with a restaurant
- Get a celebrity to endorse the lemonade

Ideas for starting a large, wildly successful dog-walking business:

 

Learn more

 

Parent topic: Foundation models

Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more