Input Windows and Batch Creation
Stride is the number of positions by which the input window shifts when the next batch is created from an input dataset.
Why Text Is Split Into Batches
When a language model is trained on a long piece of text, the whole text cannot be fed in all at once. It has to be divided into smaller pieces called batches, and each batch is built from a portion of the input dataset. The way those pieces are chosen determines which words the model sees together and how much of the text repeats from one piece to the next. The idea that controls this behavior is called stride.
Stride is the number of positions by which the input window shifts when the next batch is created from an input dataset. The rest of this article follows a single question: when the window slides forward, how far does it move each time, and what does that do to the batches it produces?
Picturing a Frame Sliding Over Text
Imagine placing a small frame over a passage of text. You read only what falls inside the frame, then slide the frame forward and read the next portion. The frame is the input window. Whatever is visible inside it at one moment is one batch. Each time you slide the frame, you produce a new batch.
Two separate settings control this process. The window size sets how many items a batch contains. The stride sets how far the window moves before the next batch is created. Keeping these two apart in your head is the key to everything that follows: changing one does not automatically change the other.
Tracing a Window Across Tokens
To make the movement concrete, consider a short sequence of ten tokens, numbered by position from 0 to 9. The window size in this trace is 4, so every batch contains four consecutive tokens. Positions are counted from zero, the same way a list is indexed in Python.
0 ['the', 'model', 'reads', 'long']
1 ['model', 'reads', 'long', 'text']
2 ['reads', 'long', 'text', 'in']
3 ['long', 'text', 'in', 'small']
4 ['text', 'in', 'small', 'pieces']
5 ['in', 'small', 'pieces', 'called']
6 ['small', 'pieces', 'called', 'batches']window_sizesets how many items each batch holds- stride is the step between successive start positions
- the range stops early enough that every batch has a full four tokens
Read the output carefully. The first batch starts at position 0. The second starts at position 1, because the stride of 1 moved the window by one position. Each new batch begins exactly one position after the previous batch began, and each batch still holds four tokens. The window size never changed; only the starting point moved.
Where the Window Sits at Each Step
The diagram below shows the same ten positions and highlights the tokens covered by the second batch when the stride is 1. Positions 1 through 4 are inside the window at that step, which is why the second batch is 'model reads long text'.
Notice that the second batch is not a new window of text placed somewhere else. It is the same frame moved one position to the right. Positions 1, 2, and 3 were already inside the first batch, and position 4 is the one new token that enters the frame.
How Stride Sets the Overlap Between Batches
A stride of 1 produces heavy overlap between batches. Each batch shares most of its tokens with the batch before it, and only one new token enters per step. This is the behavior the source describes when it says the second batch repeats part of the first batch and adds one new word at the end.
The overlap is not a fixed property of the window. It is produced by the stride. Hold the window size at 4 and change only the stride, and the amount of shared text changes with it. The comparison below applies three different strides to the same ten tokens, with the same window size each time.
Read each column from top to bottom. In the stride 1 column, the second batch repeats three tokens from the first. In the stride 2 column, the second batch repeats only two. In the stride 4 column, the second batch shares nothing with the first, because the window jumped forward by four positions and each new batch begins exactly where the previous one ended. The window size was 4 in every column. Only the stride changed, and the overlap changed with it.
Following the Order of Operations
It helps to see batch creation as a fixed sequence of steps. The stride shift is applied between emitting one batch and emitting the next, so it controls where the next batch starts without changing how many items that batch contains.
Predicting the Second Batch's Start
What do you think happens?
With the ten-token sequence and a window size of 4, a stride of 2 is used. Where does the second batch start?
Reveal answer
Position 2
The first batch starts at position 0. Shifting the window by a stride of 2 moves its start to position 2, so the second batch covers positions 2 through 5: reads, long, text, in.
Stride Larger Than the Window
The source notes that setting the stride equal to the window size can prevent overlap, because each new window begins exactly where the previous one ended. A stride larger than the window size goes one step further: the window jumps past positions that no batch has covered. Using the same ten tokens, a window size of 4, and a stride of 5, the first batch covers positions 0 through 3 and the second covers positions 5 through 8. The token at position 4, 'text', belongs to neither batch.
Common Misunderstandings About Stride
Common mistake Treating stride and window size as the same setting
What it looks likeAssuming that a larger window automatically means less overlap, because the batches are bigger.
Why it failsThe window size sets how many items a batch contains, and the stride sets how far the window moves. Changing one does not change the other.
Do this insteadAsk two separate questions: how many items does each batch hold, and how far does the window shift before the next batch?
Common mistake Believing that a stride of 1 is the same as having no overlap
What it looks likeExpecting batch 2 to contain only new tokens when the stride is 1.
Why it failsA stride of 1 shifts the window by one position, so the batch keeps most of its previous tokens. The source describes this as heavy overlap.
Do this insteadWith a stride of 1 and a window of 4, three of the four tokens in each new batch repeat from the previous batch.
Common mistake Thinking the window moves by a number of batches rather than positions
What it looks likeReading a stride of 4 as skipping four batches ahead.
Why it failsThe source defines stride as the number of positions the window shifts, not a count of batches.
Do this insteadA stride of 4 moves the starting position by four tokens, so the next batch begins four positions later in the sequence.
Common mistake Assuming a larger stride always produces better batches; the stride only changes which tokens repeat and which are skipped, and the right value depends on the task.
Checking Your Understanding of Stride
Using the ten-token sequence from this article, a window size of 4, and a stride of 3, list the tokens in the first two batches and state how many tokens they share.
Hints
- The first batch starts at position 0 and covers positions 0 through 3.
- Add the stride to the starting position to find where the second batch begins.
- Count positions that appear in both batches.
Key Takeaways
- Stride is the number of positions by which the input window shifts when the next batch is created from an input dataset.
- The window size sets how many items a batch contains, and the stride sets how far the window moves; these are separate settings.
- A stride of 1 produces heavy overlap between consecutive batches, while a stride equal to the window size can prevent overlap.
- A stride larger than the window size leaves positions that no batch covers, so the overlap comparison depends on how the stride relates to the window size.