🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Zero-Shot Learning in NLP: Generalization Without Examples

Natural Language ProcessingZero-Shot Learning in NLP: Generalization Without ExamplesđŸŸĸ Free Lesson

Zero-Shot Learning in NLP: Generalization Without Examples

Module: Natural Language Processing | Difficulty: Advanced

What You'll Learn

  • 1Distinguish zero shot, one shot, and few shot conditioning for a task
  • 2Derive chain of thought as marginalization over reasoning traces
  • 3Aggregate sampled traces with self consistency voting
  • 4Predict when instruction tuning will beat hand written prompts

Zero shot learning means the model receives a task description but no worked examples. The promise is that a single system handles classification, extraction, and generation without per task training data, and the reality is that performance depends as much on how the task is stated as on the model. This lesson covers the three prompting regimes, the reasoning traces that unlock multi step tasks, and the instruction tuning that makes a described task behave like a trained one.

Three Conditioning Regimes

A language model conditions on a prefix. The regimes differ only in what that prefix contains:

where is a set of demonstrations. With the prompt is an instruction, with it includes a single worked pair, and with the model can infer the output format, the label vocabulary, and the task boundary from the examples themselves.

The value of demonstrations is empirical rather than uniform. On LAMBADA, a passage completion benchmark, GPT-3 at 175 billion parameters moves from 76.2 percent zero shot to 86.4 percent few shot, a gain concentrated in tasks where the output format is ambiguous. On tasks with a well stated instruction the gap shrinks, which is why prompt selection should be driven by format ambiguity rather than by habit.

Chain-of-Thought Reasoning

For multi step problems, generating the answer directly skips the intermediate computation. Chain of thought prompting asks for the reasoning trace first and the answer last, which is equivalent to marginalizing over latent reasoning steps:

The sum is approximated by sampling or beam search over traces . On GSM8K, a grade school math word problem set, PaLM at 540 billion parameters scores 17.9 percent with standard prompting and 56.9 percent with chain of thought prompting, an absolute gain of 39.0 points that comes entirely from showing the intermediate arithmetic rather than from any parameter change.

Self consistency improves the estimate by sampling many traces and taking the majority answer:

Applied to the same model and benchmark, self consistency lifts GSM8K from 56.9 to 74.4 percent, a further 17.5 points. The two techniques compose, and together they add 56.5 points over the zero shot baseline.

SettingGSM8K accuracyChange from baseline
Standard prompting17.9baseline
Chain of thought56.9plus 39.0
Self consistency over traces74.4plus 56.5
Self consistency incremental74.4plus 17.5 over chain of thought

Instruction Tuning

Prompting is fragile because a small wording change can move accuracy by several points. Instruction tuning removes that variance by fine tuning on many tasks expressed as natural language instructions, so the description format seen at inference time is familiar. The Super-NaturalInstructions collection spans 1,616 tasks across eighty two languages, and the FLAN collection expands 60 datasets through template paraphrasing into 1,836 distinct tasks.

The practical effect is that a tuned model treats a zero shot instruction as an in-distribution request. This changes the error profile: rather than failing on format, the model produces the right structure for the wrong reason, and the remaining errors are capability errors that prompting cannot fix.

Controlled decoding closes the last gap. When the label space is known, constraining the first output token to the allowed labels converts a generation problem into a classification problem:

Worked Examples

Worked Code

python
def build_prompt(instruction, examples, question):
    blocks = [instruction.strip()]
    for i, (q, a) in enumerate(examples, 1):
        blocks.append(f"Example {i}\nQuestion: {q}\nAnswer: {a}")
    blocks.append(f"Question: {question}\nAnswer:")
    return "\n\n".join(blocks)

print(build_prompt(
    "Classify the sentiment as positive or negative.",
    [("the food was excellent", "positive"), ("we waited two hours", "negative")],
    "the staff were helpful and kind",
))
python
from collections import Counter

def self_consistency(traces):
    votes = Counter(answer for _, answer, _ in traces)
    mass = {a: round(sum(p for _, x, p in traces if x == a), 3) for a in votes}
    best = max(mass, key=mass.get)
    return best, dict(votes), mass

traces = [
    ("z1", "B", 0.13), ("z2", "A", 0.14), ("z3", "B", 0.12),
    ("z4", "B", 0.11), ("z5", "A", 0.12), ("z6", "C", 0.07),
    ("z7", "B", 0.11), ("z8", "A", 0.10),
]
choice, votes, mass = self_consistency(traces)
print("votes:", votes)
print("probability mass:", mass)
print("chosen:", choice)
print("win share:", round(votes[choice] / sum(votes.values()), 3))

Real-World Applications

  • Support triage - An instruction names the queue vocabulary and the model routes a ticket with no labeled training set for that queue.
  • Analytics assistants - Chain of thought makes the intermediate filter and aggregation explicit, so a wrong answer can be traced to a wrong step.
  • Compliance screening - Label constrained decoding guarantees the output is one of the allowed decisions, removing format failures from the audit log.
  • Rapid localization of new tasks - A new task ships as a description and three examples, then is promoted to fine tuning only if the error profile justifies it.

💡Test the instruction, not just the model

When accuracy is low, rewrite the instruction with the label definitions, an example of a boundary case, and an explicit output format. Most zero shot failures are specification gaps, and a rewrite is cheaper than a fine tune.

Common Mistakes

Comparing zero shot against fine tuned baselines

Fix: State the conditioning regime with every number, since zero shot, few shot, and fine tuned results are not comparable.

Sampling one chain of thought and trusting it

Fix: Vote over multiple traces, because the single best scoring trace is often the one that made the arithmetic slip.

Adding demonstrations that contradict the instruction

Fix: Examples define the label space implicitly, so a mismatched example silently overrides the written instruction.

Best Practices

  • Report shots, decoding strategy, and number of sampled traces with every accuracy figure
  • Apply label constrained decoding whenever the output vocabulary is closed
  • Escalate to instruction tuning only after prompt rewrites stop helping

Key Takeaways

  • Zero shot means instruction only, and the instruction is the entire supervision
  • Chain of thought treats reasoning as latent and marginalizes over sampled traces
  • Self consistency added 17.5 points over chain of thought on GSM8K for PaLM 540B
  • Instruction tuning turns a described task into an in distribution request

Frequently Asked Questions

How many examples should a few shot prompt contain?

As many as the context budget allows without pushing the question out of the window, but only if the examples are consistent. Three clean, mutually consistent demonstrations usually beat eight that disagree about the label boundary.

Does chain of thought help every task?

No. It helps tasks with genuine intermediate structure such as arithmetic, logic, and multi hop retrieval. On single step classification it adds latency and tokens while leaving accuracy flat, so it should be enabled per task rather than globally.

When does zero shot stop being viable?

When the label space is undefined in the instruction or when the task requires knowledge the model lacks. Prompting can fix the first, and only training or retrieval can fix the second.

Interview Questions

Q1: Explain why self consistency can beat the single most likely trace.

Because it aggregates probability mass by answer rather than by trace. Several medium probability traces that reach the correct answer can outscore one high probability trace that slips, so the vote recovers accuracy the argmax loses.

Q2: How do you decide between prompting and fine tuning?

I rewrite the prompt twice and measure. If the error rate stops moving and the errors are capability gaps rather than format gaps, the task has earned a fine tune.

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-07

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert NLP Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement