liveBook · Manning

Input-target pair

As explained in Build a Large Language Model (From Scratch)

A paired training example consisting of an input sequence and the corresponding target sequence shifted for next-token prediction.

An input-target pair is a tokenized training example for next-token prediction: the target sequence is the input sequence shifted one position forward. The input shows the context; each target gives the token the model should predict next. section 2.6

A sliding-window dataset constructs pairs as follows:

  • Tokenize the text into token IDs, then select an input window of length max_length. section 2.6

Four-token window

For x = [290, 4920, 2241, 287], the target is y = [4920, 2241, 287, 257]. The sequence therefore trains four predictions: [290] → 4920, [290, 4920] → 2241, [290, 4920, 2241] → 287, and the full window → 257.

How Build a Large Language Model (From Scratch) covers it

How deep it goes
Explains shifted slices, tensor shapes, batching, stride, overlap, and DataLoader construction without covering loss computation or optimization.
Examples
Uses token-ID windows, decoded text predictions, tensor batches, and stride-one versus nonoverlapping windows.
What it assumes
Assumes token IDs and tokenization basics, while establishing how sliding windows turn tokenized text into training data.
What you can do after
Build it from scratch using a PyTorch Dataset and DataLoader that return batched input and target tensors.
How it connects
Connects tokenization, BPE, sliding windows, next-token prediction, PyTorch tensors, and DataLoader batching.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Large Language Model (From Scratch). The section links point to the parts of the book it draws on.