ElemedexA pocket encyclopedia of AI architectures

Glossary (TM) › Use: prompts, sampling, systems

TM149

Few-shot

Also: few-shot prompting, one-shot

In Spanish: Few-shot (con pocos ejemplos)

Including a few solved examples of a task in the prompt so that the model infers the pattern and applies it to the new case, without retraining.

Instead of describing the task, one shows it. A few-shot prompt contains K input–output pairs and, at the end, an input without its output; the model fills the gap (Alammar & Grootendorst, 2024, pp. 180–181). With a single example one speaks of one-shot; with none, of zero-shot. For GPT-3, K was typically between 10 and 100, which fit in its 2,048-token context window, and no weight updates were allowed (Brown et al., 2020, sec. 2). It is the most visible form of in-context learning.

One of Brown et al. (2020)'s experiments should look familiar to any linguist. The model was given the definition of a made-up word and an example of its use:

A "whatpu" is a small, furry animal native to Tanzania. An example of a sentence that uses the word whatpu is: We were traveling in Africa and we saw these very cute whatpus.

and was then asked for a sentence with farduddle ("to jump up and down really fast"). GPT-3 produced plausible uses and even conjugated a made-up verb correctly (screeg → screeghed) (2020, sec. 3.9.5). The authors cite developmental research on learning a word from a single exposure (Carey & Bartlett, 1978); the most famous precedent is Jean Berko's (1958) wug test, which showed that children apply morphological rules to words they have never heard: "this is a wug; now there are two…".

Few-shot is also the format of the original chain of thought prompting, with eight written-out reasoning examples (Wei, Wang, et al., 2022). It has practical limits: examples take up context, and the choice and order of the examples affect the result. And it leaves the underlying question open: when the model "gets" the pattern from three examples, does it induce a rule, like the child in the wug test, or recognize a task it had seen a thousand times during training? Brown et al. (2020) explicitly leave that question open (2020, sec. 1).

Sources

  • Alammar, J., & Grootendorst, M. (2024). Hands-on large language models: Language understanding and generation. O’Reilly Media. §
  • Berko, J. (1958). The child's learning of English morphology. Word, 14(2–3), 150–177. https://doi.org/10.1080/00437956.1958.11659661 §
  • Brown, T. B., Mann, B., Ryder, N., Subbiah, M., Kaplan, J., Dhariwal, P., Neelakantan, A., Shyam, P., Sastry, G., Askell, A., Agarwal, S., Herbert-Voss, A., Krueger, G., Henighan, T., Child, R., Ramesh, A., Ziegler, D. M., Wu, J., Winter, C., . . . Amodei, D. (2020). Language models are few-shot learners. In Advances in Neural Information Processing Systems (Vol. 33, pp. 1877–1901). Curran Associates. https://proceedings.neurips.cc/paper_files/paper/2020/hash/1457c0d6bfcb4967418bfb8ac142f64a-Abstract.html §
  • Carey, S., & Bartlett, E. (1978). Acquiring a single new word. Papers and Reports on Child Language Development, 15, 17–29. https://eric.ed.gov/?id=ED198703 §
  • Wei, J., Wang, X., Schuurmans, D., Bosma, M., Ichter, B., Xia, F., Chi, E., Le, Q. V., & Zhou, D. (2022). Chain-of-thought prompting elicits reasoning in large language models. In Advances in Neural Information Processing Systems (Vol. 35, pp. 24824–24837). Curran Associates. https://doi.org/10.52202/068431-1800 §