ToHeteroModel
¶
ToHeteroModel(
module: Module,
metadata: Metadata,
aggr: str = "sum",
input_map: Optional[dict[str, str]] = None,
input_dims: Optional[dict[NodeType, int]] = None,
num_bases: Optional[int] = None,
in_channels: Optional[dict[str, int]] = None,
)
Bases: Module
Heterogeneous version of a homogeneous model, returned by
to_hetero().
It is called like the original model, with a dict per node-level input
(keyed by node type) and per edge-level input (keyed by edge type) instead
of an array, e.g. model(edge_index_dict, node_features_dict) for a
model called as model(edge_index, node_features). Node-level outputs
are returned as dicts keyed by node type (edge-level outputs keyed by edge
type).
The rewritten copy of the original model is stored as self.module;
the copy of a layer used for a type is in the layer's dispatcher, under
the type's name ("author" or "author__writes__paper"), e.g.
model.module.convs[0]["author__writes__paper"], or via
model.module.convs[0].module_for(("author", "writes", "paper")).
Methods:
| Name | Description |
|---|---|
__call__ |
Runs the model on dict-valued inputs. |
Attributes:
| Name | Type | Description |
|---|---|---|
metadata |
Metadata
|
The |
Source code in mlx_graphs/nn/to_hetero.py
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 | |
__call__
¶
Runs the model on dict-valued inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
The arguments of the original model, with node-level arrays replaced by dicts keyed by node type and edge-level arrays by dicts keyed by edge type. Other values are passed unchanged. |
()
|
|
**kwargs
|
Keyword arguments, likewise. |
{}
|
Returns:
| Type | Description |
|---|---|
|
The output of the original model, with node-level arrays replaced |
|
|
by dicts keyed by node type. |
Source code in mlx_graphs/nn/to_hetero.py
from mlx_graphs.nn import ToHeteroModel · mlx_graphs/nn/to_hetero.py