Language Modeling Fundamentals
Language modeling offers a way around this bottleneck.
Why Predicting the Next Word Is Hard to Label
Imagine you want to teach a model to predict the next word in a sentence. The most direct approach is to collect many examples and have people write down the correct answer for each one. That works, but it is slow, expensive, and hard to scale. Every new task seems to demand a new round of human annotation. Researchers call this the data labeling bottleneck, and it is one of the main reasons machine learning projects stall before they reach useful performance.
Language modeling offers a way around this bottleneck. The model does not need a person to write down the answers, because the raw text already contains them. In this article you will see how that works, follow one sentence step by step as it becomes training data, and look at why bigger models ask for bigger datasets.
Self-Supervision as Label Generation
Self-supervision is an approach that sidesteps much of the labeling cost. Instead of asking a human to attach an explicit label to each example, the model is set up so that it can work out the labels from the input data itself. The raw material already contains the answers. The training process simply needs to be arranged so that those answers are revealed to the model in the right way.
Self-supervision: a training setup in which the model infers its own labels from the input data, so that no separate human annotation step is required.
Splitting Input Into Context and Target
The key idea is to split each piece of input into two roles. One part serves as the context the model is allowed to look at. The other part serves as the target that the model must predict. Because the target comes from the input itself, no separate annotation step is required. The same text that feeds the model also tells you what the correct output should have been.
Language modeling fits this pattern naturally. Each input sequence provides two things at once: the tokens the model should predict, and the surrounding tokens the model can use as context when making that prediction. Nobody needs to write the answers down, because the sequence already contains them.
Tracing One Sentence Into Samples
Before working through a new sentence, consider the example this material uses: the sentence 'I love street food.' is reported to produce six training samples from its own text. Each sample pairs some preceding material with the piece that comes next, which is what makes the sentence useful without any labels being added.
To see the mechanism without relying on that count, try a different sentence. Take 'The cat sat down.' and treat each word and the final period as a token. Starting from the first token, every position after the first gives a sample: the words before it form the context, and the current word is the target. Work through the trace below, then compare it with the diagram that follows.
Turning 'The cat sat down.' into training samples
Treat the tokens as The, cat, sat, down, and the period. List every training sample the sentence yields under the rule that each position after the first is a target once.
- 1Identify the tokens
The five tokens are The, cat, sat, down, and the period.
- 2Skip the first token as a target
The first token has no preceding material to serve as context, so it does not produce a sample by itself.
- 3Build sample 1
Context is 'The' and the target is 'cat'.
- 4Build sample 2
Context is 'The cat' and the target is 'sat'.
- 5Build sample 3
Context is 'The cat sat' and the target is 'down'.
- 6Build sample 4
Context is 'The cat sat down' and the target is the period.
Four training samples come from one unlabeled sentence, and no human wrote any of the targets. Each target was already sitting in the text, one position after its context.
Why Capacity Needs Data
A second question follows naturally once models can be trained without labels: how much data does a model need? The size of a model changes what counts as small or large. At the time of writing, a model with 100 billion parameters was considered large, and the source expects that such a figure may one day seem modest. Size is therefore relative, but the relationship between size and data is what matters here.
Larger models have more capacity to learn. Capacity is the room a model has to absorb patterns from its training material. A model with more capacity can represent more detail, but it can only use that room if it is given enough examples to fill it. Without enough data, the extra capacity has nothing to learn from, so it contributes little to performance. For that reason, larger models need more training data to reach their best results.
Training a large model on a small dataset wastes compute that a smaller model could have used well. The large model spends its training effort on a dataset that cannot exercise most of its capacity, while a smaller model matched to the same data would have put the same compute to good use.
Mistakes Beginners Make With Self-Supervision
Common mistake Believing that self-supervised training still needs a human to write each label
What it looks likeAssuming someone must annotate every next-word target in a corpus before training can start
Why it failsThe target comes from the input itself. Each input sequence supplies both the tokens to predict and the context used to predict them.
Do this insteadIdentify which part of the raw text plays the context role and which part plays the target role.
Common mistake Assuming the first token of a sentence produces a sample
What it looks likeCounting 'The' as a target with no context before it
Why it failsEach token after the first serves as a target once. The first token has no preceding words to act as context.
Do this insteadStart generating samples at the second position, using everything before it as context.
Common mistake Treating a bigger model as automatically better on any dataset
What it looks likeChoosing the largest available model for a small corpus and expecting strong results
Why it failsLarger models have more capacity, and that capacity only helps when enough training data fills it. Otherwise the extra capacity contributes little and the compute is wasted.
Do this insteadMatch model size to the amount of training data available, and add data when you scale the model up.
Checking Your Sample Count
What do you think happens?
How many training samples does the sentence 'The dog ran.' yield if each word and the final period are tokens?
Reveal answer
Three samples
The tokens are The, dog, ran, and the period, giving four tokens. Every position after the first yields one sample: The to dog, The dog to ran, and The dog ran to the period. That is three samples.
Take the sentence 'Models learn patterns.' and treat each word and the final period as a token. List every (context, target) training sample it produces, and state which token is the label in each sample.
Hints
- Count the tokens first, then skip the first token as a target.
- Each sample's context is every token before the target.
Key Takeaways
- Self-supervision lets a model infer its labels from the input itself, which helps overcome the data labeling bottleneck.
- In language modeling, each input sequence supplies both the context and the target, so no separate annotation is needed.
- One sentence yields several training samples, with each token after the first serving as a target once.
- Larger models have more capacity and need more training data; training a large model on a small dataset wastes compute.