|
| 1 | +# NBFNet: Neural Bellman-Ford Networks # |
| 2 | + |
| 3 | +This is the official codebase of the paper |
| 4 | + |
| 5 | +[Neural Bellman-Ford Networks: A General Graph Neural Network Framework for Link Prediction][paper] |
| 6 | + |
| 7 | +[Zhaocheng Zhu](https://kiddozhu.github.io), |
| 8 | +[Zuobai Zhang](https://oxer11.github.io), |
| 9 | +[Louis-Pascal Xhonneux](https://github.com/lpxhonneux), |
| 10 | +[Jian Tang](https://jian-tang.com) |
| 11 | + |
| 12 | +[paper]: https://arxiv.org/pdf/2106.06935.pdf |
| 13 | + |
| 14 | +NeurIPS 2021 |
| 15 | + |
| 16 | +## Overview ## |
| 17 | + |
| 18 | +NBFNet is a graph neural network framework inspired by traditional path-based |
| 19 | +methods. It enjoys the advantages of both traditional path-based methods and modern |
| 20 | +graph neural networks, including **generalization in the inductive setting**, |
| 21 | +**interpretability**, **high model capacity** and **scalability**. NBFNet can be |
| 22 | +applied to solve link prediction on both homogeneous graphs and knowledge graphs. |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +This codebase is based on PyTorch and [TorchDrug]. It supports training and inference |
| 27 | +with multiple GPUs or multiple machines. |
| 28 | + |
| 29 | +[TorchDrug]: https://github.com/DeepGraphLearning/torchdrug |
| 30 | + |
| 31 | +## Installation ## |
| 32 | + |
| 33 | +You may install the dependencies via either conda or pip. Generally, NBFNet works |
| 34 | +with Python 3.7/3.8 and PyTorch version >= 1.8.0. |
| 35 | + |
| 36 | +### From Conda ### |
| 37 | + |
| 38 | +```bash |
| 39 | +conda install torchdrug pytorch=1.8.2 cudatoolkit=11.1 -c milagraph -c pytorch-lts -c pyg -c conda-forge |
| 40 | +conda install ogb easydict pyyaml -c conda-forge |
| 41 | +``` |
| 42 | + |
| 43 | +### From Pip ### |
| 44 | + |
| 45 | +```bash |
| 46 | +pip install torch==1.8.2+cu111 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html |
| 47 | +pip install torchdrug |
| 48 | +pip install ogb easydict pyyaml |
| 49 | +``` |
| 50 | + |
| 51 | +## Reproduction ## |
| 52 | + |
| 53 | +To reproduce the results of NBFNet, use the following command. Alternatively, you |
| 54 | +may use `--gpus null` to run NBFNet on a CPU. All the datasets will be automatically |
| 55 | +downloaded in the code. |
| 56 | + |
| 57 | +```bash |
| 58 | +python script/run.py -c config/inductive/wn18rr.yaml --gpus [0] --version v1 |
| 59 | +``` |
| 60 | + |
| 61 | +We provide the hyperparameters for each experiment in configuration files. |
| 62 | +All the configuration files can be found in `config/*/*.yaml`. |
| 63 | + |
| 64 | +For experiments on inductive relation prediction, you need to additionally specify |
| 65 | +the split version with `--version v1`. |
| 66 | + |
| 67 | +To run NBFNet with multiple GPUs or multiple machines, use the following commands |
| 68 | + |
| 69 | +```bash |
| 70 | +python -m torch.distributed.launch --nproc_per_node=4 script/run.py -c config/inductive/wn18rr.yaml --gpus [0,1,2,3] |
| 71 | +``` |
| 72 | + |
| 73 | +```bash |
| 74 | +python -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] |
| 75 | +``` |
| 76 | + |
| 77 | +### Visualize Interpretations on FB15k-237 ### |
| 78 | + |
| 79 | +Once you have models trained on FB15k237, you can visualize the path interpretations |
| 80 | +with the following line. Please replace the checkpoint with your own path. |
| 81 | + |
| 82 | +```bash |
| 83 | +python script/visualize.py -c config/knowledge_graph/fb15k237_visualize.yaml --checkpoint /path/to/nbfnet/experiment/model_epoch_20.pth |
| 84 | +``` |
| 85 | + |
| 86 | +### Evaluate ogbl-biokg ### |
| 87 | + |
| 88 | +Due to the large size of ogbl-biokg, we only evaluate on a small portion of the |
| 89 | +validation set during training. The following line evaluates a model on the full |
| 90 | +validation / test sets of ogbl-biokg. Please replace the checkpoint with your own |
| 91 | +path. |
| 92 | + |
| 93 | +```bash |
| 94 | +python script/run.py -c config/knowledge_graph/ogbl-biokg_test.yaml --checkpoint /path/to/nbfnet/experiment/model_epoch_10.pth |
| 95 | +``` |
| 96 | + |
| 97 | +## Results ## |
| 98 | + |
| 99 | +Here are the results of NBFNet on standard benchmark datasets. All the results are |
| 100 | +obtained with 4 V100 GPUs (32GB). Note results may be slightly different if the |
| 101 | +model is trained with 1 GPU and/or a smaller batch size. |
| 102 | + |
| 103 | +### Knowledge Graph Completion ### |
| 104 | + |
| 105 | +<table> |
| 106 | + <tr> |
| 107 | + <th>Dataset</th> |
| 108 | + <th>MR</th> |
| 109 | + <th>MRR</th> |
| 110 | + <th>HITS@1</th> |
| 111 | + <th>HITS@3</th> |
| 112 | + <th>HITS@10</th> |
| 113 | + </tr> |
| 114 | + <tr> |
| 115 | + <th>FB15k-237</th> |
| 116 | + <td>114</td> |
| 117 | + <td>0.415</td> |
| 118 | + <td>0.321</td> |
| 119 | + <td>0.454</td> |
| 120 | + <td>0.599</td> |
| 121 | + </tr> |
| 122 | + <tr> |
| 123 | + <th>WN18RR</th> |
| 124 | + <td>636</td> |
| 125 | + <td>0.551</td> |
| 126 | + <td>0.497</td> |
| 127 | + <td>0.573</td> |
| 128 | + <td>0.666</td> |
| 129 | + </tr> |
| 130 | + <tr> |
| 131 | + <th>ogbl-biokg</th> |
| 132 | + <td>-</td> |
| 133 | + <td>0.829</td> |
| 134 | + <td>0.768</td> |
| 135 | + <td>0.870</td> |
| 136 | + <td>0.946</td> |
| 137 | + </tr> |
| 138 | +</table> |
| 139 | + |
| 140 | +### Homogeneous Graph Link Prediction ### |
| 141 | + |
| 142 | +<table> |
| 143 | + <tr> |
| 144 | + <th>Dataset</th> |
| 145 | + <th>AUROC</th> |
| 146 | + <th>AP</th> |
| 147 | + </tr> |
| 148 | + <tr> |
| 149 | + <th>Cora</th> |
| 150 | + <td>0.956</td> |
| 151 | + <td>0.962</td> |
| 152 | + </tr> |
| 153 | + <tr> |
| 154 | + <th>CiteSeer</th> |
| 155 | + <td>0.923</td> |
| 156 | + <td>0.936</td> |
| 157 | + </tr> |
| 158 | + <tr> |
| 159 | + <th>PubMed</th> |
| 160 | + <td>0.983</td> |
| 161 | + <td>0.982</td> |
| 162 | + </tr> |
| 163 | +</table> |
| 164 | + |
| 165 | +### Inductive Relation Prediction ### |
| 166 | + |
| 167 | +<table> |
| 168 | + <tr> |
| 169 | + <th rowspan="2">Dataset</th> |
| 170 | + <th colspan="4">HITS@10 (50 sample)</th> |
| 171 | + </tr> |
| 172 | + <tr> |
| 173 | + <th>v1</th> |
| 174 | + <th>v2</th> |
| 175 | + <th>v3</th> |
| 176 | + <th>v4</th> |
| 177 | + </tr> |
| 178 | + <tr> |
| 179 | + <th>FB15k-237</th> |
| 180 | + <td>0.834</td> |
| 181 | + <td>0.949</td> |
| 182 | + <td>0.951</td> |
| 183 | + <td>0.960</td> |
| 184 | + </tr> |
| 185 | + <tr> |
| 186 | + <th>WN18RR</th> |
| 187 | + <td>0.948</td> |
| 188 | + <td>0.905</td> |
| 189 | + <td>0.893</td> |
| 190 | + <td>0.890</td> |
| 191 | + </tr> |
| 192 | +</table> |
| 193 | + |
| 194 | +Frequently Asked Questions |
| 195 | +-------------------------- |
| 196 | + |
| 197 | +1. **The code is stuck at the beginning of epoch 0.** |
| 198 | + |
| 199 | + This is probably because the JIT cache is broken. |
| 200 | + Try `rm -r ~/.cache/torch_extensions/*` and run the code again. |
| 201 | + |
| 202 | +Citation |
| 203 | +-------- |
| 204 | + |
| 205 | +If you find this codebase useful in your research, please cite the following paper. |
| 206 | + |
| 207 | +```bibtex |
| 208 | +@article{zhu2021neural, |
| 209 | + title={Neural Bellman-Ford Networks: A General Graph Neural Network Framework for Link Prediction}, |
| 210 | + author={Zhu, Zhaocheng and Zhang, Zuobai and Xhonneux, Louis-Pascal and Tang, Jian}, |
| 211 | + journal={arXiv preprint arXiv:2106.06935}, |
| 212 | + year={2021} |
| 213 | +} |
| 214 | +``` |
0 commit comments