NLP

[Prompt Engineering] 1. Few-shot Prompting

dongsunseng 2025. 1. 2. 16:51
반응형

What is Few-shot Prompting?

  • In artifical intelligence, a "shot" refers to an example
  • Therefore, Few-shot means a few examples.
  • Few-shot prompting is a method that helps AI models better understand and perform new tasks by providing a small number of examples when the model needs to perform a new task.
  • Few-shot prompting is broadly divided into:
    • Instructions: Description of the task the model needs to perform
    • Examples: Examples for the model to reference when generating responses
    • Input data: Optional use depending on whether there is data to analyze
  • It is common to use 2-5 examples for few-shot prompting

Examples of few-shot prompting

1. Sentiment Analysis

Input: "The food was amazing!" 
Output: Positive

Input: "Terrible service, would not recommend." 
Output: Negative

Input: "It was an okay experience."
Output: Neutral

Input: "The concert exceeded all my expectations!"
Output: [The model should predict: Positive]

 

2. Text Classification

Input: "How do I reset my password?"
Category: Technical Support

Input: "I'd like to return my recent purchase"
Category: Customer Service

Input: "What are your business hours?"
Category: General Inquiry

Input: "My account is locked, please help"
Category: [The model should predict: Technical Support]

 

3. Language Translation (Informal -> Formal)

Informal: "Hey, what's up?"
Formal: "Hello, how are you?"

Informal: "Gimme a sec"
Formal: "Please give me a moment"

Informal: "That's awesome!"
Formal: "That is excellent"

Informal: "Can't wait to see ya"
Formal: [The model should predict: "I look forward to seeing you"]

 

4. Entity Extraction

Text: "John Smith lives in New York"
Person: John Smith
Location: New York

Text: "Apple Inc. is headquartered in Cupertino"
Company: Apple Inc.
Location: Cupertino

Text: "Microsoft CEO Satya Nadella announced"
Person: Satya Nadella
Company: Microsoft

Text: "Tesla opened a new factory in Berlin"
Company: [The model should predict: Tesla]
Location: [The model should predict: Berlin]

Advantages

  • Few-shot prompting enables AI models to better understand and perform tasks with just a small amount of data.
  • While it takes longer to write prompts compared to zero-shot prompting, it allows for more precise control of responses.

Limitations

  • Since few-shot prompting only provides a small number of examples to the AI, if the quality of the given examples is low, there's a higher probability that the AI will produce incorrect results.
  • Therefore, when using few-shot prompting, it's crucial to carefully check the consistency and quality of the examples.

 

 


It is a mistake to underestimate the power of a single individual to change the world.
- Elon Musk -
반응형