Few-Shot Learning Technique
Teach the AI new patterns by providing examples. Mastering the technique makes prompts significantly more reliable.
The most powerful technique
In the previous lesson, we explored roles and personalities. Now, let's build on that foundation. If I could only teach you one advanced technique, it would be this one.
Few-shot learning—providing examples of what you want—is incredibly effective. It often solves problems that no tutorial could fix. It transforms inconsistent outputs into reliable ones. It allows you to teach AI custom formats, styles, and logic that it wasn't explicitly trained for.
And most people don't use it. Instead, they write longer instructions.
This lesson will show you how to use examples correctly.
What is few-shot learning?
This term originates from Machine Learning :
- Zero-shot : Provides instructions only, without examples.
- One-shot : Give one example
- Few-shot : Provide 2-5 examples
In fact, 'few-shot prompting' means including input examples – the output representing the pattern you want.
Zero-shot:
Phân loại tin nhắn khách hàng sau đây là Tích cực, Tiêu cực hoặc Trung lập. Tin nhắn: 'Sản phẩm bị hư hỏng khi nhận được và không ai giúp tôi'. Few-shot:
Phân loại tin nhắn khách hàng là Tích cực, Tiêu cực hoặc Trung lập. Ví dụ: Tin nhắn: 'Tôi thích sản phẩm này! Đây là món đồ mua tốt nhất tôi từng mua trong năm nay.' Phân loại: Tích cực Tin nhắn: 'Tạm được, không có gì đặc biệt nhưng hoạt động tốt.' Phân loại: Trung lập Tin nhắn: 'Đã đợi 3 tuần mà vẫn chưa nhận được hàng. Thật kinh khủng.' Phân loại: Tiêu cực Bây giờ, hãy phân loại tin nhắn này: Tin nhắn: 'Sản phẩm bị hư hỏng khi nhận được và không ai giúp tôi.'
The shorter, less-than-perfect version is much more reliable. The AI recognizes the pattern, matches the format, and produces consistent results.
Why are examples better than instructions?
Instructions for the AI on what to do. An example to illustrate this.
And illustrations are better than words for the same reason as with people. When you say 'write in an informal tone,' that's subjective. Your informal tone and someone else's can be different.
But what if you give three examples of your usual tone of voice? Artificial intelligence (AI) will automatically adjust to exactly what you really mean.
These are effective examples because they:
- Reduce ambiguity - No need for explanation
- Formatting settings - AI accurately mimics the structure.
- Set the tone - Your voice is illustrated
- Exception handling - Shows how to handle complex inputs
Structure of good examples
Not all examples are created equal. Here are the elements that make examples effective:
1. Actual input
Use examples that look like the real data you will be processing.
Bad : The test data looks fake.
Đầu vào: "Tin nhắn thử nghiệm ở đây" Đầu ra: "Phản hồi thử nghiệm" Good : Real-life representative cases
Đầu vào: "Chào, tôi đã đặt đơn hàng #4521 tuần trước nhưng trạng thái hiển thị là đang chờ xử lý?" Đầu ra: "Truy vấn trạng thái đơn hàng - Đơn hàng #4521 - Mức độ ưu tiên: Bình thường"
2. Diverse cases
Show the diversity to teach the entire pattern, not just one case.
If you're categorizing emotions, include:
- Clearly positive
- Clearly negative
- Ambiguous/Neutral
- A mixture (both positive and negative elements)
If extracting data, include:
- Full information
- Incomplete information
- Missing required fields
3. Consistent formatting
Each example should follow the same format. AI learns patterns from consistency.
Bad : Inconsistent formatting
Đầu vào: "Sản phẩm tuyệt vời!" → Cảm xúc tích cực Thông điệp: Tôi ghét phải chờ đợi Phân loại = Tiêu cực Good : Consistent structure
Đầu vào: "Sản phẩm tuyệt vời!" Phân loại: Tích cực Đầu vào: "Tôi ghét phải chờ đợi" Phân loại: Tiêu cực 4. Exceptions
Include at least one example of handling a complex case.
For sentiment analysis, you can display it as follows:
Đầu vào: "Sản phẩm tốt nhưng vận chuyển tệ" Phân loại: Hỗn hợp Lý luận: Tích cực về sản phẩm, tiêu cực về vận chuyển This teaches the AI what to do when the input doesn't clearly match.
How many examples should be included?
Quick check : Before we continue, do you remember the main concept we just learned? Try to explain it in your own words before we move on.
Research and practical experience converge on the following points:
| For example | When should it be used? |
|---|---|
| 1-2 | Simple tasks, formatted presentation. |
| 3-5 | For most tasks, the optimal point for reliability. |
| 6-10 | Complex patterns, many exceptions |
| 10+ | Rarely needed, benefits diminish. |
The more examples you have, the more space they occupy in the context window. After 5-6 examples, you'll generally get better results by improving the quality of the examples rather than increasing the number.
Few-Shot Template
This is a reliable structure:
[MÔ TẢ NHIỆM VỤ] Giải thích ngắn gọn những gì bạn muốn. [VÍ DỤ] --- Đầu vào: [ví dụ đầu vào 1] Đầu ra: [ví dụ đầu ra 1] --- Đầu vào: [ví dụ đầu vào 2] Đầu ra: [ví dụ đầu ra 2] --- Đầu vào: [ví dụ đầu vào 3] Đầu ra: [ví dụ đầu ra 3] --- [YÊU CẦU THỰC TẾ] Bây giờ, hãy xử lý những điều sau: Đầu vào: [đầu vào thực tế của bạn] Đầu ra: The 'Output:' section at the end signals to the AI to respond in the same format.
Example: Product classification
Construct a short question (no training required) to classify e-commerce products.
Task : Classify products into departments based on their titles.
Start simple (zero-shot) :
Hãy phân loại sản phẩm này vào danh mục: "Tai nghe chống ồn không dây Sony WH-1000XM5" This approach might work, but the results will vary. "Electronics"? "Audio"? "Headphones"? "Technology"?
More examples (few-shots) :
Phân loại sản phẩm vào đúng danh mục. Các danh mục hiện có: Điện tử, Đồ gia dụng & Nhà bếp, Quần áo, Thể thao & Ngoài trời, Sách, Đồ chơi & Trò chơi --- Sản phẩm: "Nồi áp suất điện Instant Pot Duo 7 trong 1" Danh mục: Đồ gia dụng & Nhà bếp Sản phẩm: "Giày chạy bộ Nike Revolution 6 dành cho nam" Danh mục: Quần áo Sản phẩm: "Máy đọc sách điện tử Kindle Paperwhite 16GB" Danh mục: Điện tử Sản phẩm: "Bộ lắp ráp LEGO Star Wars Millennium Falcon" Danh mục: Đồ chơi & Trò chơi --- Bây giờ hãy phân loại: Sản phẩm: "Tai nghe không dây chống ồn Sony WH-1000XM5" Danh mục: Now, AI knows exactly which categories to use and how to format the answers. Consistent, every time.
The Few-Shot Method for Capturing Style and Tone
Examples are particularly effective in demonstrating tone of voice. Instructions like "speak professionally but in a friendly manner" are rather vague. Examples make it more specific.
Bạn đang viết thư trả lời khách hàng. Hãy viết theo phong cách này: --- Khách hàng: "Đơn hàng của tôi đâu?" Phản hồi: "Tôi hoàn toàn hiểu việc chờ đợi thật khó chịu! Để tôi kiểm tra ngay cho bạn. Số đơn hàng của bạn là gì?" Khách hàng: "Sản phẩm này bị hỏng sau một ngày." Phản hồi: "Ồ không, điều đó chắc chắn không ổn. Chúng tôi sẽ khắc phục vấn đề này. Bạn có thể gửi cho tôi một bức ảnh nhanh về vấn đề đó không? Tôi sẽ gửi sản phẩm thay thế cho bạn sớm nhất có thể." Khách hàng: "Các bạn có giao hàng quốc tế không?" Phản hồi: "Có! Thời gian giao hàng khác nhau tùy thuộc vào địa điểm — thường là 7-14 ngày đối với đơn hàng quốc tế. Các bạn đang giao hàng đến quốc gia cụ thể nào?" --- Bây giờ hãy trả lời: Khách hàng: "Tôi có thể thay đổi địa chỉ giao hàng không?" Phản hồi:
Artificial intelligence (AI) now has a specific model of your voice—comfortable, helpful, action-oriented. It will precisely match that style.
Common mistakes
- Error 1 : The examples don't match the real data . Your examples only show simple cases, but the real data is more complex. The AI won't know how to handle that complexity.
- Error 2 : Inconsistent formatting between examples. AI learns from patterns. Inconsistencies will cause confusion.
- Error 3 : All examples are of the same type . If all examples are positive cases, the AI may struggle with negative cases.
- Error 4 : Examples are too long. Overly long examples lose context. Keep them concise—just enough to illustrate the pattern, no more.
Key points to remember
- Few-shot learning means teaching by showing examples – often more effective than lengthy instructions.
- 3-5 examples typically achieve the optimal balance between scope and effectiveness.
- Good examples should be practical, diverse, consistent, and include exceptions.
- Format the examples identically – that pattern is what the AI learns.
- End with 'Output:' to prepare the AI to match your format.
You should read it
- ★ Google researchers for gaming AI to improve enhanced learning ability
- ★ The world's fastest badminton shot is 565 km/h, faster than a Formula 1 car
- ★ Study online on e-Learning lectures
- ★ Rounded his eyes to see the bullet shatter when shot at the glass of 'Dutch tears'
- ★ What is machine learning? What is deep learning? Difference between AI, machine learning and deep learning