Package: neuralkg-ind
A Python Library for Inductive Knowledge Graph Representation LearningEnglish |中文NeuralKG-ind is a python-based library for inductive knowledge graph representation learning, which includesstandardized processes,rich existing methods,decoupled modules, andcomprehensive evaluation metrics. We providecomprehensive documentsfor beginners.Table of ContentsTable of Contents😃What's NewFeb, 2023OverviewDemoImplemented MethodsQuick StartInstallationTrainingEvaluationHyperparameter TuningReproduced ResultsNotebook GuideDetailed DocumentationNeuralKG-ind Core Team😃What's NewFeb, 2023We have released a paperNeuralKG-ind: A Python Library for Inductive Knowledge Graph Representation LearningOverviewNeuralKG-ind is built onPyTorch Lightningand based onNeuralKG. It provides  a general workflow for developing models handling inductive tasks on KGs. It has the following features:Standardized process.According to existing methods, we standardized the overall process of constructing an inductive knowledge graph representation learning model, including data processing, sampler and trainer construction, and evaluation of link prediction and triple classification tasks. We also provide auxiliary functions, including log management and hyper-parameter tuning, for model training and analysis.Rich existing methods.We re-implemented 5 inductive knowledge graph representation learning methods proposed in recent 3 years, includingGraIL,CoMPILE,SNRI,RMPIandMorsE, enabling users to apply these models off the shelf.Decoupled modules.We provide a lot of decoupled modules, such as the subgraph extraction function, the node labeling function, neighbor aggregation functions, compound graph neural network layers, and KGE score functions, enabling users to construct a new inductive knowledge graph representation learning model faster.Long-term supports.We provide long-term support on NeuralKG-ind, including maintaining detailed documentation, creating straightforward quick-start, adding new models, solving issues, and dealing with pull requests.DemoThere is a demonstration of NeuralKG-ind.Implemented MethodsComponentsModelsKGEModelTransE,TransH,TransR,ComplEx,DistMult,RotatE,ConvE,BoxE,CrossE,SimplE,HAKE,PairRE,DualEGNNModelRGCN,KBAT,CompGCN,XTransE,GraIL,CoMPILE,SNRI,RMPI,MorsERuleModelComplEx-NNE+AER,RUGE,IterEQuick StartInstallationStep1Create a virtual environment usingAnacondaand enter itcondacreate-nneuralkg-indpython=3.8
condaactivateneuralkg-indStep2Install 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 packagegitclonehttps://github.com/zjukg/NeuralKG-ind.gitcdNeuralKG-ind
pythonsetup.pyinstallTraining# Use bash script
sh ./scripts/your-sh

# Use config
python main.py --load_config --config_path <your-config>Evaluation# Testing AUC and AUC-PR 
python main.py --test_only --checkpoint_dir <your-model-path> --eval_task triple_classification 

# Testing MRR and hit@1,5,10
python main.py --test_only --checkpoint_dir <your-model-path> --eval_task link_prediction --test_db_path <your-db-path>Hyperparameter TuningNeuralKG-ind 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 Grail on the FB15K-237 dataset using bayes search:command:
  - ${env}
  - ${interpreter}
  - ${program}
  - ${args}
program: main.py
method: bayes
metric:
  goal: maximize
  name: Eval|auc
parameters:
  dataset_name:
    value: FB15K237
  model_name:
    value: Grail
  loss_name:
    values: [Margin_Loss]
  train_sampler_class:
    values: [SubSampler]
  emb_dim:
    values: [32, 64]
  lr:
    values: [1e-2, 5e-3, 1e-3]
  train_bs:
    values: [64, 128]
  num_neg:
    values: [16, 32]Reproduced ResultsThere are some reproduced model results on FB15K-237 dataset and partial results on NELL-995 using NeuralKG as below. See more results inhereMethodFB15K-237_v1FB15K-237_v2AUCAUC-PRMRRHits@1Hit@5Hit@10AUCAUC-PRMRRHits@1Hit@5Hit@10GraIL0.8020.8210.4520.3590.5610.6240.8730.9000.6420.5390.7670.831CoMPILE0.8000.8350.5160.4370.6000.6680.8760.9050.6170.5090.7410.813SNRI0.7920.8830.4950.3900.6000.7200.8840.9060.6460.5360.7810.857RMPI0.8030.8230.5320.4510.6200.6890.8510.8820.6320.5230.7630.830MorsE0.8440.8470.5910.4700.7230.8330.9630.9600.7540.6430.8970.950MethodFB15K-237_v3FB15K-237_v4AUCAUC-PRMRRHits@1Hit@5Hit@10AUCAUC-PRMRRHits@1Hit@5Hit@10GraIL0.8710.8990.6370.5300.7650.8280.9110.9210.6390.5210.7970.880CoMPILE0.9060.9250.6700.5680.7960.8590.9270.9320.7040.6040.8310.894SNRI0.8700.8840.6420.5250.7750.8710.8990.9160.6810.5730.8210.894RMPI0.8760.8660.6620.5690.7670.8270.9050.9160.6470.5350.7870.866MorsE0.9590.9520.7450.6370.8780.9540.9630.9520.7420.6620.8880.958MethodNELL-995_v1NELL-995_v2AUCAUC-PRMRRHits@1Hit@5Hit@10AUCAUC-PRMRRHits@1Hit@5Hit@10GraIL0.8140.7500.4670.3950.5150.5750.9290.9470.7350.6240.8840.933SNRI0.7370.7200.5230.4750.5450.5950.8640.8840.6300.5070.7740.863Notebook Guide😃We use colab to provide some notebooks to help users use our library.Detailed Documentationhttps://zjukg.github.io/NeuralKG-ind/neuralkg_ind.model.htmlNeuralKG-ind Core TeamZhejiang University: Wen Zhang, Zhen Yao, Mingyang Chen, Zhiwei Huang, Huajun Chen