Essentials of Prompt Engineering Flashcards
What is a Prompt?
A prompt is a natural language text that requests the generative AI to perform a specific task.
What is Prompt Engineering?
Prompt engineering is the process of designing and refining prompts to guide AI models to produce the desired output. It’s a complex process that involves choosing the right words, phrases, formats, and symbols to help the AI understand the intent and respond meaningfully.
Prompt engineering makes AI applications more efficient and effective.
What do Prompt Engineers do?
Prompt engineers bridge the gap between your end users and the large language model.
They identify scripts and templates that your users can customize and complete to get the best result from the language models.
They experiment with different types of inputs to build a prompt library that application developers can reuse in different scenarios.
For example, consider AI chatbots. A user may enter an incomplete problem statement like, “Where to purchase a shirt.” Internally, the application’s code uses an engineered prompt that says, “You are a sales assistant for a clothing company. A user, based in Alabama, United States, is asking you where to purchase a shirt. Respond with the three nearest store locations that currently stock a shirt.” The chatbot then generates more relevant and accurate information.
An example of prompt engineering for a medical AI application
For example, in the medical field, a physician could use a prompt-engineered language model to generate differential diagnoses for a complex case. The medical professional only needs to enter the symptoms and patient details. The application uses engineered prompts to guide the AI first to list possible diseases associated with the entered symptoms. Then it narrows down the list based on additional patient information.
What are the elements of a prompt?
Instructions - task for the large language model to do
Context - external information to guide the model
Input - the input for which you want a response
Output - This is the output type or format. e.g. Narrative, table, or other forms.
What is negative prompting?
Guide a model toward a desired output by including what you don’t want included in the output.
What are inference parameters?
Values that you can adjust to limit or influence the model response. You can control the randomness and diversity of the model output by turning:
1. Temperature
2. Top-p
3. Top-k
You can specify the length of the output and stop sequences as well.
What is temperature?
A parameter that affects the shape of the probability distribution for the predicted output and influences the likelihood of the model selecting lower-probability outputs.
Choose a lower value to influence the model to select higher-probability outputs. Leads to more deterministic responses that are conservative.
Choose a higher value to influence the model to select lower-probability outputs.
What is Top-P?
The percentage of most-likely candidates that the model considers for the next token:
Choose a lower value to decrease the size of the pool and limit the options to more likely outputs.
Choose a higher value to increase the size of the pool and allow the model to consider less likely outputs.
In technical terms, the model computes the cumulative probability distribution for the set of responses and considers only the top P% of the distribution.
For example, if you choose a value of 0.8 for Top P, the model selects from the top 80% of the probability distribution of tokens that could be next in the sequence.
What is Top-K?
The number of most-likely candidates that the model considers for the next token.
Choose a lower value to decrease the size of the pool and limit the options to more likely outputs.
Choose a higher value to increase the size of the pool and allow the model to consider less likely outputs.
For example, if you choose a value of 50 for Top K, the model selects from 50 of the most probable tokens that could be next in the sequence.
An example of how temp, top-p, and top-k work.
As an example to understand these parameters, consider the example prompt I hear the hoof beats of “. Let’s say that the model determines the following three words to be candidates for the next token. The model also assigns a probability for each word.
{
“horses”: 0.7,
“zebras”: 0.2,
“unicorns”: 0.1
}
If you set a high temperature, the probability distribution is flattened and the probabilities become less different, which would increase the probability of choosing “unicorns” and decrease the probability of choosing “horses”.
If you set Top K as 2, the model only considers the top 2 most likely candidates: “horses” and “zebras.”
If you set Top P as 0.7, the model only considers “horses” because it is the only candidate that lies in the top 70% of the probability distribution. If you set Top P as 0.9, the model considers “horses” and “zebras” as they are in the top 90% of probability distribution.
https://docs.aws.amazon.com/bedrock/latest/userguide/inference-parameters.html
What does “Length” the inference parameter do?
Limits output length.
Helps to prevent the model from generating excessive or infinite output, which could lead to resource exhaustion or undesirable behavior.
What are best practices for prompting?
- Be clear and concise
- Include context if necessary
- Use directives for the appropriate response type
- Consider the output in the prompt - mention it at the end to keep the model focused
- Start prompt with an interrogation
- Provide an example response
- Break up complex tasks
- Experiment and be creative
- Use prompt templates
What are some prompt engineering techniques?
- Zero Shot Prompting
- Few Shot Prompting
- Chain of Thought Prompting
What is Few-shot prompting?
Involves providing a language model with contextual examples to guide its understanding and expected output for a specific task.
In this approach, you supplement the prompt with sample inputs and their corresponding desired outputs, effectively giving the model a few shots or demonstrations to condition it for the requested task.