SetTransformerAggregation
¶
SetTransformerAggregation(
channels: int,
num_seed_points: int = 1,
num_encoder_blocks: int = 1,
num_decoder_blocks: int = 1,
heads: int = 1,
concat: bool = True,
layer_norm: bool = False,
dropout: float = 0.0,
)
Bases: Aggregation
Aggregation with a Set Transformer, from the "Set Transformer: A Framework for Attention-based Permutation-Invariant Neural Networks" paper, as PyG's
SetTransformerAggregation.
The elements of each set are encoded with num_encoder_blocks Set
Attention Blocks (SAB), pooled onto num_seed_points learnable seeds by
Pooling by Multihead Attention (PMA), and decoded with
num_decoder_blocks SABs. The seeds of empty sets attend to nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
int
|
Size of each input sample. |
required |
num_seed_points
|
int
|
Number of seed points. Default: |
1
|
num_encoder_blocks
|
int
|
Number of SABs in the encoder. Default: |
1
|
num_decoder_blocks
|
int
|
Number of SABs in the decoder. Default: |
1
|
heads
|
int
|
Number of attention heads. Default: |
1
|
concat
|
bool
|
If |
True
|
layer_norm
|
bool
|
Whether to apply layer normalization. Default: |
False
|
dropout
|
float
|
Dropout probability of the attention weights. Default: |
0.0
|
Example:
import mlx.core as mx
from mlx_graphs.nn.aggr import SetTransformerAggregation
aggr = SetTransformerAggregation(16, num_seed_points=2, heads=4)
x = mx.random.normal((6, 16))
index = mx.array([0, 0, 1, 1, 1, 2])
>>> aggr(x, index).shape
(3, 32)
Methods:
| Name | Description |
|---|---|
aggregate |
Aggregates |
Source code in mlx_graphs/nn/aggr/set_transformer.py
aggregate
¶
aggregate(
x: array,
index: array,
dim_size: int,
max_num_elements: Optional[int] = None,
**kwargs,
) -> array
Aggregates x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array
|
Array of shape |
required |
index
|
array
|
Set of each element. |
required |
dim_size
|
int
|
Number of sets. |
required |
max_num_elements
|
Optional[int]
|
Only the first |
None
|
Source code in mlx_graphs/nn/aggr/set_transformer.py
from mlx_graphs.nn.aggr import SetTransformerAggregation · mlx_graphs/nn/aggr/set_transformer.py