{"id":28700507,"url":"https://github.com/deepgraphlearning/nbfnet","last_synced_at":"2025-06-14T11:08:10.912Z","repository":{"id":41273834,"uuid":"430829075","full_name":"DeepGraphLearning/NBFNet","owner":"DeepGraphLearning","description":"Official implementation of Neural Bellman-Ford Networks (NeurIPS 2021)","archived":false,"fork":false,"pushed_at":"2023-08-02T21:49:24.000Z","size":270,"stargazers_count":198,"open_issues_count":7,"forks_count":30,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-01-06T09:03:24.521Z","etag":null,"topics":["graph-neural-networks","knowledge-graph","link-prediction","reasoning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DeepGraphLearning.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-22T18:53:27.000Z","updated_at":"2024-12-17T07:34:29.000Z","dependencies_parsed_at":"2023-01-21T22:04:00.913Z","dependency_job_id":null,"html_url":"https://github.com/DeepGraphLearning/NBFNet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DeepGraphLearning/NBFNet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepGraphLearning%2FNBFNet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepGraphLearning%2FNBFNet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepGraphLearning%2FNBFNet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepGraphLearning%2FNBFNet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeepGraphLearning","download_url":"https://codeload.github.com/DeepGraphLearning/NBFNet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepGraphLearning%2FNBFNet/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259804865,"owners_count":22913903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graph-neural-networks","knowledge-graph","link-prediction","reasoning"],"created_at":"2025-06-14T11:08:07.823Z","updated_at":"2025-06-14T11:08:10.896Z","avatar_url":"https://github.com/DeepGraphLearning.png","language":"Python","readme":"# NBFNet: Neural Bellman-Ford Networks #\n\nThis is the official codebase of the paper\n\n[Neural Bellman-Ford Networks: A General Graph Neural Network Framework for Link Prediction][paper]\n\n[Zhaocheng Zhu](https://kiddozhu.github.io),\n[Zuobai Zhang](https://oxer11.github.io),\n[Louis-Pascal Xhonneux](https://github.com/lpxhonneux),\n[Jian Tang](https://jian-tang.com)\n\n[paper]: https://arxiv.org/pdf/2106.06935.pdf\n\nA PyG re-implementation of NBFNet can be found [here](https://github.com/KiddoZhu/NBFNet-PyG).\n\n## Overview ##\n\nNBFNet is a graph neural network framework inspired by traditional path-based\nmethods. It enjoys the advantages of both traditional path-based methods and modern\ngraph neural networks, including **generalization in the inductive setting**,\n**interpretability**, **high model capacity** and **scalability**. NBFNet can be\napplied to solve link prediction on both homogeneous graphs and knowledge graphs.\n\n![NBFNet](asset/nbfnet.svg)\n\nThis codebase is based on PyTorch and [TorchDrug]. It supports training and inference\nwith multiple GPUs or multiple machines.\n\n[TorchDrug]: https://github.com/DeepGraphLearning/torchdrug\n\n## Installation ##\n\nYou may install the dependencies via either conda or pip. Generally, NBFNet works\nwith Python 3.7/3.8 and PyTorch version \u003e= 1.8.0.\n\n### From Conda ###\n\n```bash\nconda install torchdrug pytorch=1.8.2 cudatoolkit=11.1 -c milagraph -c pytorch-lts -c pyg -c conda-forge\nconda install ogb easydict pyyaml -c conda-forge\n```\n\n### From Pip ###\n\n```bash\npip install torch==1.8.2+cu111 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html\npip install torchdrug\npip install ogb easydict pyyaml\n```\n\n## Reproduction ##\n\nTo reproduce the results of NBFNet, use the following command. Alternatively, you\nmay use `--gpus null` to run NBFNet on a CPU. All the datasets will be automatically\ndownloaded in the code.\n\n```bash\npython script/run.py -c config/inductive/wn18rr.yaml --gpus [0] --version v1\n```\n\nWe provide the hyperparameters for each experiment in configuration files.\nAll the configuration files can be found in `config/*/*.yaml`.\n\nFor experiments on inductive relation prediction, you need to additionally specify\nthe split version with `--version v1`.\n\nTo run NBFNet with multiple GPUs or multiple machines, use the following commands\n\n```bash\npython -m torch.distributed.launch --nproc_per_node=4 script/run.py -c config/inductive/wn18rr.yaml --gpus [0,1,2,3]\n```\n\n```bash\npython -m torch.distributed.launch --nnodes=4 --nproc_per_node=4 script/run.py -c config/inductive/wn18rr.yaml --gpus [0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3]\n```\n\n### Visualize Interpretations on FB15k-237 ###\n\nOnce you have models trained on FB15k237, you can visualize the path interpretations\nwith the following line. Please replace the checkpoint with your own path.\n\n```bash\npython script/visualize.py -c config/knowledge_graph/fb15k237_visualize.yaml --checkpoint /path/to/nbfnet/experiment/model_epoch_20.pth\n```\n\n### Evaluate ogbl-biokg ###\n\nDue to the large size of ogbl-biokg, we only evaluate on a small portion of the\nvalidation set during training. The following line evaluates a model on the full\nvalidation / test sets of ogbl-biokg. Please replace the checkpoint with your own\npath.\n\n```bash\npython script/run.py -c config/knowledge_graph/ogbl-biokg_test.yaml --checkpoint /path/to/nbfnet/experiment/model_epoch_10.pth\n```\n\n## Results ##\n\nHere are the results of NBFNet on standard benchmark datasets. All the results are\nobtained with 4 V100 GPUs (32GB). Note results may be slightly different if the\nmodel is trained with 1 GPU and/or a smaller batch size.\n\n### Knowledge Graph Completion ###\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003cth\u003eDataset\u003c/th\u003e\n        \u003cth\u003eMR\u003c/th\u003e\n        \u003cth\u003eMRR\u003c/th\u003e\n        \u003cth\u003eHITS@1\u003c/th\u003e\n        \u003cth\u003eHITS@3\u003c/th\u003e\n        \u003cth\u003eHITS@10\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003cth\u003eFB15k-237\u003c/th\u003e\n        \u003ctd\u003e114\u003c/td\u003e\n        \u003ctd\u003e0.415\u003c/td\u003e\n        \u003ctd\u003e0.321\u003c/td\u003e\n        \u003ctd\u003e0.454\u003c/td\u003e\n        \u003ctd\u003e0.599\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003cth\u003eWN18RR\u003c/th\u003e\n        \u003ctd\u003e636\u003c/td\u003e\n        \u003ctd\u003e0.551\u003c/td\u003e\n        \u003ctd\u003e0.497\u003c/td\u003e\n        \u003ctd\u003e0.573\u003c/td\u003e\n        \u003ctd\u003e0.666\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003cth\u003eogbl-biokg\u003c/th\u003e\n        \u003ctd\u003e-\u003c/td\u003e\n        \u003ctd\u003e0.829\u003c/td\u003e\n        \u003ctd\u003e0.768\u003c/td\u003e\n        \u003ctd\u003e0.870\u003c/td\u003e\n        \u003ctd\u003e0.946\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\n### Homogeneous Graph Link Prediction ###\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003cth\u003eDataset\u003c/th\u003e\n        \u003cth\u003eAUROC\u003c/th\u003e\n        \u003cth\u003eAP\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003cth\u003eCora\u003c/th\u003e\n        \u003ctd\u003e0.956\u003c/td\u003e\n        \u003ctd\u003e0.962\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003cth\u003eCiteSeer\u003c/th\u003e\n        \u003ctd\u003e0.923\u003c/td\u003e\n        \u003ctd\u003e0.936\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003cth\u003ePubMed\u003c/th\u003e\n        \u003ctd\u003e0.983\u003c/td\u003e\n        \u003ctd\u003e0.982\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\n### Inductive Relation Prediction ###\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003cth rowspan=\"2\"\u003eDataset\u003c/th\u003e\n        \u003cth colspan=\"4\"\u003eHITS@10 (50 sample)\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003cth\u003ev1\u003c/th\u003e\n        \u003cth\u003ev2\u003c/th\u003e\n        \u003cth\u003ev3\u003c/th\u003e\n        \u003cth\u003ev4\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003cth\u003eFB15k-237\u003c/th\u003e\n        \u003ctd\u003e0.834\u003c/td\u003e\n        \u003ctd\u003e0.949\u003c/td\u003e\n        \u003ctd\u003e0.951\u003c/td\u003e\n        \u003ctd\u003e0.960\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003cth\u003eWN18RR\u003c/th\u003e\n        \u003ctd\u003e0.948\u003c/td\u003e\n        \u003ctd\u003e0.905\u003c/td\u003e\n        \u003ctd\u003e0.893\u003c/td\u003e\n        \u003ctd\u003e0.890\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\nFrequently Asked Questions\n--------------------------\n\n1. **The code is stuck at the beginning of epoch 0.**\n\n   This is probably because the JIT cache is broken.\n   Try `rm -r ~/.cache/torch_extensions/*` and run the code again.\n\nCitation\n--------\n\nIf you find this codebase useful in your research, please cite the following paper.\n\n```bibtex\n@article{zhu2021neural,\n  title={Neural bellman-ford networks: A general graph neural network framework for link prediction},\n  author={Zhu, Zhaocheng and Zhang, Zuobai and Xhonneux, Louis-Pascal and Tang, Jian},\n  journal={Advances in Neural Information Processing Systems},\n  volume={34},\n  year={2021}\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepgraphlearning%2Fnbfnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepgraphlearning%2Fnbfnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepgraphlearning%2Fnbfnet/lists"}