Learning Paradigms
Few-shot Prompting
In shortShowing a language model a handful of worked examples inside the prompt so it copies the pattern, format or labels you want, without retraining.
Few-shot prompting means including a small number of examples of the task, each with its input and the correct output, in your prompt to a large language model. The model infers the pattern from those examples and applies it to new input. With no examples it is called zero-shot; with one, one-shot.
How it works
The 2020 GPT-3 paper, “Language Models are Few-Shot Learners”, showed that large models can pick up a task from a few demonstrations in the prompt, with no change to their weights. This is sometimes called in-context learning. The examples teach format, label set, tone and edge cases far more precisely than a description alone. Good examples are varied, cover the tricky cases, and are clearly separated from the instructions, for instance with tags or headings.
Few-shot prompting sits between zero-shot approaches and fine-tuning, which changes the model itself using many labelled examples.
How it’s used in SEO and marketing
- Classifying keywords by intent or category: show five labelled keywords, then ask for labels on the rest.
- Extracting entities or attributes in a fixed JSON format.
- Writing titles or meta descriptions in a house style, using strong existing examples.
- Sentiment or topic labelling of reviews, where examples clarify what “mixed” or “neutral” means for your brand.
- Understanding AI search: a Google patent describes using few-shot prompting to generate synthetic query-document pairs for training retrieval models.
Example
MLforSEO’s Semantic ML-enabled Keyword Research course covers patent WO2024064249A1, Systems and Methods for Prompt-Based Query Generation. It describes giving an LLM a few example query-document pairs and asking it to generate diverse queries for new documents. Those synthetic queries then train a retrieval model, one reason your pages may be matched to queries no user has typed yet.
Limitations and things to watch
- Models can over-copy examples, repeating their wording or favouring the label that appears most. Balance and vary your examples.
- Examples use up tokens, adding cost on every call.
- MLforSEO’s comparison of NLP APIs found that zero-, one- or few-shot prompting improves generative AI on sentiment, but results stayed questionable compared with a purpose-built API.
- Test on a labelled sample before running at scale; few-shot is not a substitute for evaluation.
Learn it on MLforSEO
- Comparing NLP APIs for Entity and Sentiment Analysis (vs Generative AI)
- How to Structure and Categorise Keyword Data for Semantic Analysis
- What Are Synthetic Queries?
- Semantic ML-enabled Keyword Research course, lessons on synthetic queries and query fan-out.
Where Few-shot Prompting shows up on MLforSEO
Learn it in a course
Sources and further reading
Other terms from Learning Paradigms
- Active LearningA training approach where the model picks the unlabelled examples it is least sure about for a human to label,…
- Fine-tuningTraining an existing pre-trained model a little further on your own labelled examples so it performs better on…
- Human-in-the-loopAn approach where people stay involved in an AI or ML system, labelling data, reviewing outputs or approving a…
- Pre-trainingThe first, large-scale training stage in which a model learns general patterns from huge datasets before it is…
- Reinforcement LearningA machine learning approach where an agent learns by trial and error, taking actions and adjusting its behavio…
- Supervised LearningMachine learning trained on labelled examples, where the right answer is known, so the model can predict label…
- Unsupervised LearningMachine learning on data without labels, where the model finds groups, patterns or structure on its own, as in…
- Zero-shot LearningGetting a model to perform a task or apply labels it was never trained on, with no examples, using only knowle…
