We can't feed an entire book to the model at once. We have to break the data into small chunks. The model learns by looking at a chunk of text (the Input) and trying to guess the very next word (the Target). We group these chunks into "batches" so the computer can process many of them at the exact same time.
We use a "sliding window" trick. Imagine a tiny window that only lets you see 3 words at a time. We take what's in the window (the Input sequence), and then we slide the window over by exactly one word to get the correct answer (the Target sequence).
Description: A massive, single-file line of numbers representing our entire training book or dataset. Here is our tokenized master sentence: "The quick, brown fox jumps over the lazy dog!"
Description: Two distinct grids of numbers. One grid is the "Inputs" and the other is the "Targets". The grids are sized by (Batch Size, Sequence Length).
Example:
# Inputs (Batch Size = 2, Sequence Length = 3)inputs = tensor([[464, 2068, 11], # "The quick," [2068, 11, 7586]]) # "quick, brown"# Targets (Shifted over by one word!)targets = tensor([[2068, 11, 7586], # "quick, brown" [11, 7586, 21831]]) # ", brown fox"