Padding adds filler positions to sequences that are too short for a fixed-length convolutional neural network. Together with clipping, it lets an NLP pipeline convert texts of different lengths into equal-size vectors, so patterns can be compared at consistent dimensions. section 7.4.1
Think of padding as extending a short strip of text until it reaches the model’s required length. Convolution and pooling otherwise shorten sequences predictably: a kernel of size K removes K−1 positions before pooling reduces them further. A padding token such as <PAD> fills the unused positions; the token must also exist in the embedding vocabulary. section 7.4.1 section 7.5.1
Pad or clip a sequence
def pad(sequence, pad_value, seq_len): padded = list(sequence)[:seq_len] padded = padded + [pad_value] * (seq_len - len(padded)) return padded This keeps the first seq_len positions and appends the pad value when fewer positions are available. For a CNN configured with seq_len = 40, every token sequence enters the embedding layer with the same length.


















