liveBook · Manning

Adaptive pooling

As explained in Inside Deep Learning: Math, Algorithms, Models

A pooling method that adjusts its pooling region to produce a requested output size, used here to collapse the time dimension.

Adaptive pooling produces a requested output size instead of shrinking by a fixed factor. It changes the pooling region to match the input, making variable-sized inputs produce consistent tensors. section 8.4.1

For a 3 × 3 target, a 6 × 6 input pools over 2 × 2 regions, while a 12 × 12 input pools over 4 × 4 regions. In PyTorch, nn.AdaptiveMaxPool2d((7,7)) standardizes each RoI before flattening and classification. section 8.4.1

Common shape transformations include:

  • Average embeddings with nn.AdaptiveAvgPool2d((1,D)): (B,T,D) becomes (B,1,D), then flattening gives (B,D). The target leaves the feature dimension unchanged and collapses time. section 12.2
  • After 1D convolutions, nn.AdaptiveMaxPool1d(1) changes (B,D′,T′) to (B,D′,1), allowing a linear classifier to receive a consistent shape. section 12.3
  • Prefer adaptive max pooling for padded variable-length sequences when padding produces zero activations that should not become the selected representation. section 12.3

Collapsing sequence time

Given embeddings shaped (B,T,D), apply nn.AdaptiveAvgPool2d((1,D)), then nn.Flatten(), producing (B,D) for subsequent fully connected layers. This works even when T changes between batches, but averaging discards temporal order. section 12.2

How Inside Deep Learning: Math, Algorithms, Models covers it

How deep it goes
Explains target-size adjustment, tensor shapes, pooling choices, and PyTorch implementations, but does not derive pooling-bin boundaries.
Examples
Uses 3 × 3 image outputs, 7 × 7 RoI features, pooled embeddings, and adaptive max pooling after sequence convolutions.
What it assumes
Assumes tensor-shape and pooling familiarity while demonstrating the required reshaping, permutation, flattening, and classifier steps.
What you can do after
Apply it via PyTorch pooling modules to standardize variable-sized image regions or sequence representations before classification.
How it connects
Connects adaptive pooling to RoI pooling, embeddings, 1D convolutional neural networks, padding, and linear layers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Inside Deep Learning: Math, Algorithms, Models. The section links point to the parts of the book it draws on.