GATv2Conv
¶
GATv2Conv(
node_features_dim: Union[int, Tuple[int, int]],
out_features_dim: int,
heads: int = 1,
concat: bool = True,
bias: bool = True,
negative_slope: float = 0.2,
dropout: float = 0.0,
edge_features_dim: Optional[int] = None,
add_self_loops: bool = True,
fill_value: SelfLoopFillValue = "mean",
**kwargs,
)
Bases: MessagePassing
Graph Attention Network convolution layer with dynamic attention.
Modification of GATConv based off of "How Attentive are Graph Attention Networks?" paper.
The layer also works on bipartite graphs (e.g. author -> paper in a
heterogeneous graph): pass node_features as a (src_features,
dst_features) tuple and, if the two sides have different feature
sizes, node_features_dim as a (src_dim, dst_dim) tuple. The output
has one row per destination node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
Union[int, Tuple[int, int]]
|
Size of input node features, or a
|
required |
out_features_dim
|
int
|
Size of output node embeddings |
required |
heads
|
int
|
Number of attention heads |
1
|
concat
|
bool
|
Whether to use concat of heads or mean reduction |
True
|
bias
|
bool
|
Whether to use bias in the node projection |
True
|
negative_slope
|
float
|
Slope for the leaky relu |
0.2
|
dropout
|
float
|
Probability p for dropout |
0.0
|
edge_features_dim
|
Optional[int]
|
Size of edge features |
None
|
add_self_loops
|
bool
|
Whether to add a self-loop to every node, as in PyG
(existing self-loops are replaced by it). Not supported on
bipartite |
True
|
fill_value
|
SelfLoopFillValue
|
Edge features of the added self-loops, if
|
'mean'
|
Example:
import mlx.core as mx
from mlx_graphs.nn import GATv2Conv
conv = GATv2Conv(16, 32, heads=2, concat=True)
edge_index = mx.array([[0, 1, 2, 3, 4], [0, 0, 1, 1, 3]])
node_features = mx.random.uniform(low=0, high=1, shape=(5, 16))
h = conv(edge_index, node_features)
>>> h.shape
(5, 64)
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the forward pass of GATConv. |
Source code in mlx_graphs/nn/conv/gatv2_conv.py
__call__
¶
__call__(
edge_index: array,
node_features: Union[array, Tuple[array, array]],
edge_features: Optional[array] = None,
) -> array
Computes the forward pass of GATConv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
input edge index of shape |
required |
node_features
|
Union[array, Tuple[array, array]]
|
input node features, or a |
required |
edge_features
|
Optional[array]
|
edge features |
None
|
Returns:
| Type | Description |
|---|---|
array
|
computed node embeddings |
Source code in mlx_graphs/nn/conv/gatv2_conv.py
from mlx_graphs.nn import GATv2Conv · mlx_graphs/nn/conv/gatv2_conv.py