Language Models are Few-Shot Learners (GPT-3)¶
Authors: Tom B. Brown et al. (OpenAI - 31 authors total)
Published: May 2020 (NeurIPS 2020)
Paper Link: https://arxiv.org/abs/2005.14165
Why This Paper Matters¶
GPT-3 demonstrated that scaling language models to 175 billion parameters unlocks remarkable capabilities. It showed that models can perform tasks with just a few examples (few-shot learning) or even no examples (zero-shot learning), without any fine-tuning. This paper shifted the paradigm from "pre-train and fine-tune" to "pre-train and prompt," fundamentally changing how we interact with AI systems.
The Core Innovation: Scale + In-Context Learning¶
The Breakthrough Insight¶
Previous paradigm (BERT, GPT-2):
Pre-train → Fine-tune on task-specific data → Deploy
GPT-3 paradigm:
Pre-train at massive scale → Give examples in prompt → Use immediately
In-Context Learning¶
Instead of updating model weights, you provide examples in the prompt:
Zero-Shot (no examples):
Translate to French: "Hello, how are you?"
One-Shot (1 example):
Translate to French:
English: "Hello" → French: "Bonjour"
English: "Goodbye" →
Few-Shot (multiple examples):
Translate to French:
English: "Hello" → French: "Bonjour"
English: "Thank you" → French: "Merci"
English: "Goodbye" → French: "Au revoir"
English: "Good morning" →
The model learns the task from the examples in the prompt without any weight updates!
Model Architecture and Scale¶
GPT-3 Model Sizes¶
| Model | Parameters | Layers | Hidden Size |
|---|---|---|---|
| GPT-3 Small | 125M | 12 | 768 |
| GPT-3 Medium | 350M | 24 | 1024 |
| GPT-3 Large | 760M | 24 | 1536 |
| GPT-3 XL | 1.3B | 24 | 2048 |
| GPT-3 2.7B | 2.7B | 32 | 2560 |
| GPT-3 6.7B | 6.7B | 32 | 4096 |
| GPT-3 13B | 13B | 40 | 5120 |
| GPT-3 175B | 175B | 96 | 12288 |
Architecture Details¶
- Type: Transformer decoder (like GPT-2)
- Context Window: 2048 tokens
- Vocabulary: 50,257 tokens (GPT-2 BPE tokenizer)
- Training Data: 300B tokens (~570GB of text)
- Common Crawl (filtered): 410B tokens (60% weight)
- WebText2: 19B tokens (22% weight)
- Books1: 12B tokens (8% weight)
- Books2: 55B tokens (8% weight)
- Wikipedia: 3B tokens (3% weight)
Training¶
- Compute: ~3.14 × 10²³ FLOPS (~375 petaflop-days)
- Cost: Estimated $4.6M in compute
- Hardware: Likely thousands of GPUs/TPUs
- Training Time: Weeks to months
How GPT-3 Works¶
Autoregressive Language Modeling¶
Training Objective: Predict next token given all previous tokens
Input: "The cat sat on the"
Target: "mat"
Model learns: P(mat | The cat sat on the)
Generation Process: 1. Start with prompt 2. Predict next token 3. Append predicted token 4. Repeat until done
Example:
Prompt: "Once upon a time"
→ "there" (predicted)
→ "Once upon a time there"
→ "was" (predicted)
→ "Once upon a time there was"
→ "a" (predicted)
... continues ...
Why Scale Matters¶
Emergent Capabilities appear at scale: - Small models (125M): Struggle with complex tasks - Medium models (1.3B): Basic reasoning - Large models (13B): Better performance - GPT-3 (175B): Qualitatively different capabilities
Examples of emergent abilities: - Arithmetic (3-digit addition) - Logical reasoning - Using novel words in context - Simple programming - Following complex instructions
Key Results¶
Few-Shot Learning Performance¶
Translation: - English to French: Competitive with supervised systems - English to German: Near state-of-the-art
Question Answering: - TriviaQA: 71.2% (vs. 68.0% fine-tuned) - Natural Questions: 29.9%
Commonsense Reasoning: - PIQA (physical reasoning): 81.0% - ARC (science questions): 51.4% - HellaSwag: 78.9%
Reading Comprehension: - RACE-h: 46.8% - RACE-m: 58.4%
SuperGLUE (language understanding): - Few-shot: 71.8% - Fine-tuned BERT: ~89% - (Note: Without fine-tuning, impressive!)
Novel Capabilities¶
Creative Tasks: - Write poems in specific styles - Generate news articles (very convincing) - Create dialogue and stories - Compose basic code
Reasoning: - Solve word problems - Basic arithmetic (up to 3-digit) - Simple logical puzzles
Language Tasks: - Define made-up words from context - Correct grammar - Rephrase sentences - Summarize text
In-Context Learning: How It Works¶
The Scaling Hypothesis¶
Performance improves with: 1. Model size (more parameters) 2. Number of examples (more shots) 3. Example quality (better demonstrations)
Scaling Curve:
Zero-Shot < One-Shot < Few-Shot
Small Model < Medium Model < Large Model
GPT-3 175B Few-Shot >> GPT-3 13B Few-Shot
Prompt Engineering Matters¶
Bad Prompt:
Translate: "Hello" to French
Good Prompt:
English: "Good morning"
French: "Bonjour"
English: "Thank you"
French: "Merci"
English: "Hello"
French:
Best Practices: - Clear formatting - Consistent examples - Relevant examples - Sufficient examples (3-10 typically)
Limitations and Problems¶
1. Text Synthesis Issues¶
- Can generate false information confidently
- Lacks factual grounding
- No source attribution
- Can create misleading content
Example:
Q: Who was the 50th president of the United States?
A: The 50th president was John Anderson, elected in 2087.
2. Reasoning Limitations¶
- Struggles with complex multi-step reasoning
- Arithmetic errors (especially with large numbers)
- Inconsistent logical reasoning
- Can't explain its reasoning reliably
3. Sample Efficiency¶
- Needs massive amounts of data (300B tokens)
- Humans learn from far fewer examples
- Expensive to train and run
4. Bias and Fairness¶
- Reflects biases in training data
- Gender stereotypes
- Racial biases
- Potentially harmful outputs
Paper includes extensive bias analysis: - Gender bias in occupations - Racial bias in sentiment - Religious bias
5. Structural Limitations¶
- Fixed context window (2048 tokens)
- Can't access external information
- No memory beyond context window
- No real-world grounding
6. Energy and Environmental Cost¶
- Training: Estimated 1,287 MWh
- CO₂ equivalent: ~552 tons
- Inference also expensive
Broader Impacts (Paper's Own Analysis)¶
Potential Benefits:¶
- Democratize access to AI capabilities
- Assist with writing, coding, learning
- Automate routine language tasks
- Research tool for understanding language
Potential Risks:¶
- Misinformation: Generate fake news at scale
- Spam and Phishing: Automate malicious content
- Automation Impact: Job displacement
- Bias Amplification: Reinforce societal biases
- Dual Use: Could be used for harmful purposes
Mitigation Strategies:¶
- API access rather than open-source (control usage)
- Content filtering
- Usage monitoring
- Rate limiting
- Research into detection
Note: This became controversial - balancing openness vs. safety
Real-World Impact and Applications¶
Direct Applications (via OpenAI API):¶
- Content Creation: Writing assistance, marketing copy
- Coding: GitHub Copilot (uses Codex, GPT-3 variant)
- Customer Service: Chatbots and support
- Education: Tutoring, explanation
- Productivity: Email drafting, summarization
Research Impact:¶
- Sparked "scaling laws" research
- Prompted discussion on AI safety
- Led to improved prompting techniques
- Inspired architectural innovations
Industry Impact:¶
- Demonstrated commercial viability of LLMs
- Created market for language model APIs
- Influenced product roadmaps across tech industry
- Led to foundation model paradigm
GPT-3 Successors and Variants¶
Direct Successors:¶
- Codex (2021): Fine-tuned for code (powers GitHub Copilot)
- InstructGPT (2022): Trained with RLHF for following instructions
- ChatGPT (2022): Based on GPT-3.5 with conversational fine-tuning
- GPT-4 (2023): Multimodal, more capable, better reasoning
Competitors Inspired by GPT-3:¶
- PaLM (Google, 2022): 540B parameters
- LLaMA (Meta, 2023): Open-source, efficient
- Claude (Anthropic, 2023): Focus on safety and helpfulness
- Gemini (Google, 2023): Multimodal from the ground up
Key Concepts Introduced or Popularized¶
1. In-Context Learning¶
Learning tasks from examples in the prompt without gradient updates.
2. Prompting as Programming¶
Natural language instructions as the primary interface to AI.
3. Scaling Laws¶
Predictable improvements from scaling model size and data.
4. Few-Shot Transfer¶
Adapting to new tasks with minimal examples.
5. Foundation Models¶
Large pre-trained models as basis for many downstream tasks.
Comparison: GPT-3 vs. Other Approaches¶
| Aspect | GPT-3 | BERT | GPT-2 | T5 |
|---|---|---|---|---|
| Parameters | 175B | 340M | 1.5B | 11B |
| Approach | Few-shot | Fine-tune | Zero-shot | Fine-tune |
| Architecture | Decoder | Encoder | Decoder | Encoder-Decoder |
| Best For | Generation | Understanding | Generation | Text-to-text |
| Task Adaptation | Prompting | Fine-tuning | Prompting | Fine-tuning |
Lessons for Practitioners¶
1. Scale Unlocks Capabilities¶
- Larger models can do qualitatively different things
- Consider model size vs. task complexity
2. Prompt Engineering is Critical¶
- Invest time in crafting good prompts
- Few-shot examples significantly boost performance
- Format and consistency matter
3. Context Window Matters¶
- 2048 tokens = ~1500 words
- Design applications within this constraint
- Break large documents into chunks
4. Beware Hallucinations¶
- Always verify factual claims
- Don't use for critical decisions without verification
- Implement fact-checking pipelines
5. Consider Costs¶
- Inference is expensive at scale
- Balance model size vs. performance needs
- Explore smaller models for production
The Paradigm Shift¶
Before GPT-3:¶
Task → Collect labeled data → Fine-tune model → Deploy
(Weeks to months per task)
After GPT-3:¶
Task → Write prompt with examples → Use immediately
(Minutes to hours per task)
This dramatically lowered the barrier to using AI for language tasks.
Ethical and Social Considerations¶
The Paper's Broader Impacts Section¶
One of the first major AI papers to include extensive discussion of risks: - Misinformation and disinformation - Spam and phishing - Bias and fairness - Economic impacts - Environmental costs
This set a precedent for responsible AI disclosure.
The Release Strategy Debate¶
- GPT-2: Staged release due to concerns
- GPT-3: API-only, no model weights released
- Sparked debate: Open science vs. safety?
Key Takeaways¶
- Scale is a key ingredient for emergent capabilities
- In-context learning is powerful and practical
- Prompting becomes a new form of programming
- Few-shot learning works surprisingly well
- Risks and benefits must be carefully considered
- Language models can generalize across many tasks
- Investment in compute can yield breakthrough capabilities
Further Reading¶
- Original Paper: https://arxiv.org/abs/2005.14165
- OpenAI GPT-3 Blog: https://openai.com/blog/gpt-3-apps
- GPT-3 Creative Fiction: https://www.gwern.net/GPT-3
- Scaling Laws Paper: https://arxiv.org/abs/2001.08361
- The Illustrated GPT-3: https://jalammar.github.io/how-gpt3-works-visualizations-animations/
Citation¶
@article{brown2020language,
title={Language models are few-shot learners},
author={Brown, Tom B and Mann, Benjamin and Ryder, Nick and Subbiah, Melanie and Kaplan, Jared and Dhariwal, Prafulla and Neelakantan, Arvind and Shyam, Pranav and Sastry, Girish and Askell, Amanda and others},
journal={Advances in neural information processing systems},
volume={33},
pages={1877--1901},
year={2020}
}
Related in This Collection¶
- BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
- Training Language Models to Follow Instructions with Human Feedback (InstructGPT)
- Scaling Laws for Neural Language Models
- GPT-4 Technical Report
- Codex: Evaluating Large Language Models Trained on Code
- Language Models are Unsupervised Multitask Learners (GPT-2)
- Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer (T5)
- Emergent Abilities of Large Language Models (and the Mirage Rebuttal)