Concepts / Training Data for Language Models

Training Data for Language Models

Self-supervised learning trains a model on data without explicit labels, creating labels from the structure of the data itself.

  • Programming

Where Training Labels Usually Come From

Most people picture machine learning as a teacher with an answer key. You show a program thousands of photos, someone has marked each photo with what it contains, and the program learns to match pictures to those marks. The marks are called labels, and producing them is often slow and expensive.

Language models such as GPT face a serious version of this problem. Their training material is written text. Text is abundant, but nobody has attached a labeled answer to each sentence. So the question is how a model can still learn from such text, and why that makes it practical to train on very large collections of unlabeled writing. This article answers both parts, starting with a small experiment you can run in your head.

What do you think happens?

In the sentence 'The cat sat on the mat', what label would a model be trained to predict when its input is 'The cat'?

  • sat

  • cat

  • mat

  • The

Reveal answer
Answer:

sat

The label at each position is the word that actually comes next in the text. After 'The cat' the next word in the sentence is 'sat', so 'sat' is the label. No person had to write that answer; it is read straight from the sentence.

Labels Hidden Inside the Text

Definition

Self-supervised learning trains a model on data without explicit labels, creating labels from the structure of the data itself.

The key idea is that a text already contains information about its own structure. Words appear in a particular order, and each word sits in a particular place relative to the words around it. Self-supervised learning exploits that order. Instead of asking a human to supply the answer for each piece of text, the training procedure reads the answer straight out of the text.

Put simply, the data supplies both the question and the answer key. The earlier words are the question the model sees, and the word that really follows them is the answer it is checked against. Because the answer is already present in the data, no separate annotation step is needed.

Next-Word Prediction as a Labeling Rule

The specific technique that GPT relies on is next-word prediction. It is a task in which the model is asked to predict the next word in a sentence or document. The next word that actually appears in the text serves as the label the model is supposed to predict.

This gives a simple rule that can be applied at every position in the text. Take the words up to some point, call them the input, and look at the word that follows. That following word is the label for that position. Repeat the rule at each position, and the text generates its own training examples.

Tracing One Sentence Into Training Pairs

The sentence 'The cat sat on the mat' is a generated example, not taken from the source, but it follows the same rule. Read it from left to right. Each diagram cell below shows one word of the sentence and the label that the rule assigns to it. The diagram is an index map: position, word, and the word that follows.

Thelabel: catcatlabel: satsatlabel: ononlabel: thethelabel: matmatno labelnext wordnext wordnext wordnext wordnext word
For the sentence 'The cat sat on the mat', which word is the label at each position, and where does the last word fall?
Worked example

Counting the training positions in one sentence

How many input and label pairs does the sentence 'The cat sat on the mat' produce, and what is each pair?

  1. 1
    Step 1: Choose the first input

    Start with the first word, 'The'. The next word in the sentence is 'cat', so the pair is input 'The' with label 'cat'.

  2. 2
    Step 2: Grow the input by one word

    Now the input is 'The cat'. The next word is 'sat', so the pair is input 'The cat' with label 'sat'.

  3. 3
    Step 3: Continue the same way

    Input 'The cat sat' has label 'on'. Input 'The cat sat on' has label 'the'. Input 'The cat sat on the' has label 'mat'.

  4. 4
    Step 4: Stop at the last word

    The final word 'mat' has no word after it inside this sentence, so it cannot serve as a label here. It appears only as the label of the word before it.

  5. 5
    Step 5: Count the pairs

    There are five input and label pairs, from a sentence of six words. One sentence produced five training examples without any human writing a label.

Result

Five training pairs: The to cat, The cat to sat, The cat sat to on, The cat sat on to the, and The cat sat on the to mat.

The Moving Context Window

The sentence-tracing process can be seen as a window that moves across the text. At each step the window covers the words seen so far, which form the input. The word just after the window is the target the model must predict. Then the window grows by one word, and the next target is the word after that.

Window: Thetarget: catWindow: The cattarget: satWindow: The cat sattarget: onWindow: The cat satontarget: theWindow: The cat saton thetarget: matadd one wordadd one wordadd one wordadd one word
How does the known input grow by one word at each step, and where does each target word come from?

