Skip to content

nexuml_library.layers.feature.pooling

nexuml_library.layers.feature.pooling

Pooling layers for token/sequence aggregation.

TokenPool

Bases: LayerDefinition

Pool tokens along a specified dimension.

Attributes:

Name Type Description
dim int

Dimension to pool over (negative indexing supported, e.g. -2 for time).

pooling_type Literal['mean', 'max', 'std', 'mean_std', 'cls', 'multilayer']
  • "mean": average over the pool dim
  • "max": max over the pool dim
  • "std": standard deviation over the pool dim
  • "mean_std" (alias: "mean+std", "mean_plus_std"): concatenate mean and std along the last axis
  • "cls": select the first index along the pool dim (CLS-style)
  • "multilayer": when the input is multi-layer hidden states (e.g. [B, L, N, D] from an encoder that exposes all hidden states), concatenate per-layer mean+std along the last axis, preserving the per-layer ordering.
remove_dim bool

Whether to squeeze the pooled dimension.

skip_first bool

Skip the first token (e.g. CLS token) before pooling.

AttentionPool

Bases: LayerDefinition

Learned attention pooling using a query token.

Attributes:

Name Type Description
dim int

Token dimension to pool over.

remove_dim bool

Whether to remove the pooled dimension.

n_heads int

Number of attention heads.

AttentiveStatisticsPool

Bases: LayerDefinition

Attentive Statistics Pooling (Okabe et al., 2018).

Computes attention-weighted mean and std, then projects to input dim.

Attributes:

Name Type Description
dim int

Dimension to pool over.

remove_dim bool

Whether to remove the pooled dimension.

hidden_dim int

Hidden dimension for the attention MLP.