JumpingKnowledge
¶
JumpingKnowledge(
mode: JumpingKnowledgeModes,
node_features_dim: Optional[int] = None,
num_layers: Optional[int] = None,
)
Bases: Module
Jumping Knowledge layer aggregation from "Representation Learning on Graphs with Jumping Knowledge Networks" paper.
Combines the node embeddings \(\mathbf{x}_i^{(1)}, \ldots, \mathbf{x}_i^{(T)}\) computed by \(T\) successive GNN layers into a single embedding per node, using one of three modes.
Concatenation ("cat"):
Feature-wise max pooling ("max"):
Weighted sum with attention scores \(\alpha_i^{(t)}\) obtained from a
bi-directional LSTM run over the layers ("lstm"):
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
JumpingKnowledgeModes
|
Aggregation mode: |
required |
node_features_dim
|
Optional[int]
|
Size of each layer's node embeddings. Only required
for the |
None
|
num_layers
|
Optional[int]
|
Number of layers to aggregate. Only required for the
|
None
|
Example:
import mlx.core as mx
from mlx_graphs.nn.pooling.jumping_knowledge import JumpingKnowledge
# embeddings of 5 nodes after each of 3 GNN layers
xs = [mx.random.uniform(shape=(5, 16)) for _ in range(3)]
>>> JumpingKnowledge("cat")(xs).shape
(5, 48)
>>> JumpingKnowledge("max")(xs).shape
(5, 16)
>>> JumpingKnowledge("lstm", node_features_dim=16, num_layers=3)(xs).shape
(5, 16)
Methods:
| Name | Description |
|---|---|
__call__ |
Aggregates the layer-wise node embeddings. |
Source code in mlx_graphs/nn/pooling/jumping_knowledge.py
__call__
¶
__call__(node_features_list: List[array]) -> array
Aggregates the layer-wise node embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_list
|
List[array]
|
Node embeddings after each layer, each of shape
|
required |
Returns:
| Type | Description |
|---|---|
array
|
The aggregated node embeddings, of shape |
array
|
|
array
|
|
Source code in mlx_graphs/nn/pooling/jumping_knowledge.py
from mlx_graphs.nn import JumpingKnowledge · mlx_graphs/nn/pooling/jumping_knowledge.py