Zero-shot learning lets a model perform a task without seeing task-specific examples during training. It relies on broader learned associations, such as semantic similarity, word embeddings, or shared representations, to generalize to a new task. section 2.5 section 4.4
Use zero-shot learning when the task can be expressed clearly without supplying examples:
- Translate text into another language even when the model has not seen examples of that specific translation task. section 2.5 section 6.4.2
- Classify images using natural-language class names, even when the model was not fine-tuned for those classes. section 4.4
- Prefer few-shot learning when examples are available and task criteria or intent are difficult to convey through instructions alone. section 6.4.2
- Avoid confusing inference-time conditioning with weight updates: few-shot and many-shot examples affect the current call transiently and may be cached to reduce repeated cost. section 6.4.2
Prompt-based translation
A zero-shot completion prompt can request translation directly: “Translate the following to Spanish: I have a small dog called Champ.” An Azure OpenAI completion call sends this instruction without supplying translation examples. section 6.4.2
Listing 6.3 Prompt engineering zero-shot example
import os
import openai
openai.api_type = "azure"
openai.api_base = os.getenv("AOAI_ENDPOINT")
openai.api_version = "2022-12-01"
openai.api_key = os.getenv("AOAI_KEY")
prompt_startphrase = "Translate the following to Spanish:
I have a small dog called Champ."
response = openai.Completion.create(
engine="gpt-35-turbo",
prompt=prompt_startphrase,
temperature=0.8,
max_tokens=100,
stop=None)
responsetext = response["choices"][0]["text"]
print("Prompt:" + prompt_startphrase + "\nResponse:" + responsetext)
Inspect the Python completion example for the prompt, Azure OpenAI configuration, model engine, temperature, and token limit. section 6.4.2
Table 2.1 Types of LLMs
|
LLM Type
|
Description
|
|---|---|
|
Base LLM
|
These are the original models, pretrained on a massive corpus of text data, and they can generate text based on the patterns they learned during this training. Some also call these raw language models or even refer to them as foundational models; they can be used out of the box to generate text. They learn powerful and general representations but lack specific expertise in a particular task. GPT-3’s DaVinci model is an example of a base LLM.
|
|
Instruction-based LLM
|
This involves using a base LLM and providing explicit instructions in prompt input. In many examples we saw in the previous chapter, we instructed the model to follow instructions, such as “Translate the following text to French:” or “Summarize this article:” Sometimes, these models are also called instruction-tuned LLMs.
|
|
Fine-tuned LLM
|
Fine-tuning involves taking the base LLM and training it further on a task it might perform poorly at, often in a specific domain. An example would be training the model on medical literature if we want it to understand medical topics or training it on customer service interactions if we want it to respond to customer inquiries for a specific industry. Fine- tuning can help make the model more accurate or helpful to particular tasks or domains, but it requires additional data and training time.
|
Compare zero-shot learning with base, instruction-based, and fine-tuned language-model approaches. section 2.5









