Skip to main content

GPT-3: Language Models Are Few-Shot Learners — Understanding the Paper from First Principles

Updated 5 min readMarkdown
GPT-3: Language Models Are Few-Shot Learners — Understanding the Paper from First Principles

I recently started reading the research paper “Language Models are Few-Shot Learners”, the paper that introduced GPT-3.

Instead of jumping directly into the results, I first wanted to understand the concepts behind the paper: base models, parameters, pre-training, scaling, zero-shot, one-shot, few-shot, and in-context learning.

This article is my understanding of the paper from the ground up.


1. What problem was NLP trying to solve?

Before GPT-3, a common approach in NLP was:

Large text corpus
       ↓
   Pre-training
       ↓
Pre-trained model
       ↓
Task-specific dataset
       ↓
   Fine-tuning
       ↓
Task-specific model

The model would first learn general language patterns from a large amount of text.

Then, for a specific task such as:

  • Translation

  • Question answering

  • Sentiment classification

  • Reading comprehension

we would provide a task-specific dataset and fine-tune the model.

The problem was that fine-tuning often required thousands or tens of thousands of examples for each task.

Humans, however, can often understand a new task from just an instruction or a few examples.

This created an interesting question:

Can a language model learn a new task from only a few examples without being fine-tuned for that task?


Zero-Shot, One-Shot and Few-Shot Learning

The GPT-3 paper evaluates different levels of task-specific information.

They can be viewed as a spectrum:

Less task-specific information
            ↓
Zero-shot → One-shot → Few-shot → Fine-tuning
            ↓
More task-specific information

Let's understand them.

Zero-Shot

The model receives an instruction but no examples.

Translate English to French:

Hello →

The model has to figure out the task from the instruction.

Instruction
     ↓
GPT-3
     ↓
Answer

One-Shot

The model receives one example.

English: Hello
French: Bonjour

English: Good morning
French:

The model uses the first example to understand the task.


Few-Shot

The model receives multiple examples.

English: Hello
French: Bonjour

English: Thank you
French: Merci

English: Good morning
French: Bonjour

English: How are you?
French:

The model uses these examples as context to infer the task.

What Does "Few-Shot" Mean in GPT-3?

The paper defines few-shot learning as giving the model a few demonstrations at inference time while allowing no weight updates.

A demonstration usually contains:

Context → Desired completion

For example:

Context: English sentence
Completion: French translation

Then multiple demonstrations are placed before a new example:

Example 1: Context → Completion

Example 2: Context → Completion

Example 3: Context → Completion

New Context → ?

GPT-3 generates the missing completion.

The important thing is:

Examples
   ↓
Context
   ↓
GPT-3
   ↓
Answer

Parameters remain unchanged

How Many Examples Did GPT-3 Use?

The paper represents the number of demonstrations using K.

K = number of examples

Therefore:

K = 0  → Zero-shot
K = 1  → One-shot
K > 1  → Few-shot

They typically used around 10–100 examples for few-shot evaluation, depending on what could fit inside the model's context window.

The context window in this setup was:

2048 tokens

So the number of examples depends on how much text each example requires.

How Did They Evaluate GPT-3?

The researchers tested GPT-3 on many different NLP benchmarks.

The basic idea was:

GPT-3
  ↓
Different benchmarks
  ↓
Generate predictions
  ↓
Compare predictions with expected results
  ↓
Calculate evaluation score

Some important benchmarks include:

PTB

Penn Treebank

Used for language modeling.

Remember:

PTB → Language modeling

LAMBADA

Tests the ability to understand context across a passage and predict the final word.

Remember:

LAMBADA → Long-context understanding

StoryCloze

Tests understanding of stories and selecting an appropriate ending.

Remember:

StoryCloze → Story understanding

Winograd

Tests language understanding and commonsense reasoning, including pronoun resolution.

Remember:

Winograd → Reasoning / pronoun resolution

What Are BLEU, F1 and Exact Match?

These are evaluation metrics.

They answer:

How good was the model's answer?

BLEU

Often used for translation.

It measures the similarity between generated text and reference translations using word/phrase overlap.

Remember:

BLEU → Translation/text generation

F1

F1 combines precision and recall.

Remember:

F1 → Balance between precision and recall

Exact Match

The predicted answer must match the expected answer according to the evaluation rules.

Remember:

Exact Match → Exact answer correctness

What Data Was GPT-3 Trained On:

The paper used a mixture of:

  • Common Crawl

  • WebText2

  • Books1

  • Books2

  • Wikipedia

The major source was Common Crawl.

But the researchers did not simply throw raw web data into the model.

They performed data processing.

What Did They Find?

The major finding was that larger language models generally performed better in zero-shot, one-shot, and few-shot settings.

This was important because the model was becoming increasingly capable of performing tasks without task-specific fine-tuning.

Conceptually:

Model size increases
        ↓
Model capability increases
        ↓
Few-shot performance improves

This does not mean that simply adding parameters solves every problem.

GPT-3 still struggled on some tasks.

But the overall trend was significant.


No comments yet. Be the first to comment.