What are Few-Shot Prompts? 

We’ve discussed how variability in a large language model (LLM) output is one of the biggest challenges to creating an effective AI-driven application. If you ask the same question to an LLM-based chatbot, you may get different answers depending on the bot’s configuration and the parameters used in the prompt.  

The user can force an LLM to interact with a query in a specific way by manipulating the variables inserted into the prompt. This is called prompt engineering; significant information and training are available on how to engineer prompts.


The question is, how do we achieve this same objective when constructing an AI application? 

The same prompt engineering techniques available to users in the context window are available via the API. The challenge is designing the API calls to maximize the output’s accuracy, relevance, and predictability while minimizing the potential degradation of the model’s performance.  

One approach is called few-shot prompts, which involves passing in sample queries and their answers along with the user’s query. These examples help the model learn the task or understand the context, enabling it to generalize and perform adequately on similar inputs. Transformer-based LLMs, like ChatGPT, are designed to allow these small examples to influence the nature and structure of their output materially. This approach enables the application to adapt a generalized model to perform specific tasks even when available training data is limited. 


What are the risks? 

While few-shot prompts can be an effective method to improve the accuracy and performance of an LLM-based application, there are some risks, including: 

  1. Coverage—It may not be suitable for tasks with a broader or more nuanced knowledge base. Variability in training data is critical to teaching a model the nuances associated with some topics, and the limited examples provided by a few-shot prompt may result in corrupt or garbage data when interacting with edge cases. 
  1. Similarity—The few-shot technique’s applicability is limited by the level of similarity between the base model’s training data and the target task. Getting a model to produce outputs materially different from its initial training set requires more additional data and context than few-shot prompts can provide. 
  1. Overhead—Constructing the few-shot examples requires precise knowledge of the target business process and will increase the project’s design and testing time. 
  1. Memorization—Since the supplemental training is based on a small amount of new data, the model may memorize the examples and incorrectly generalize new inputs to them. 

As with any of these design techniques for interacting with an LLM in your application, careful consideration of the trade-offs between functionality and risk is required. 

Insights & News

Find out GEG can do for you.