Prompting Flashcards
Fine Tuning
Prompt Engineering
Crafting an input prompt. Trial-and-error process. Helps define which training data should be used to formulate the response.
Key Elements of Context
- Persona/Role
- Purpose
- Clear/Precise
- Concise
- Specific
- Details
- Examples
Persona / Role
Works best when:
* Quality of answer is subjective.
* You’re trying to emulate a specific style.
Purpose
Define the purpose of the prompt:
* Tone, e.g., funny, professional, casual?
* Format: paragraph, bulleted list, essay, code, etc.
* Audience: who is this for?
Clarity / Precision
Get rid of unnecessary information, jargon, confusing phrases, or mistakes.
They can lead AI down the wrong path.
Conciseness
Less words –> less tokens –> less cost.
Chain of Thought Prompting
Request AI show its thought process (or provide the thought process in the prompt) as it solves a given problem. This technique forces an AI to reason about a problem and solve it in a way a person would, by breaking it down and solving it step-by-step. Also, by asking the AI to show us its thought process, we can identify where something went wrong if the AI were to give an incorrect answer. Use “show me your thought process” or something similar in the prompt.
Use Cases for Chain of Thought Prompting
- solving multi-step/complex problems requiring logical reasoning
- addressing tasks that require logical deduction
- solving mathematical or analytical challenges
- explaining complex concepts or processes
Complex Tasks
Avoid making assumptions. Instead, break down complex tasks into simple sub-problems with a logical order and relationships.
- Improves understanding: allows AI to focus on one task at a time, reducing the thought processing required and increasing accuracy.
- Reduces errors: the step-by-step nature of this technique facilitates error detection and correction during task execution.
- Better accuracy: clear instructions for each subtask ensure the AI applies appropriate logic and principles, improving overall accuracy.
- Better logical flow: A structured, step-by-step approach maintains a coherent and understandable flow in problem-solving.
Iteration
Trying multiple prompts until you get an adequate response.
Specificity
Include specific limitations or requirements. However, avoid too much information as it may confuse the AI or cause it to focus on less important aspects of your request.
Details & Context
Include any details essential to understanding the request, such as historical context or related concepts.
Example: lines of code and error message.
Examples
Adding examples clarifies what you mean and gives the AI a baseline to work from.
Types of Prompting
- Zero Shot
- One Shot
- Few-Shot
Zero-Shot Prompting
No examples provided. Use for simple tasks where answer is straightforward.
One-Shot Prompting
One example provided. Use when trying to specify specific format, context, or style.
Few-Shot Prompting
Allows a model to learn from a very small number of examples or “shots” (typically 2-5) for a new task. Examples are provided directly in the prompt or input to the model, rather than through additional training.
Does not modify the underlying model weights or architecture. Fast to implement and flexible to adapt to new tasks or classes on the fly. Can be integrated with fine-tuning for better results. Valuable in scenarios where obtaining large labeled datasets is expensive, time-consuming, or impractical. Example: facial recognition, diagnosing rare diseases, or translation for low resource languages.
Retrieval Augmented Generation (RAG)
Combines old and new data, blending different bits of information to generate better answers. Can use fresh data in real-time to supplement training data. This means AI can give us more accurate responses to our questions, even if they’re about recent events or custom data.
Either complex, API-based or uploading docs to chatbot.
RAG Components
- Retriever Model - processes the query by converting it into computer-understandable format (numerical) and searches the knowledge base to find the most relevant documents.
- Knowledge Base - repository of documents, articles, research papers, etc. to supplement training data.
RAG Steps
- Query
- Retriever Model searches for relevant text in Knowledge Base
- Retriever Model adds relevant text to Query
- LLM generates a response.
Benefits of RAG
- Precise, reliable answers from up-to-date data.
- Tailors AI responses for personalized information.
- Information can be instantly updated without retraining.
- Saves time for users and business.
- Improves user satisfaction due to accurate, relevant responses.
- Can ask AI to point out where it found answers/details.
Fine Tuning
Process of taking a pre-trained model and further training it on a smaller, targeted dataset to adapt it for specific tasks, domains/industries, or company needs, e.g., medical research, legal analysis, customer support. Leverages the general knowledge and skills of a large, powerful model and applies them to a specific field or objective. Reduces training time and computational resources compared to training a model from scratch. There are different types of fine tuning.
Benefits of Few-Shot Prompting
- Fast to implement
- Slight latency
- Flexible to adapt to new tasks; rapid prototyping
- Personalization
- Doesn’t require a lot of data
- Can be integrated with fine-tuning for better results.
- Minimal maintenance
Downsides of Few-Shot Prompting
- Slightly higher ongoing cost (longer prompts)
- Lower accuracy (less examples, may not be up-to-date)
- Worse for complex tasks
- Slight latency
When Few-Shot Prompting is Valuable
Scenarios where obtaining large labeled datasets is expensive, time-consuming, or impractical. Quick adaptation to new tasks; rapid prototyping; personalization; rare scenarios.
Ex: facial recognition, diagnosing rare diseases, or translating low res
When RAG is Valuable
Question-answering systems/chatbots w/ access to specific Knowledge Basis; content-generation w/ factual accuracy; summarization requiring external information; tech support w/ product docs.
When Fine Tuning is Valuable
Specialized chatbot or virtual assistant; domain-specific text generation; domain-specific sentiment analysis; customized summarization; translation.
Downsides of RAG
- Increased latency due to retrieval
- Medium training cost
- Medium implementation speed
- Must maintain Knowledge Base
- Medium accuracy
Downsides of Fine Tuning
- Requires lots of data (100K+)
- Must adjust model weights
- Slower speed to implement
- Higher training cost
- Periodic retraining