Set2Set
¶
Bases: Module
Set2Set global pooling from "Order Matters: Sequence to Sequence for Sets" paper.
Starting from \(\mathbf{q}^{*}_0 = \mathbf{0}\), each processing step \(t\) reads the nodes of a graph \(\mathcal{V}_g\) with attention:
where \(\mathbf{q}^{*}_T\) is the output of the layer, with twice the size of the input features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
int
|
Size of input node features |
required |
processing_steps
|
int
|
Number of processing steps \(T\) |
required |
Example:
import mlx.core as mx
from mlx_graphs.nn.pooling.set2set import Set2Set
pool = Set2Set(16, processing_steps=3)
node_features = mx.random.uniform(shape=(5, 16))
batch_indices = mx.array([0, 0, 0, 1, 1])
>>> pool(node_features, batch_indices).shape
(2, 32)
Methods:
| Name | Description |
|---|---|
__call__ |
Pools the node features of each graph with Set2Set. |
Source code in mlx_graphs/nn/pooling/set2set.py
__call__
¶
__call__(
node_features: array,
batch_indices: Optional[array] = None,
num_graphs: Optional[int] = None,
) -> array
Pools the node features of each graph with Set2Set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features
|
array
|
Node features array. |
required |
batch_indices
|
Optional[array]
|
Batch array of shape (node_features.shape[0]), indicating for each node its batch index. If not provided, all nodes belong to a single graph. |
None
|
num_graphs
|
Optional[int]
|
Number of graphs in the batch. By default, inferred as
|
None
|
Returns:
| Type | Description |
|---|---|
array
|
An array of shape (num_graphs, 2 * node_features_dim) with the pooled |
array
|
features of each graph, (1, 2 * node_features_dim) if |
array
|
is None. |
Source code in mlx_graphs/nn/pooling/set2set.py
from mlx_graphs.nn import Set2Set · mlx_graphs/nn/pooling/set2set.py