Skip to content

Version 1.7 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.

HugeGraph-ML

HugeGraph-ML reads graph data from HugeGraph and converts it to DGL graphs for tasks such as node embedding, node classification, and graph classification. Model implementations are under hugegraph-ml/src/hugegraph_ml/models/.

Requirements

  • Python 3.10 or later
  • HugeGraph Server 1.0 or later; 1.5 or later is recommended
  • uv 0.7 or later

Installation

1git clone https://github.com/apache/hugegraph-ai.git
2cd hugegraph-ai
3uv sync --extra ml
4source .venv/bin/activate
5cd hugegraph-ml/src

HugeGraph-ML is a path dependency of the root project but is not a uv workspace member. Select the ml extra at the repository root instead of creating another lock file in the subdirectory.

Implemented Models

The current README lists these models:

ModelsMain purpose
AGNN, APPNP, ARMA, Cluster-GCN, DAGNN, DeeperGCN, GRAND, JKNetNode classification
BGNN, CARE-GNNFraud detection
BGRL, DGI, GRACERepresentation learning
DiffPoolGraph classification
GATNE, P-GNN, SEALLink prediction or network embedding
C&SCorrection and smoothing of predictions

The source also includes GIN for graph classification and MLPClassifier for downstream classification. The model count changes between versions; use src/hugegraph_ml/models/ as the authoritative list.

DGI Node Embedding Example

First import DGL’s Cora dataset into HugeGraph:

1from hugegraph_ml.utils.dgl2hugegraph_utils import import_graph_from_dgl
2
3import_graph_from_dgl("cora")

Read the graph and train DGI:

 1from hugegraph_ml.data.hugegraph2dgl import HugeGraph2DGL
 2from hugegraph_ml.models.dgi import DGI
 3from hugegraph_ml.models.mlp import MLPClassifier
 4from hugegraph_ml.tasks.node_classify import NodeClassify
 5from hugegraph_ml.tasks.node_embed import NodeEmbed
 6
 7hg2d = HugeGraph2DGL()
 8graph = hg2d.convert_graph(vertex_label="CORA_vertex", edge_label="CORA_edge")
 9
10embed_model = DGI(n_in_feats=graph.ndata["feat"].shape[1])
11embed_task = NodeEmbed(graph=graph, model=embed_model)
12embedded_graph = embed_task.train_and_embed(
13    add_self_loop=True, n_epochs=300, patience=30
14)
15
16classifier = MLPClassifier(
17    n_in_feat=embedded_graph.ndata["feat"].shape[1],
18    n_out_feat=embedded_graph.ndata["label"].unique().shape[0],
19)
20classify_task = NodeClassify(graph=embedded_graph, model=classifier)
21classify_task.train(lr=1e-3, n_epochs=400, patience=40)
22print(classify_task.evaluate())

The complete script is hugegraph-ml/src/hugegraph_ml/examples/dgi_example.py.

GRAND Node Classification Example

 1from hugegraph_ml.data.hugegraph2dgl import HugeGraph2DGL
 2from hugegraph_ml.models.grand import GRAND
 3from hugegraph_ml.tasks.node_classify import NodeClassify
 4
 5hg2d = HugeGraph2DGL()
 6graph = hg2d.convert_graph(vertex_label="CORA_vertex", edge_label="CORA_edge")
 7model = GRAND(
 8    n_in_feats=graph.ndata["feat"].shape[1],
 9    n_out_feats=graph.ndata["label"].unique().shape[0],
10)
11task = NodeClassify(graph, model)
12task.train(lr=1e-2, weight_decay=5e-4, n_epochs=2000, patience=100)
13print(task.evaluate())

The complete script is hugegraph-ml/src/hugegraph_ml/examples/grand_example.py.

Troubleshooting

  • Connection failures: check the HugeGraph Server address, port, and credentials.
  • Schema mismatches: the examples use CORA_vertex and CORA_edge; pass the actual labels for your own data.
  • DGL or PyTorch import failures: rerun uv sync --extra ml from the repository root and confirm that Python comes from the root .venv.