GraphMultisetTransformer
¶
GraphMultisetTransformer(
channels: int,
k: int,
num_encoder_blocks: int = 1,
heads: int = 1,
layer_norm: bool = False,
dropout: float = 0.0,
)
Bases: Aggregation
The Graph Multiset Transformer pooling operator from the "Accurate Learning of Graph Representations with Graph Multiset Pooling" paper, as PyG's
GraphMultisetTransformer.
The elements of each set (e.g. node embeddings computed by a GNN) are
pooled onto k seed points by Pooling by Multihead Attention (PMA),
processed by num_encoder_blocks Set Attention Blocks (SAB), and
pooled again onto a single seed point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
int
|
Size of each input sample. |
required |
k
|
int
|
Number of seed points of the first PMA. |
required |
num_encoder_blocks
|
int
|
Number of SABs between the two PMAs. Default: |
1
|
heads
|
int
|
Number of attention heads. Default: |
1
|
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 GraphMultisetTransformer
aggr = GraphMultisetTransformer(16, k=4, heads=2)
x = mx.random.normal((6, 16))
batch_indices = mx.array([0, 0, 1, 1, 1, 2])
>>> aggr(x, batch_indices).shape
(3, 16)
References
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
|
Returns:
| Type | Description |
|---|---|
array
|
An array of shape |
Source code in mlx_graphs/nn/aggr/set_transformer.py
from mlx_graphs.nn.aggr import GraphMultisetTransformer · mlx_graphs/nn/aggr/set_transformer.py