• Stars
    star
    350
  • Rank 121,229 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 3 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[Tool] For Knowledge Graph Representation Learning

Website Pypi Pypi Documentation

An Open Source Library for Diverse Representation Learning of Knowledge Graphs

English | δΈ­ζ–‡

NeuralKG is a python-based library for diverse representation learning of knowledge graphs implementing Conventional KGEs, GNN-based KGEs, and Rule-based KGEs. We provide comprehensive documents for beginners and an online website to organize an open and shared KG representation learning community.


Table of Contents


πŸ˜ƒWhat's New


Overview

NeuralKG is built on PyTorch Lightning. It provides a general workflow of diverse representation learning on KGs and is highly modularized, supporting three series of KGEs. It has the following features:

  • Support diverse types of methods. NeuralKG, as a library for diverse representation learning of KGs, provides implementations of three series of KGE methods, including Conventional KGEs, GNN-based KGEs, and Rule-based KGEs.

  • Support easy customization. NeuralKG contains fine-grained decoupled modules that are commonly used in different KGEs, including KG Data Preprocessing, Sampler for negative sampling, Monitor for hyperparameter tuning, Trainer covering the training, and model validation.

  • long-term technical maintenance. The core team of NeuralKG will offer long-term technical maintenance. Other developers are welcome to pull requests.


Demo

There is a demonstration of NeuralKG.


Implemented KGEs

Components Models
KGEModel TransE, TransH, TransR, ComplEx, DistMult, RotatE, ConvE, BoxE, CrossE, SimplE, HAKE, PairRE, DualE
GNNModel RGCN, KBAT, CompGCN, XTransE, SEGNN
RuleModel ComplEx-NNE+AER, RUGE, IterE

Quick Start

Installation

Step1 Create a virtual environment using Anaconda and enter it

conda create -n neuralkg python=3.8
conda activate neuralkg

Step2 Install the appropriate PyTorch and DGL according to your cuda version

Here we give a sample installation based on cuda == 11.1

  • Install PyTorch
pip install torch==1.9.1+cu111 -f https://download.pytorch.org/whl/torch_stable.html
  • Install DGL
pip install dgl-cu111 dglgo -f https://data.dgl.ai/wheels/repo.html

Step3 Install package

  • From Pypi
pip install neuralkg
  • From Source
git clone https://github.com/zjukg/NeuralKG.git
cd NeuralKG
python setup.py install

Training

# Use bash script
sh ./scripts/your-sh

# Use config
python main.py --load_config --config_path <your-config>

Evaluation

python main.py --test_only --checkpoint_dir <your-model-path>

Hyperparameter Tuning

NeuralKG utilizes Weights&Biases supporting various forms of hyperparameter optimization such as grid search, Random search, and Bayesian optimization. The search type and search space are specified in the configuration file in the format "*.yaml" to perform hyperparameter optimization.

The following config file displays hyperparameter optimization of the TransE on the FB15K-237 dataset using bayes search:

command:
  - ${env}
  - ${interpreter}
  - ${program}
  - ${args}
program: main.py
method: bayes
metric:
  goal: maximize
  name: Eval|hits@10
parameters:
  dataset_name:
    value: FB15K237
  model_name:
    value: TransE
  loss_name:
    values: [Adv_Loss, Margin_Loss]
  train_sampler_class:
    values: [UniSampler, BernSampler]
  emb_dim:
    values: [400, 600]
  lr:
    values: [1e-4, 5e-5, 1e-6]
  train_bs:
    values: [1024, 512]
  num_neg:
    values: [128, 256]

Reproduced Results

There are some reproduced model results on FB15K-237 dataset using NeuralKG as below. See more results in here

Method MRR Hit@1 Hit@3 Hit@10
TransE 0.32 0.23 0.36 0.51
TransR 0.23 0.16 0.26 0.38
TransH 0.31 0.2 0.34 0.50
DistMult 0.30 0.22 0.33 0.48
ComplEx 0.25 0.17 0.27 0.40
SimplE 0.16 0.09 0.17 0.29
ConvE 0.32 0.23 0.35 0.50
RotatE 0.33 0.23 0.37 0.53
BoxE 0.32 0.22 0.36 0.52
HAKE 0.34 0.24 0.38 0.54
PairRE 0.35 0.25 0.38 0.54
DualE 0.33 0.24 0.36 0.52
XTransE 0.29 0.19 0.31 0.45
RGCN 0.25 0.16 0.27 0.43
KBAT* 0.28 0.18 0.31 0.46
CompGCN 0.34 0.25 0.38 0.52
SEGNN 0.36 0.27 0.39 0.54
IterE 0.26 0.19 0.29 0.41

*:There is a label leakage error in KBAT, so the corrected result is poor compared with the paper result. Details in deepakn97/relationPrediction#28


Notebook Guide

πŸ˜ƒWe use colab to provide some notebooks to help users use our library.

Colab Notebook


Detailed Documentation

https://zjukg.github.io/NeuralKG/neuralkg.html


Citation

Please cite our paper if you use NeuralKG in your work

