Tokenization: Converting Text into Tokens
A token is a unit of text that a model reads, and dataset sizes are commonly reported as token counts, which roughly track the number of words and punctuation characters.
Measuring a Training Set in Tokens
When people describe a large language model, they usually talk about its size in parameters or about the amount of computing used to build it. A second question is just as important: what did the model see during training? Before a model can learn anything, someone has to decide which text goes into its training collection, how much of each kind of text is included, and how that collection is measured.
The GPT-3 model offers a concrete case study. Its pretraining collection was assembled from several sources, and the way those sources were combined says a great deal about what the model learned to imitate. We will follow one composition table through three questions: what unit the table measures the data in, where the data came from, and how much of it the model actually consumed. Each question changes how you read the numbers, so we will take them in order.
What a Token Is
A token is a unit of text that a model reads. Dataset sizes are commonly reported as token counts, and those counts roughly track the number of words and punctuation characters in the text.
The step that turns raw text into these units is called tokenization: converting text into tokens. The direction of the transformation is the key idea. Human-readable text goes in, a sequence of token units comes out, and only that sequence is what the model reads. The detailed mechanics of tokenization are deferred to a later chapter, so for now treat it as a conversion step whose output is the unit of measurement for the whole dataset.
A useful rule of thumb is that the number of tokens in a text is roughly equal to the number of words plus the punctuation characters. The rule is approximate, so read token counts as estimates of how much text there is, not as exact word counts.
Counting Tokens in a Sentence
Estimating the token count of one question
Estimate the number of tokens in the sentence: Why is the sky blue?
- 1Count the words
The words are Why, is, the, sky, and blue. That is 5 words.
- 2Count the punctuation
The question mark at the end is one punctuation character.
- 3Apply the rule of thumb
Tokens are roughly words plus punctuation, so 5 + 1 = 6 token units.
- 4State the caveat
This is an estimate. The exact split a tokenizer produces can differ, so the answer is approximately 6.
About 6 tokens. Measured this way, a document's size reflects how much text it contains, which is why dataset sizes are reported in tokens.
Why measure in tokens rather than documents? Documents vary enormously in length. A single long article and a single short note are each one document, yet they contain very different amounts of text. Counting tokens puts every piece of text on a common scale, so two collections can be compared by how much text they actually hold.
Where the GPT-3 Training Data Came From
The GPT-3 pretraining collection drew on five named datasets. They fall into two broad families. Some are web crawl data, gathered by automatically collecting pages from the internet. Others are internet-based book collections or high-quality text. The composition table lists each dataset with a short description, its size in tokens, and its share of the training data.
| Source | Family | Share of training data |
|---|---|---|
| CommonCrawl (filtered) | Web crawl data | 60 percent |
| Internet book collection (first) | Internet-based book collection | 8 percent |
| Internet book collection (second) | Internet-based book collection | 8 percent |
| Two remaining sources | Not separated in this excerpt | 24 percent combined |
The five sources in the GPT-3 pretraining mix. The two remaining sources are shown together because this excerpt does not give their individual shares.
CommonCrawl (filtered) contributes the biggest slice of the training mix at 60 percent. The two book collections are given equal weight at 8 percent each, even though their token counts can differ. That is why the two columns of the table must be read side by side. A large token count does not automatically mean a large share of the mix, and a share describes proportion, not raw size.
Available Tokens Versus Trained Tokens
The composition table reports a total of 499 billion tokens. The model, however, was trained on 300 billion tokens. These are two different numbers answering two different questions. The first describes what the collection contains. The second describes what a training run consumed.
This distinction matters whenever you compare datasets from published papers. A figure describing what a collection contains is a different claim from a figure describing what a training run consumed. When you read a composition table, ask which of these two numbers the author is reporting.
Checking Whether the Shares Add Up
Verifying the composition proportions
Given CommonCrawl (filtered) at 60 percent and two book collections at 8 percent each, check whether the proportions can be internally consistent with a total of 100 percent.
- 1Add the known shares
$60\% + 8\% + 8\% = 76\%$. These three sources account for 76 percent of the sampled training data.
- 2Find the remainder
$100\% - 76\% = 24\%$. The remaining share must belong to the other sources.
- 3Match the remainder to the table
The table lists two remaining sources together at 24 percent. Their shares therefore sum to the remainder, so the column is consistent.
- 4Allow for rounding
The proportion column describes the mix of the sampled data and sums to 100 percent once rounding is allowed for. A small difference from exactly 100 is acceptable, but a large one would signal an error in the table.
The listed shares are internally consistent: 60 + 8 + 8 + 24 = 100 percent, with rounding allowed.
Mistakes Readers Make With Token Counts
Common mistake Treating tokens and documents as the same unit
What it looks likeSaying a dataset has 5 million documents and therefore 5 million tokens.
Why it failsDocuments vary in length, so one document can contain many tokens or very few.
Do this insteadRead dataset sizes in tokens, which measure the amount of text on a common scale.
Common mistake Reading the total as the amount the model trained on
What it looks likeAssuming the model saw all 499 billion tokens because that total is listed.
Why it failsThe table lists 499 billion tokens while the model was trained on 300 billion tokens.
Do this insteadKeep the available total and the trained amount separate, and ask which one a given figure reports.
Common mistake Equating a large share with a large token count
What it looks likeAssuming two sources with equal shares must contain equal numbers of tokens.
Why it failsA share is a proportion of the mix, and token counts for the same share can still differ between sources.
Do this insteadRead the share column and the token column side by side.
Common mistake Assuming the token rule is exact, when it is only a rough estimate of text volume
Testing Your Reading of the Composition Table
What do you think happens?
Before reading the answer, predict: must the five source shares in a composition table add up to exactly 100 percent?
Reveal answer
The shares should sum to 100 percent once rounding is allowed for, not necessarily to exactly 100 with every rounded figure.
The proportion column describes the mix of the sampled data. Rounded percentages can differ slightly from 100, so you check for consistency and allow for rounding rather than demanding an exact match.
A composition table lists four sources at 50 percent, 20 percent, 20 percent, and 8 percent, and gives a total of 200 billion tokens. Explain whether the proportions are internally consistent, and state what the 200 billion figure does and does not tell you about how many tokens the model was trained on.
Hints
- Add the four percentages and compare the result with 100 percent.
- A total in a composition table describes the collection, not necessarily the training run.
Key Takeaways
- A token is a unit of text that a model reads, and dataset sizes are reported in tokens because token counts roughly track the words and punctuation in the text.
- Tokenization converts human-readable text into a sequence of token units, and only that sequence is what the model reads.
- The GPT-3 pretraining mix has five sources, led by CommonCrawl (filtered) at 60 percent, with two book collections at 8 percent each and two remaining sources together at 24 percent.
- The composition table lists 499 billion tokens in total, but the model was trained on 300 billion tokens, and the source does not explain the difference.
- To check a composition table, add the listed shares and confirm they sum to 100 percent once rounding is allowed for, then ask whether each figure describes the collection or the training run.