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.
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.
Python right here
Each arrow separates a two-word hint from its target. Replace the phrase and predict the pairs you will see.
Click Run to see the result.
Python message
Done reading?
Mark the lesson as read to move your track progress forward.
Lesson marked as done.
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.
One payment, no auto-renewal · Terms
Progress saved in this browser
Clear your history or open this on your phone, and the marks will be gone. Leave your email and they'll move to your account. No password needed.
Done. moved to your account. You can see your progress on any device. My progress