Back to section lessons
Free overview · easy · Lesson 2 of 9

Turn text into training pairs

Split a short phrase into examples where two words give the model a clue and the third is its target.

To learn prediction, a model needs a prefix as input and the correct next word as a separate target. A single sentence can supply several examples. Words after the target must stay out of the input.

A small example

Take “birds drink water daily” and keep two preceding words as the hint. After “birds drink”, the target is “water”. Shift the window by one: “drink water” now points to “daily”. Try producing two such pairs from your own four-word sentence.

Why hide the answer?

Cover everything after “birds drink”. You can think of several plausible next words, including “water” and “nectar”. For training, the target is the word that actually came next in the text. Reveal it after the prediction and compare it with the model’s choice.

If you include “water” in the input and also expect “water” as the output, copying a visible word could earn a perfect score. That score tells you little about how the model would continue a new sentence.

See it happen

Two words in. One target out.

Highlighted words form the input window. The outlined token is the target. Move forward: the window follows the sentence, including its end.

<PAD>input · id 0<PAD>input · id 0apitarget · id 3respondsid 4fastid 5<EOS>id 2

Model input

<PAD> · <PAD>

Indices [0, 0]

Correct next token

api

Index 3. Not included in the input.

Example 1 of 4. Target: api.

Teaching tokenizer: one word per token. PAD fills missing input; EOS marks the end. No model is trained here.

Done reading?

Mark the lesson as read to move your track progress forward.

Now build your own version

Build training pairs from new sentences. Check that the target stays out of the input and windows never mix documents.

What practice includes and how much it costs

MCP includes the full lesson and a local project with starter files. Work through the task with your agent, ask for a hint and run the checks on your computer.

$134 $67.00 for one year −50%

One payment, no auto-renewal · Terms

Buy for $67.00