Notice where each target comes from. It is never supplied by hand. It is simply the next word already sitting in the text, waiting to be read. The model sees the window, produces a guess for the target, and the actual word from the text is the reference used for comparison.

Supervised Versus Self-Supervised Labels

The difference between the two approaches lies in where the answer comes from. In the photo example, people write each label after the data exists. In self-supervised training, the label is already part of the data, because it is the word that follows.

Labels written bypeopleLabels read from thetextLabels producedslowly andexpensivelyLabels created on thefly
What is different about the source of labels in supervised learning compared with self-supervised learning?
Key point

Self-supervised learning removes the need to collect labels explicitly. The structure of the text provides the label at every position, so there is no separate annotation pass.

Why Massive Unlabeled Text Becomes Usable

Because labels are generated as the training process reads through the text, one position at a time, any ordinary body of text can serve as training material without being prepared first. There is no need to annotate it in advance. A collection of writing becomes training data simply by being read.

The practical payoff is that self-labeling removes the bottleneck of annotation. The source states directly that next-word prediction makes it possible to use massive unlabeled text datasets to train LLMs such as GPT. The amount of training material is limited by the text available, rather than by how much human labeling time can be paid for.

In the real world

Imagine two teams. The first must hand-label every sentence before training can begin, so its data grows only as fast as its annotators work. The second points its training procedure at a large collection of written text and lets next-word prediction create the labels as it reads. The second team's supply of training positions grows with the text it can access, which is the advantage the source describes.

Mistakes Beginners Make With Self-Labeling

  • Common mistake

    Believing that someone must have labeled the text first

    What it looks like

    Assuming the sentence 'The cat sat on the mat' needs a note saying what each word means before the model can learn from it.

    Why it fails

    The label at each position is the word that actually follows in the text, so it is read from the data rather than written by a person.

    Do this instead

    Ask only one question at each position: what word actually comes next here?

  • Common mistake

    Labeling the final word of a sentence

    What it looks like

    Giving the word 'mat' a label inside the sentence 'The cat sat on the mat'.

    Why it fails

    Nothing follows 'mat' inside that sentence, so there is no word to use as its label.

    Do this instead

    Stop the pairs one word before the end of the sentence or document.

  • Common mistake

    Thinking one sentence yields only one training example

    What it looks like

    Counting only the whole sentence as a single example for 'The cat sat on the mat'.

    Why it fails

    Every position with a following word creates its own input and label pair, which gives five pairs here.

    Do this instead

    Count the positions, not the sentences.

  • Common mistake

    Assuming self-supervised labels are always correct in a human sense

    What it looks like

    Treating the word that follows as a verified answer about meaning.

    Why it fails

    The label is simply the word that appears next in the text, which is the thing the model is trained to predict.

    Do this instead

    Think of the label as the actual next word in the data, not as a judgment written by an annotator.

Practice: Pairing Words in a New Sentence

EASY

Take the sentence 'Birds sing in trees'. Write out every input and label pair that next-word prediction would create from it. Then say how many pairs the sentence produces and which word never becomes a label.

Hints
  • Start with the input 'Birds' and find the word that comes next.
  • Each time, grow the input by one word, as in the window example.
  • The last word 'trees' has nothing after it inside the sentence, so it is not a label.

Checking the Answer to the Practice

Worked example

Tracing the sentence Birds sing in trees

List the input and label pairs for 'Birds sing in trees'.

  1. 1
    Pair 1

    Input 'Birds', label 'sing'.

  2. 2
    Pair 2

    Input 'Birds sing', label 'in'.

  3. 3
    Pair 3

    Input 'Birds sing in', label 'trees'.

  4. 4
    Word without a label

    The word 'trees' is the end of the sentence, so it appears only as a label and never has a label of its own here.

Result

Three training pairs from a four-word sentence, following the same pattern as the 'The cat sat on the mat' example.

Key Takeaways

  • Self-supervised learning trains a model on data without explicit labels, creating labels from the structure of the data itself.
  • In next-word prediction, the word that actually follows a position in the text serves as the label for that position.
  • A single sentence yields many training positions, one for each word that has a following word, all without human annotation.
  • Because labels are created on the fly as the text is read, massive unlabeled text datasets can be used to train LLMs such as GPT.

Related concepts

More concepts starting with T