Zero-Shot Learning in NLP: Generalization Without Examples
Module: Natural Language Processing | Difficulty: Advanced
Zero-Shot Classification
Chain-of-Thought Prompting
Instruction Tuning
Few-Shot vs Zero-Shot
| Method | MNLI | SST-2 | QNLI | |--------|------|-------|------| | Zero-Shot | 72.3 | 85.6 | 68.1 | | One-Shot | 78.1 | 89.2 | 75.3 | | Few-Shot | 82.5 | 91.8 | 80.2 |
def zero_shot_classify(model, tokenizer, text, labels):
scores = []
for label in labels:
prompt = f"{text} This is about {label}."
inputs = tokenizer(prompt, return_tensors='pt')
with torch.no_grad():
outputs = model(**inputs)
log_prob = outputs.logits[0, -1, inputs.input_ids[0, -1]]
scores.append(log_prob.item())
return labels[scores.index(max(scores))]
Research Insight: Chain-of-thought prompting improves zero-shot reasoning by 20-40% on math and logic tasks. The key insight is that intermediate reasoning steps provide a scaffold for the model to build upon, similar to how humans solve complex problems.