attention_pooling
attention_pooling
¶
Inspired from https://benjaminwarner.dev/2022/07/14/tinkering-with-attention-pooling
AttentionPool2d
¶
Bases: Module
Attention for Learned Aggregation.
Source code in src/versatil/models/layers/pooling/attention_pooling.py
forward
¶
Pool a feature sequence with a learned query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Tensor
|
Spatial feature map or token sequence. |
required |
class_query
|
Tensor
|
Learned query vector used to aggregate the sequence. |
required |
padding_mask
|
Tensor | None
|
Optional token padding mask where |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Aggregated feature tensor of shape |
Source code in src/versatil/models/layers/pooling/attention_pooling.py
LearnedAggregation
¶
LearnedAggregation(feature_dimension, attention_bias=True, feedforward_expand=3, norm=LayerNorm, activation_class=GELU)
Bases: Module
Learned Aggregation from https://arxiv.org/abs/2112.13692.
Source code in src/versatil/models/layers/pooling/attention_pooling.py
forward
¶
Aggregate a token sequence while optionally ignoring padded tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
Tensor
|
Feature tensor to aggregate. |
required |
padding_mask
|
Tensor | None
|
Optional token padding mask where |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Aggregated feature tensor of shape |