liveBook · Manning

Stride

As explained in Natural Language Processing in Action, Second Edition

A stride is the number of input positions by which a convolution kernel moves between successive applications.

A stride is the number of input positions a convolution kernel skips between successive applications. With stride 1, a two-token kernel checks every adjacent pair; with stride 2, it checks alternating positions. section 7.2.2

Stride changes both coverage and output length:

  • Stride 1 preserves the most opportunities to detect a pattern and is the common choice for kernels of size two or more. section 7.2.2
  • Stride 2 reduces the number of examined spans, so some matches can be skipped; in the paired-word example, it detected both matches only by chance. section 7.2.2
  • Larger strides shorten the convolution output sequence; the amount of shortening depends on stride, kernel size, padding, and dilation. section 7.5.1

Checking part-of-speech pairs

A two-token stencil over “right ones in the right order” finds matches at spans 0–1 and 4–5 with stride 1. Moving by stride 2 inspects spans 0–1, 2–3, and 4–5, omitting the intervening pairs. section 7.2.2

def calc_conv_out_seq_len(seq_len, kernel_len,
                          stride=1, dilation=1, padding=0):
    """
    L_out =     (L_in + 2 * padding - dilation * (kernel_size - 1) - 1)
            1 + _______________________________________________________
                                        stride
    """
    return (
        1 + (seq_len +
             2 * padding - dilation * (kernel_len - 1) - 1
            ) //
        stride
        )

Use the convolution output-length calculation to inspect how stride changes the sequence shape. section 7.5.1

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains stride through adjacent-token experiments and output-length formulas, but stops short of broader optimization guidance.
Examples
Demonstrates stride with part-of-speech bigrams and PyTorch Conv1d configurations using stride 1.
What it assumes
Assumes familiarity with convolution kernels and token sequences while explaining stride through concrete two-token patterns.
What you can do after
Apply stride by selecting a scan step and calculating the resulting convolution sequence length.
How it connects
Connects stride with convolution, kernels, padding, dilation, pooling, and word embeddings.

Also explained in

Compare how 8 books explain stride →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.