Entendiendo el prompting por “shots”
El término "shot" en ingeniería de prompts se refiere al número de ejemplos proporcionados en tu prompt. Este concepto proviene del aprendizaje automático, donde los modelos aprenden de ejemplos de entrenamiento.
🎯 Tipos de prompting por “shots”
- Zero-Shot: No se proporcionan ejemplos; el modelo se apoya en su conocimiento de entrenamiento
- One-Shot: Un solo ejemplo para demostrar el patrón
- Few-Shot: Múltiples ejemplos (normalmente 2-5) para establecer el patrón
Prompting Zero-Shot
El prompting zero-shot le pide al modelo realizar una tarea sin ejemplos. El modelo usa solo su conocimiento preentrenado y tus instrucciones.
// Zero-Shot Example 1: Classification
"Classify the following text as positive, negative, or neutral:
Text: 'The new update completely broke my workflow. Very frustrated.'
Sentiment:"
// Output: negative
// Zero-Shot Example 2: Translation
"Translate the following English text to Spanish:
'The quick brown fox jumps over the lazy dog.'
Translation:"
// Output: El rápido zorro marrón salta sobre el perro perezoso.
// Zero-Shot Example 3: Code Generation
"Write a JavaScript function that checks if a string is a palindrome."
// Output: Working function (model knows the task from training)
// When Zero-Shot Works Well:
// - Common, well-defined tasks
// - Tasks the model was trained on
// - When format is flexible
// - Simple transformations
Prompting One-Shot
El prompting one-shot proporciona un solo ejemplo para demostrar el patrón o formato deseado.
// One-Shot Example: Custom Format
"Convert product descriptions to marketing copy.
Example:
Input: Wireless headphones with 40-hour battery life
Output: 🎧 Experience freedom! Our wireless headphones deliver
an incredible 40 hours of non-stop music. No more charging anxiety!
Now convert:
Input: Laptop stand with adjustable height and cooling fans
Output:"
// One-Shot Example: Code Style
"Refactor functions to use early returns.
Example:
Before:
function isValid(user) {
if (user) {
if (user.active) {
if (user.verified) {
return true;
}
}
}
return false;
}
After:
function isValid(user) {
if (!user) return false;
if (!user.active) return false;
if (!user.verified) return false;
return true;
}
Now refactor:
function processOrder(order) {
if (order) {
if (order.items.length > 0) {
if (order.paymentComplete) {
return { success: true };
}
}
}
return { success: false };
}"
Prompting Few-Shot
El prompting few-shot proporciona múltiples ejemplos para establecer claramente el patrón deseado. Esto es especialmente útil para tareas complejas o personalizadas.
// Few-Shot Example: Consistent JSON Extraction
"Extract structured data from text descriptions.
Example 1:
Text: John Smith is a 32-year-old software engineer from Boston.
JSON: { "name": "John Smith", "age": 32, "job": "software engineer", "city": "Boston" }
Example 2:
Text: Maria Garcia, 28, works as a data scientist in San Francisco.
JSON: { "name": "Maria Garcia", "age": 28, "job": "data scientist", "city": "San Francisco" }
Example 3:
Text: The 45-year-old CEO, Robert Chen, is based out of Seattle.
JSON: { "name": "Robert Chen", "age": 45, "job": "CEO", "city": "Seattle" }
Now extract:
Text: Lisa Wong is a 36-year-old product manager working in Austin.
JSON:"
// Few-Shot Example: Custom Code Transformation
"Convert Express routes to OpenAPI YAML specs.
Example 1:
Express: app.get('/users', getAllUsers)
OpenAPI:
/users:
get:
summary: Get all users
responses:
200:
description: Success
Example 2:
Express: app.post('/users', createUser)
OpenAPI:
/users:
post:
summary: Create a user
requestBody:
required: true
responses:
201:
description: Created
Now convert:
Express: app.delete('/users/:id', deleteUser)
OpenAPI:"
Elegir el enfoque correcto
| Enfoque | Mejor para | Consideraciones |
|---|---|---|
| Zero-Shot | Tareas estándar, formato flexible, solicitudes simples | Más rápido, usa menos tokens, puede ser inconsistente |
| One-Shot | Formatos personalizados, guía de estilo, patrones simples | Buen equilibrio, puede no cubrir todos los casos límite |
| Few-Shot | Patrones complejos, salida consistente, casos límite | Más consistente, usa más tokens, requiere buenos ejemplos |
Buenas prácticas de few-shot
// 1. Diverse Examples - Cover different cases
"Classify customer feedback:
Example 1 (product issue):
Text: The app crashes when I try to upload photos
Category: Bug Report
Example 2 (feature request):
Text: It would be great if you could add dark mode
Category: Feature Request
Example 3 (praise):
Text: Love the new update! Everything runs so smoothly
Category: Positive Feedback
Example 4 (confusion):
Text: How do I change my password? Can't find the option
Category: Support Question
Now classify:
Text: The checkout button doesn't work on mobile
Category:"
// 2. Consistent Format - All examples follow same structure
// ✅ Good: All examples have same keys
{ "name": "...", "role": "...", "level": "..." }
{ "name": "...", "role": "...", "level": "..." }
// ❌ Bad: Inconsistent structure
{ "name": "...", "job": "..." }
{ "fullName": "...", "role": "...", "experience": "..." }
// 3. Representative Examples - Include edge cases
"Parse dates from various formats:
Input: 2024-01-15 → Output: { year: 2024, month: 1, day: 15 }
Input: January 15, 2024 → Output: { year: 2024, month: 1, day: 15 }
Input: 15/01/2024 → Output: { year: 2024, month: 1, day: 15 }
Input: Jan 15 '24 → Output: { year: 2024, month: 1, day: 15 }
Now parse:
Input: 03-22-2024"
Few-shot para tareas de código
// Generate TypeScript interfaces from examples
"Generate TypeScript interfaces from sample JSON data.
Example 1:
JSON: { "id": 1, "name": "Item", "price": 29.99 }
Interface:
interface Product {
id: number;
name: string;
price: number;
}
Example 2:
JSON: { "userId": "abc", "email": "user@test.com", "active": true }
Interface:
interface User {
userId: string;
email: string;
active: boolean;
}
Example 3:
JSON: { "posts": [{ "id": 1, "title": "Hello" }], "total": 100 }
Interface:
interface Post {
id: number;
title: string;
}
interface PostsResponse {
posts: Post[];
total: number;
}
Now generate:
JSON: { "orderId": "ord_123", "items": [{ "sku": "A1", "qty": 2 }], "shipped": false }
Interface:"
⚠️ Errores comunes
- • Usar demasiados ejemplos (3-5 suele ser lo óptimo)
- • Proporcionar ejemplos incorrectos o inconsistentes
- • Ejemplos demasiado similares (falta de diversidad)
- • Ejemplos demasiado complejos que confunden al modelo
- • No alinear el formato del ejemplo con el caso real