Package: neuralkg
An Open Source Library for Diverse Representation Learning of Knowledge GraphsEnglish |中文NeuralKG is a python-based library for diverse representation learning of knowledge graphs implementingConventional KGEs,GNN-based KGEs, andRule-based
KGEs. We providecomprehensive documentsfor beginners and anonline websiteto organize an open and shared KG representation learning community.Table of ContentsTable of Contents😃What's NewOct, 2022Sep, 2022Jun, 2022Mar, 2022Feb, 2022OverviewDemoImplemented KGEsQuick StartInstallationTrainingEvaluationHyperparameter TuningReproduced ResultsNotebook GuideDetailed DocumentationCitationNeuralKG Core Team😃What's NewOct, 2022We add theDualEmodel for our librarySep, 2022We add thePairREmodel for our libraryJun, 2022We add theHAKEmodel for our libraryMar, 2022We have providedGoogle Colab Tutotialshelp users use our libraryWe have provided a newblogabout how to use NeuralKG on custom datasetsFeb, 2022We have released a paperNeuralKG: An Open Source Library for Diverse Representation Learning of Knowledge GraphsOverviewNeuralKG is built onPyTorch 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, includingConventional KGEs,GNN-based KGEs, andRule-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.DemoThere is a demonstration of NeuralKG.Implemented KGEsComponentsModelsKGEModelTransE,TransH,TransR,ComplEx,DistMult,RotatE,ConvE,BoxE,CrossE,SimplE,HAKE,PairRE,DualEGNNModelRGCN,KBAT,CompGCN,XTransERuleModelComplEx-NNE+AER,RUGE,IterEQuick StartInstallationStep1Create a virtual environment usingAnacondaand enter itcondacreate-nneuralkgpython=3.8
condaactivateneuralkgStep2Install the appropriate PyTorch and DGL according to your cuda versionHere we give a sample installation based on cuda == 11.1Install PyTorchpip install torch==1.9.1+cu111 -f https://download.pytorch.org/whl/torch_stable.htmlInstall DGLpip install dgl-cu111 dglgo -f https://data.dgl.ai/wheels/repo.htmlStep3Install packageFrom PypipipinstallneuralkgFrom Sourcegitclonehttps://github.com/zjukg/NeuralKG.gitcdNeuralKG
pythonsetup.pyinstallTraining# Use bash script
sh ./scripts/your-sh

# Use config
python main.py --load_config --config_path <your-config>Evaluationpython main.py --test_only --checkpoint_dir <your-model-path>Hyperparameter TuningNeuralKG utilizesWeights&Biasessupporting 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 ResultsThere are some reproduced model results on FB15K-237 dataset using NeuralKG as below. See more results inhereMethodMRRHit@1Hit@3Hit@10TransE0.320.230.360.51TransR0.230.160.260.38TransH0.310.20.340.50DistMult0.300.220.330.48ComplEx0.250.170.270.40SimplE0.160.090.170.29ConvE0.320.230.350.50RotatE0.330.230.370.53BoxE0.320.220.360.52HAKE0.340.240.380.54PairRE0.350.250.380.54DualE0.330.240.360.52XTransE0.290.190.310.45RGCN0.250.160.270.43KBAT*0.280.180.310.46CompGCN0.340.250.380.52IterE0.260.190.290.41*:There is a label leakage error in KBAT, so the corrected result is poor compared with the paper result. Details inhttps://github.com/deepakn97/relationPrediction/issues/28Notebook Guide😃We use colab to provide some notebooks to help users use our library.Detailed Documentationhttps://zjukg.github.io/NeuralKG/neuralkg.htmlCitationPlease cite our paper if you use NeuralKG in your work@article{zhang2022neuralkg,title={NeuralKG: An Open Source Library for Diverse Representation Learning of Knowledge Graphs},author={Zhang, Wen and Chen, Xiangnan and Yao, Zhen and Chen, Mingyang and Zhu, Yushan and Yu, Hongtao and Huang, Yufeng and others},journal={arXiv preprint arXiv:2202.12571},year={2022},}NeuralKG Core TeamZhejiang 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