@inproceedings{neuralkg,
  author    = {Wen Zhang and
               Xiangnan Chen and
               Zhen Yao and
               Mingyang Chen and
               Yushan Zhu and
               Hongtao Yu and
               Yufeng Huang and
               Yajing Xu and
               Ningyu Zhang and
               Zezhong Xu and
               Zonggang Yuan and
               Feiyu Xiong and
               Huajun Chen},
  title     = {NeuralKG: An Open Source Library for Diverse Representation Learning
               of Knowledge Graphs},
  booktitle = {{SIGIR}},
  pages     = {3323--3328},
  publisher = {{ACM}},
  year      = {2022}
}

NeuralKG Core Team

Zhejiang University: Wen Zhang, Xiangnan Chen, Zhen Yao, Mingyang Chen, Yushan Zhu, Hongtao Yu, Yufeng Huang, Zezhong Xu, Yajing Xu, Peng Ye, Yichi Zhang, Ningyu Zhang, Guozhou Zheng, Huajun Chen

More Repositories

1

KG-LLM-Papers

[Paper List] Papers integrating knowledge graphs (KGs) and large language models (LLMs)
1,409
star
2

KG-MM-Survey

Knowledge Graphs Meet Multi-Modal Learning: A Comprehensive Survey
305
star
3

MyGO

[Paper][Preprint 2024] MyGO: Discrete Modality Information as Fine-Grained Tokens for Multi-modal Knowledge Graph Completion
Python
208
star
4

KnowPAT

[Paper][ACL 2024 Findings] Knowledgeable Preference Alignment for LLMs in Domain-specific Question Answering
Python
182
star
5

KoPA

[Paper][ACM MM 2024] Making Large Language Models Perform Better in Knowledge Graph Completion
Python
133
star
6

Structure-CLIP

[Paper][AAAI2024]Structure-CLIP: Towards Scene Graph Knowledge to Enhance Multi-modal Structured Representations
Python
106
star
7

MEAformer

[Paper][ACM MM 2023] MEAformer: Multi-modal Entity Alignment Transformer for Meta Modality Hybrid
Python
52
star
8

DUET

[Paper][AAAI 2023] DUET: Cross-modal Semantic Grounding for Contrastive Zero-shot Learning
Python
46
star
9

MorsE

[Paper][SIGIR2022] Meta-Knowledge Transfer for Inductive Knowledge Graph Embedding
Python
40
star
10

MaKEr

[Paper][IJCAI2022] Meta-Learning Based Knowledge Extrapolation for Knowledge Graphs in the Federated Setting
Python
29
star
11

EasySchema

29
star
12

UMAEA

[Paper][ISWC 2023] Rethinking Uncertainly Missing and Ambiguous Visual Modality in Multi-Modal Entity Alignment
Python
29
star
13

NATIVE

[Paper][SIGIR 2024] NativE: Multi-modal Knowledge Graph Completion in the Wild
Python
23
star
14

AdaMF-MAT

[Paper][LREC-COLING 2024] Unleashing the Power of Imbalanced Modality Information for Multi-modal Knowledge Graph Completion
Python
20
star
15

FedE

[Paper][IJCKG2021] FedE: Embedding Knowledge Graphs in Federated Setting
Python
19
star
16

RMPI

[Paper][ICDE2023] Relational Message Passing for Fully Inductive Knowledge Graph Completion
Python
18
star
17

Ruleformer

[Paper][COLING2022] Ruleformer: Context-aware Rule Mining over Knowledge Graph
Python
18
star
18

NeuralKG-ind

Python
15
star
19

CausE

[Paper][CCKS2023] CausE: Towards Causal Knowledge Graph Embedding
Python
15
star
20

SNAG

[Paper][Preprint 2024] The Power of Noise: Toward a Unified Multi-modal Knowledge Graph Representation Framework
Python
12
star
21

EARL

[Paper][AAAI2023] Entity-Agnostic Representation Learning for Parameter-Efficient Knowledge Graph Embedding
Python
12
star
22

KGTransformer

Source code for "Structure Pre-training and Prompt Tuning for Knowledge Graph Transfer" accepted by WWW'23
Python
11
star
23

MoMoK

[Paper][Preprint 2024] Mixture of Modality Knowledge Experts for Robust Multi-modal Knowledge Graph Completion
Python
9
star
24

DOZSL

[Paper][KDD2022] Disentangled Ontology Embedding for Zero-shot Learning
Python
8
star
25

MANS

[Paper][IJCNN2023] Modality-Aware Negative Sampling for Multi-modal Knowledge Graph Embedding
Python
7
star
26

AnKGE

[Paper][AAAI2023] Analogical Inference Enhanced Knowledge Graph Embedding
Python
7
star
27

LPKG

Python
6
star
28

ENeSy

[Paper][NeurIPS2022] Neural-Symbolic Entangled Framework for Complex Query Answering
Python
5
star
29

MACO

[Paper][NLPCC 2023] MACO: A Modality Adversarial and Contrastive Framework for Modality-missing Multi-modal Knowledge Graph Completion
Python
5
star
30

GEEA

Revisit and Outstrip Entity Alignment: A Perspective of Generative Models
Python
4
star
31

MuDoK

[Paper][Preprint 2024] Multi-domain Knowledge Graph Collaborative Pre-training and Prompt Tuning for Diverse Downstream Tasks
Python
3
star
32

GPHT-for-TSP

Python
2
star
33

cnGraph

1
star
34

PaperList-Neural-Symbolic-KGR

1
star