HeteroDictLinear
¶
Bases: Module
Applies a separate linear layer to each node type.
The layers are initialized like PyG's HeteroDictLinear (and
torch.nn.Linear): weights and biases uniform in
[-1/sqrt(input_dims), 1/sqrt(input_dims)], i.e. mlx.nn.Linear's
default.
Node types in a heterogeneous graph usually have different numbers of
features. This layer maps every node type to the same size, so later layers
(e.g. HeteroConv with SAGEConv(out_dim, out_dim)) can use one
size for all node types.
Node types in x_dict without a layer are left out of the output, and
layers whose node type is missing from x_dict are skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dims
|
dict[str, int]
|
Number of input features per node type, e.g.
|
required |
output_dims
|
int
|
Number of output features, the same for every node type. |
required |
bias
|
bool
|
If set to |
True
|
Example:
import mlx.core as mx
from mlx_graphs.nn import HeteroDictLinear
x_dict = {"author": mx.ones((4, 334)), "paper": mx.ones((5, 4231))}
proj = HeteroDictLinear({"author": 334, "paper": 4231}, 64)
h = proj(x_dict)
>>> {k: v.shape for k, v in h.items()}
{'author': (4, 64), 'paper': (5, 64)}
Methods:
| Name | Description |
|---|---|
__call__ |
Projects the features of every node type that has a layer. |
Source code in mlx_graphs/nn/linear.py
__call__
¶
Projects the features of every node type that has a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_dict
|
dict[str, array]
|
Node features per node type. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, array]
|
Projected node features per node type, each with |
dict[str, array]
|
features. |
Source code in mlx_graphs/nn/linear.py
from mlx_graphs.nn import HeteroDictLinear · mlx_graphs/nn/linear.py