Package: pykg2vec
Pykg2vec: Python Library for KGE MethodsPykg2vec is a library for learning the representation of entities and relations in Knowledge Graphs built on top of PyTorch 1.5 (TF2 version is available intf-masterbranch as well). We have attempted to bring state-of-the-art Knowledge Graph Embedding (KGE) algorithms and the necessary building blocks in the pipeline of knowledge graph embedding task into a single library. We hope Pykg2vec is both practical and educational for people who want to explore the related fields.Features:Support state-of-the-art KGE model implementations and benchmark datasets. (also support custom datasets)Support automatic discovery for hyperparameters.Tools for inspecting the learned embeddings.Support exporting the learned embeddings in TSV or Pandas-supported format.Interactive result inspector.TSNE-based, KPI summary visualization (mean rank, hit ratio) in various format. (csvs, figures, latex table)We welcome any form of contribution! Please refer toCONTRIBUTING.mdfor more details.To Get StartedBefore using pykg2vec, we recommend users to have the following libraries installed:python >=3.6 (recommended)pytorch>= 1.5Quick Guide for Anaconda users:Setup a Virtual Environment: we encourage you to use anaconda to work with pykg2vec:(base)$condacreate--namepykg2vecpython=3.6(base)$condaactivatepykg2vecSetup Pytorch: we encourage to use pytorch with GPU support for good training performance. However, a CPU version also runs. The following sample commands are for setting up pytorch:# if you have a GPU with CUDA 10.1 installed(pykg2vec)$condainstallpytorchtorchvisioncudatoolkit=10.1-cpytorch# or cpu-only(pykg2vec)$condainstallpytorchtorchvisioncpuonly-cpytorchSetup Pykg2vec:(pykg2vec)$gitclonehttps://github.com/Sujit-O/pykg2vec.git(pykg2vec)$cdpykg2vec(pykg2vec)$pythonsetup.pyinstallFor beginners, these papers,A Review of Relational Machine Learning for Knowledge Graphs,Knowledge Graph Embedding: A Survey of Approaches and Applications, andAn overview of embedding models of entities and relationships for knowledge base completioncan be good starting points!User DocumentationThe documentation ishere.Usage ExamplesWith pykg2vec command-line interface, you canRun a single algorithm with various models and datasets (customized dataset also supported).# Check all tunnable parameters.
(pykg2vec) $ pykg2vec-train -h

# Train TransE on FB15k benchmark dataset.
(pykg2vec) $ pykg2vec-train -mn TransE

# Train using different KGE methods.
(pykg2vec) $ pykg2vec-train -mn [TransE|TransD|TransH|TransG|TransM|TransR|Complex|ComplexN3|
                    CP|RotatE|Analogy|DistMult|KG2E|KG2E_EL|NTN|Rescal|SLM|SME|SME_BL|HoLE|
                    ConvE|ConvKB|Proje_pointwise|MuRP|QuatE|OctonionE|InteractE|HypER]

# For KGE using projection-based loss function, use more processes for batch generation.
(pykg2vec) $ pykg2vec-train -mn [ConvE|ConvKB|Proje_pointwise] -npg [the number of processes, 4 or 6]

# Train TransE model using different benchmark datasets.
(pykg2vec) $ pykg2vec-train -mn TransE -ds [fb15k|wn18|wn18_rr|yago3_10|fb15k_237|ks|nations|umls|dl50a|nell_955]

# Train TransE model using your own hyperparameters.
(pykg2vec) $ pykg2vec-train -exp True -mn TransE -ds fb15k -hpf ./examples/custom_hp.yaml

# Use your own dataset
(pykg2vec) $ pykg2vec-train -mn TransE -ds [name] -dsp [path to the custom dataset]Tune a single algorithm.# Tune TransE using the benchmark dataset.
(pykg2vec) $ pykg2vec-tune -mn [TransE] -ds [dataset name]

# Tune TransE with your own search space
(pykg2vec) $ pykg2vec-tune -exp True -mn TransE -ds fb15k -ssf ./examples/custom_ss.yamlPerform Inference Tasks (more advanced).# Train a model and perform inference tasks.
(pykg2vec) $ pykg2vec-infer -mn TransE

# Perform inference tasks over a pretrained model.
(pykg2vec) $ pykg2vec-infer -mn TransE -ld [path to the pretrained model]* NB: On Windows, usepykg2vec-train.exe,pykg2vec-tune.exeandpykg2vec-infer.exeinstead.For more usage of pykg2vec APIs, please check theprogramming examples.CitationPlease kindly consider citing our paper if you find pykg2vec useful for your research.@article{yu2019pykg2vec,
  title={Pykg2vec: A Python Library for Knowledge Graph Embedding},
  author={Yu, Shih Yuan and Rokka Chhetri, Sujit and Canedo, Arquimedes and Goyal, Palash and Faruque, Mohammad Abdullah Al},
  journal={arXiv preprint arXiv:1906.04239},
  year={2019}
  }