Views
No views yet

Extensive knowledge graphs (KGs) have been constructed to facilitate knowledge-driven tasks across various scenarios. However, existing work usually develops separate reasoning models for different KGs, lacking the ability to generalize and transfer knowledge across diverse KGs and reasoning settings. In this paper, we propose a prompt-based KG foundation model via in-context learning, namely KG-ICL, to achieve a universal reasoning ability. Specifically, we introduce a prompt graph centered with a query-related example fact as context to understand the query relation. To encode prompt graphs with the generalization ability to unseen entities and relations in queries, we first propose a unified tokenizer that maps entities and relations in prompt graphs to predefined tokens. Then, we propose two message passing neural networks to perform prompt encoding and KG reasoning, respectively. We conduct evaluation on 43 different KGs in both transductive and inductive settings. Results indicate that the proposed KG-ICL outperforms baselines on most datasets, showcasing its outstanding generalization and universal reasoning capabilities.

pip install torch==2.2.0 --index-url https://download.pytorch.org/whl/cu118
pip install torch-scatter==2.1.2 torch-sparse==0.6.18 torch-geometric==2.4.0 -f https://data.pyg.org/whl/torch-2.2.0+cu118.html
pip install ninja easydict pyyaml tqdmpip uninstall numpy
pip install numpy==1.24.0rspmm kernel. Please make sure your CUDA_HOME variable is set properly to avoid potential compilation errors, egexport CUDA_HOME=/usr/local/cuda-11.8/rspmm kernel is not compiled successfully, please set the hyperparameter use_rspmm to False.unzip datasets.zipcd datasets
chmod +x process.sh
./process.shIf you have any difficulty or question in running code and reproducing experimental results, please email to yncui.nju@gmail.com.
cd src
python pretrain.py./chechpoint/pretrain/ fold.cd shell
chmod +x test.sh
./test.shcd src
python evaluation.py --checkpoint_path ./checkpoint/pretrain/kg_icl_6l --test_dataset_list [dataset_name]cd shell
chmod +x finetune.sh
./finetune.sh| Model | Inductive | Fully-Inductive | Transductive | Average |
|---|---|---|---|---|
| Supervised SOTA | 0.466 | 0.210 | 0.365 | 0.351 |
| ULTRA (pretrain) | 0.513 | 0.352 | 0.329 | 0.396 |
| ULTRA (finetune) | 0.528 | 0.350 | 0.384 | 0.421 |
| KG-ICL-4L (pretrain) | 0.550 | 0.434 | 0.328 | 0.433 |
| KG-ICL-5L (pretrain) | 0.554 | 0.438 | 0.346 | 0.441 |
| KG-ICL-6L (pretrain) | 0.550 | 0.442 | 0.350 | 0.443 |
| KG-ICL-6L (finetune) | 0.592 | 0.444 | 0.413 | 0.481 |
| Model | Inductive | Fully-Inductive | Transductive | Average |
|---|---|---|---|---|
| Supervised SOTA | 0.607 | 0.347 | 0.511 | 0.493 |
| ULTRA (pretrain) | 0.664 | 0.536 | 0.479 | 0.557 |
| ULTRA (finetune) | 0.684 | 0.542 | 0.548 | 0.590 |
| KG-ICL-4L (pretrain) | 0.696 | 0.622 | 0.471 | 0.590 |
| KG-ICL-5L (pretrain) | 0.705 | 0.635 | 0.501 | 0.608 |
| KG-ICL-6L (pretrain) | 0.706 | 0.642 | 0.504 | 0.611 |
| KG-ICL-6L (finetune) | 0.738 | 0.640 | 0.566 | 0.644 |
1@inproceedings{cui2024prompt,
2 title = { A Prompt-based Knowledge Graph Foundation Model for Universal In-Context Reasoning },
3 author = { Cui, Yuanning and
4 Sun, Zequn and
5 Hu, Wei },
6 booktitle = { NeurIPS },
7 year = { 2024 }
8}
9