model-insights · GPT-2 small · WebText

Inside GPT-2

In 2019 OpenAI trained GPT-2 to do one thing: given some text, guess the next piece. Its training data was WebText, about 8 million web pages that had been linked from Reddit posts with at least three upvotes. This page runs the smallest version (124 million parameters) in your browser, opens up its forward pass, and looks for what those pages left behind.

Loading model weights…

1 Text becomes tokens

GPT-2 never sees letters. Text is first converted to bytes and then cut into pieces from a fixed vocabulary of 50,257 tokens. The vocabulary was built by byte-pair encoding: start from the 256 possible bytes and repeatedly merge the most frequent adjacent pair in the training text into a new token, 50,000 times. Common words become one token. Rare words are spelled out in pieces. Type below to see how text gets split.

A leading space is part of the token (shown as ·), so " the" and "the" are different tokens. Tokens marked ◆ hold only part of a multi-byte character, such as one byte of an emoji. They mean nothing on their own.

2 Tokens it never learned to use

Each token gets an embedding, a vector of 768 numbers that the model learns during training. Every vector starts out random, and training only moves the vectors of tokens that actually occur in the training text. A token that almost never appears keeps its starting value. That makes it sit close to the average of all embeddings, apart from the tokens that were used.

The likely cause is a mismatch: the vocabulary was fitted to a larger, rawer pile of scraped text than the filtered pages the model then trained on. Strings that were frequent in the first but almost absent from the second got their own token, and almost no training. They read like a list of the web's back rooms:

3 One guess at a time

The model reads up to 128 tokens here (1,024 in the original) and, at every position, outputs a probability for each of the 50,257 possible next tokens. Each token's vector goes through 12 identical blocks. In each block, attention lets every position copy information from earlier positions, and an MLP transforms each position on its own. Both add their result to a running vector, the residual stream. At the end, the stream is compared with every token's embedding to score the candidates.

Layer by layer

The text, coloured by how expected each token was

Colour is the probability the model gave each token before seeing it: bright means expected, dark means surprising. Click a token to inspect the prediction made there.

Next token after

    The logit lens reads the residual stream after each block as if the model had to answer right there: the stream goes through the final layer norm and the unembedding early. Each cell shows the top guess and its probability for the token after that column. In the lower rows the guess is often just a copy of the token itself. Higher up, the model's answer forms. Shown: the 16 positions up to the selected token.

    4 What it memorised

    A language model is a compression of its training text, and the text that compresses best is the text that occurred thousands of times. Pick a passage below and look at the colours. A token the model saw coming is bright. A passage it has memorised is bright from start to finish.

    What GPT-2 small remembers word for word is not what is famous. It is what was copied: software licences pasted into thousands of repositories, the wire-service footer under every Associated Press story, the share buttons of every WordPress blog. Hamlet's soliloquy and the digits of π are famous, yet they score barely better than a sentence made up for this page. The model is a record of how often text appeared on the web, not of what mattered.

    From nothing

    Every document in training ended with the special token <|endoftext|>. Start from that token alone and the model writes the start of a typical WebText document. These are samples at temperature 0.9 (first one: greedy):

    Live samples are unfiltered. They read like WebText, which includes crime reporting, slurs and conspiracy theories, so expect some to be unpleasant.