[DRAFT] LLM prompting guide
https://huggingface.co/docs/transformers/en/tasks/prompting
How to Prompt?
Prompt engineering
Prompt engineering is the process of designing and crafting effective prompts to guide Large Language Models (LLMs) to generate the responses you want.
Analogy: Think of prompt engineering like the following:
- Giving a chef a recipe: A detailed recipe (prompt) guides the chef (LLM) to create the desired dish (output).
- Programming with natural language: Instead of complex code, you use carefully crafted language to instruct the LLM.
- The art of asking the right questions: Prompt engineering is about finding the most effective way to communicate your needs to the LLM to get the outcome you desire.
Common Best Practice of LLM prompting
- Start with a simple and short prompt, and iterate from there.
- Put the instructions at the beginning of the prompt, or at the very end. When working with large context, models apply various optimizations to prevent Attention complexity from scaling quadratically. This may make a model more attentive to the beginning or end of a prompt than the middle.
- Clearly separate instructions from the text they apply to - more on this in the next section.
- Be specific and descriptive about the task and the desired outcome - its format, length, style, language, etc.
- Avoid ambiguous descriptions and instructions.
- Favor instructions that say “what to do” instead of those that say “what not to do”.
- “Lead” the output in the right direction by writing the first word (or even begin the first sentence for the model).
- Test your prompts with different models to assess their robustness.
- Version and track the performance of your prompts.
Main types of prompts used in prompt engineering
Here’s a breakdown of the main types of prompts used in prompt engineering, along with illustrative examples:
1. Direct Instruction Prompts
- Purpose: Clearly state the exact task you want the LLM to execute.
- Example: “Translate this paragraph from English to Spanish.”
2. Task Completion Prompts
- Purpose: Provide a scenario or problem and ask the LLM to complete a task related to it.
- Example: “You are a customer service representative. A customer is upset their package is late. Write a reply email that apologizes and offers a solution.”
3. Few-Shot Learning Prompts
- Purpose: Give a few examples of the desired input-output format to guide the LLM towards a new task.
- Example:
- “Input: Apple, Output: Fruit”
- “Input: Paris, Output: Country”
- “Input: Microwave. Output: Appliance”
- “Input: Bark, Output: ?” (The LLM should respond with “Dog”)
4. Story Continuation Prompts
- Purpose: Set the stage for a narrative and let the LLM continue the story.
- Example: “Once upon a time, in a land far away, a brave knight named Sir Thomas set out on a quest to find a hidden treasure…”
5. Question-Answering Prompts
- Purpose: Ask the LLM a question and have it provide an answer based on its knowledge.
- Example: “What is the capital of France?”
Important Notes:
- Complexity: Prompts can range from simple one-line instructions to elaborate, multi-part scenarios.
- Specificity: The level of detail in your prompt greatly influences the quality of the LLM’s output.
- Prompt Chains: Complex tasks can sometimes be broken down into a series of smaller, connected prompts.