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']
|
|
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. |