cat posts/2020-06-23-gpt-3-and-few-shot-learning.md
GPT-3 and few-shot learning
The GPT-3 paper runs to more than 70 pages and has 31 authors, and the most interesting result in it is a table of grade-school arithmetic.
The paper is Language Models are Few-Shot Learners, from OpenAI, posted at the end of May. GPT-3 is the same basic idea as GPT-2 last year, a Transformer trained to predict the next word on a huge pile of text, made much bigger. GPT-2 was 1.5 billion parameters. GPT-3 is 175 billion, about ten times bigger than any previous model of its kind, with 96 layers and a context window of 2,048 tokens, trained on about 300 billion tokens of text. On June 11th OpenAI announced an API for it, a private beta with a waitlist. I’m on the waitlist, so everything here comes from reading the paper, not from playing with it.
What “few-shot” means
The usual way to get a language model to do a specific task, say translate English to French or answer trivia, is to fine-tune it: take the pretrained model and keep training it on a few thousand labeled examples of the task, which changes its weights. That’s what the field has mostly done since BERT.
GPT-3 doesn’t do that. The weights are frozen. Instead you put the task in the prompt. Zero-shot means you just describe it (“Translate English to French: cheese =>”). One-shot means you give one worked example before the real question. Few-shot means you give it a handful, as many as fit in the 2,048-token window, usually 10 to 100. Then the model does what it always does, predicts what text comes next, and if it’s good enough at that, what comes next is the answer.
So the “learning” in few-shot learning happens entirely inside one forward pass over the prompt, with no gradient updates at all. The paper calls this in-context learning. That’s the claim that matters: one model, trained once, that you program with examples instead of training.
The arithmetic table
Which brings me back to the arithmetic. They gave the model problems like “Q: What is 48 plus 76? A:” with a few solved examples in front, and here’s the few-shot accuracy for the full 175B model:
- 2-digit addition: 100%
- 2-digit subtraction: 98.9%
- 3-digit addition: 80.4%
- 3-digit subtraction: 94.2%
- 4-digit addition: 25.5%
- 5-digit addition: 9.3%
- 2-digit multiplication: 29.2%
Nobody needs a 175-billion-parameter model to add numbers. What’s interesting is that nobody taught it to. And the obvious objection, that it’s seen “48 plus 76” somewhere on the internet and memorized it, they actually checked. They searched the training data for the 3-digit problems in the test set and found 17 matches out of 2,000 for addition and 2 out of 2,000 for subtraction. So it isn’t just looking answers up. They also say the wrong answers often look like a person’s mistakes, forgetting to carry a 1, which suggests something like a procedure, a bad one, is happening in there. And it falls off a cliff at 4 digits, which tells you whatever it learned isn’t really the algorithm.
The smaller models in the same paper, trained the same way, are much worse at this. The next size down, 13 billion parameters, gets 2-digit addition and subtraction right only about half the time, and everything else less than 10% of the time. That’s the pattern across most of the paper: the few-shot ability gets steadily better with size, and on several tasks it shows up mostly at the top end. If that trend holds, the obvious thing to do is make it bigger again, which I suspect someone is already doing.
I took Andrew Ng’s machine learning class in its first run in 2011, and there’s a slide from it I still remember, from the week on machine learning system design. He showed results where several quite different algorithms all converged as the training set got bigger, and the lesson he drew was that it’s often not who has the best algorithm that wins, it’s who has the most data. In 2011 that was about spam classifiers and logistic regression. GPT-3 is that lesson taken about as far as anyone has taken it, the same architecture as GPT-2 and a lot more data and compute. I find that slightly depressing, as someone who likes clever algorithms, and also hard to argue with.
The parts that should make you careful
The paper is unusually candid about its problems, which I appreciated. A few that stood out:
On many standard benchmarks few-shot GPT-3 is good but not as good as smaller models fine-tuned on the task. It beats the state of the art on some, a couple of the trivia and language modeling ones, and loses on plenty, including some reading comprehension and the tasks where you compare two sentences. The headline is that it can do a bit of everything without any task-specific training, which is impressive enough without overselling it.
There’s a data contamination problem they own up to. They tried to remove test-set examples from the training data, a bug in the filtering meant some overlaps got through, and the model was too expensive to retrain. They spend a whole section estimating how much it matters, and conclude mostly not much, but it’s a strange thing to read in a paper. It also tells you something about the cost. When you can’t afford to fix a bug by running the job again, you’re in a different regime from the models most of us have ever trained. (The models I fit during the certificate trained on my laptop in a few minutes, and I re-ran them a dozen times a night.)
And then the news articles. They had people try to tell GPT-3’s short news articles apart from real ones, and for the 175B model people were right 52% of the time, which is basically a coin flip. After my GPT-2 post I did download the small model and fed it our help-center articles as prompts, and the output was fluent nonsense, recognizably machine-written after a sentence or two. If the 52% result holds up outside a study, the spam and phishing worries I had last year get a lot more real, and “does this text look human” stops being a usable filter for anything.
For programmers
This is the part where I’m least sure, so take it as a guess.
The paper doesn’t really test code. But the pattern it does test, show a few examples of input and output and let the model continue, is what a lot of programming looks like from the outside. Converting data from one format to another. Writing a SQL query from a description. Writing the tenth test case when you’ve written nine similar ones. If few-shot works for those, I’d think of it as a very strange autocomplete that you configure with examples instead of rules, which is more useful than it sounds.
But arithmetic falling apart at 4 digits is the warning label. A model that’s right 80% of the time on 3-digit addition is, for most programming purposes, a model that’s wrong. When it’s wrong you get a confident, plausible answer that’s slightly off, which is the hardest kind of bug to catch in review. I’d want any code it wrote to come with tests I wrote, and I’m not sure how much time that saves.
I’m also not convinced about the economics. Nobody outside OpenAI can train this, and maybe not many inside can run it cheaply. The API is how they’re dealing with that, and it means the rest of us rent access to one company’s model and its rules about what we can use it for. That’s a very different world from the one where I could download a model and train it on my own laptop.
I’ve got my name on the waitlist. If I get in, the first thing I’ll try is the dull stuff, turning our support team’s free-text tags into categories, and I’ll write up how often it’s wrong.