liveBook · Manning

Few-shot learning

As explained in Build AI-Enhanced Web Apps

Few-shot learning is a technique in which a model performs or adapts to a task by inferring the desired behavior from a small number of examples.

Few-shot learning guides a model with a small set of examples included in its prompt. It helps a web application adapt responses to a new task without fine-tuning or configuring the model. Unlike a zero-shot request, the model sees examples of the desired behavior; unlike fine-tuning, the examples do not require further training on a dataset. section 5.2

Build the prompt around the behavior users should receive:

  • State the model’s role and task, then identify the kinds of requests it must handle. section 5.2.2
  • Provide varied example requests paired with suitable responses. Choose examples that demonstrate the tone, content, or format you want. section 5.2.2
  • End with an instruction to respond to new requests using those examples. Generate a response, review it, and adjust the prompt if needed. section 5.2.2 section 5.2

Customer support tone

A JavaScript system prompt can assign a customer-support role and show example exchanges for technical support, billing, and general inquiries. For a slow-connection request, the example response acknowledges the problem and asks for speed-test results. For a duplicate-charge request, it acknowledges the concern and offers to investigate. A final directive asks the chatbot to use the appropriate tone and sentiment for the next inquiry. The examples give the model a pattern to follow, not a fixed answer to reuse. section 5.2.1 section 5.2.2

Be precise about the output as well as its style. A programming-language prompt that asks for “some” examples may produce an unexpectedly long list; asking for five makes the requested length clearer. section 5.2.1

Figure 5.5 The step-by-step procedure for few-shot learning, where users provide a few examples to guide the AI model. The process involves compiling these examples into a prompt, generating output using the AI model, and then reviewing and adjusting the output as needed to achieve the desired results.

The workflow diagram shows how examples become a prompt, followed by generation, review, and adjustment. section 5.2

How Build AI-Enhanced Web Apps covers it

How deep it goes
Provides a prompt-building procedure and examples, but does not descend into model training internals.
Examples
Uses a programming-language list and customer-support exchanges for technical, billing, and general inquiries.
What it assumes
Assumes familiarity with prompts and AI models while defining few-shot learning and distinguishing it from zero-shot learning and fine-tuning.
What you can do after
Apply it via JavaScript prompts to shape chatbot responses, then review outputs and adjust the examples or instructions.
How it connects
Connects prompt engineering and system prompts with zero-shot learning and fine-tuning.

Also explained in

Compare how 18 books explain few-shot learning →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.