attention
attention
¶
AttentionFusion
¶
AttentionFusion(input_features, output_name, hidden_dimension, input_feature_query=None, number_of_heads=8, dropout=0.1, use_residual=True, use_norm=True)
Bases: SequentialFusion
Combines sequence features by projecting them into a shared embedding space and then applying cross-attention to them. If only one feature is provided, it is returned as-is after projection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
list[str]
|
List of feature names to fuse. |
required |
output_name
|
str
|
Name of the output fused feature. |
required |
hidden_dimension
|
int
|
Dimension to project each input feature to before fusion. |
required |
input_feature_query
|
str | None
|
Name of the feature to use as query in cross-attention. If None, uses the first feature. |
None
|
number_of_heads
|
int
|
Number of attention heads. |
8
|
dropout
|
float
|
Dropout rate for attention weights. |
0.1
|
use_residual
|
bool
|
Whether to add a residual connection from the input to the output. |
True
|
use_norm
|
bool
|
Whether to apply layer normalization after projection and before fusion. |
True
|
Source code in src/versatil/models/encoding/fusion/attention.py
forward
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list[Tensor]
|
List of features shaped [B, T, S, D_i] (sequential), [B, T, D_i] (flat with time), or [B, D_i] (flat). |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Fused features [B, T, hidden_dimension] or [B, hidden_dimension] |
Source code in src/versatil/models/encoding/fusion/attention.py
get_output_specification
¶
Get output specification.