Knowledge Graph Autoencoder Training Environment (KGATE)
KGATE is a knowledge graph embedding library bridging the encoders from Pytorch Geometric and the decoders from TorchKGE.
This tool relies heavily on the performances of TorchKGE and its numerous implemented modules for link prediction, negative sampling and model evaluation. The main goal here is to address the lack of encoders in the original library, who is unfortunately not maintained anymore.
Installation
It is recommended to download the configuration template alongside your installation (see Usage below).
With pip
pip install kgate
From source
Clone this repository and install it in a virtual environment like so:
git clone git@github.com:BAUDOTlab/KGATE.git
python -m venv kge_env
source kge_env/bin/activate
Join the development
KGATE is developed using Poetry. If you want to contribute to KGATE or make your own modifications, follow these steps:
1. Install Poetry
pip install poetry
2. Clone the repository
git clone git@github.com:BAUDOTlab/KGATE.git
3. Install dependencies
cd KGATE
poetry install
(usage)=
Usage
KGATE is meant to be a self-sufficient training environment for knowledge graph embedding that requires very little code to work but can easily be expanded or modified. Everything stems from the Architect class, which holds all the necessary attributes and methods to fully train and test a KGE model following the autoencoder architecture, as well as run inference.
Command line
After installation, the kgate command trains and tests a model in a single step (or use python -m kgate):
# The most common case: a CSV file and an output directory. That's enough.
kgate my_kg.csv --output runs/my_run
# Tweak the model: a different decoder, embedding size, training budget
kgate my_kg.csv --output runs/my_run --decoder ComplEx --dim 50 --epochs 30
# Start from a configuration file and override a few options on the command line
kgate config.toml --lr 0.0005 --batch-size 4096
# Check that a setup is valid without training
kgate my_kg.csv --output runs/my_run --dry-run
- The first argument can be either a TOML configuration file or directly the knowledge graph CSV (equivalent to
--kg-csv). Command line options always override the configuration file values. - Every option of the configuration template is available as a command line option; run
kgate --helpfor the full list with plain-language explanations, allowed values and defaults. - Results (checkpoints, metrics, learning curves) are written to the output directory, and the resolved configuration is saved there as
kgate_config.tomlfor reproducibility.
Python API
The configuration file lets you iterate quickly without changing your code. See the template to learn what the different options do.
At the very least, KGATE expects the Knowledge Graph to be given as a pandas dataframe or a CSV file with the columns "head", "tail" and "edge", corresponding respectively to the head nodes, tail nodes and relation types of the triplets, with one triplet per row. Any extra columns are ignored. In addition, a metadata dataframe can be submitted (can also be a CSV) to map each node with their type, requiring the columns "id" and "type". Extra columns are likewise ignored.
from kgate import Architect
config_path = "/path/to/your/config.toml"
architect = Architect(config_path = config_path)
# Train the model using KG and hyperparameters specified in the configuration
architect.train_model()
# Test the trained model, using the best checkpoint
architect.test()
# Run KG completion task, the empty list is the element that will be predicted
known_heads = []
known_relations = []
known_tails = []
architect.infer(known_heads, known_relations, known_tails)
For a more detailed example and specific methods that are available in the package, see the upcoming readthedocs documentation.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for KGATE 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kgate-1.0.0.tar.gz | 136.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kgate-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 286.6 kB
Release files / kgate-1.0.0.tar.gz
| Download URL | kgate-1.0.0.tar.gz |
|---|---|
| Size | 136.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
73437283ea90240da7bcc821c433f74874bfa0ba1cd471eb37936b2ce2f5834d
|
|
BLAKE2b-256 checksum How to use checksums |
91e1d746f68059be36f367daab249a8e1a29dc69952686bed937b91142583efd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.14.6 Linux/7.1.5-arch1-2
|
Release files / kgate-1.0.0-py3-none-any.whl
| Download URL | kgate-1.0.0-py3-none-any.whl |
|---|---|
| Size | 150.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
15fcbf90eeddb9d9920aa66aacbe1078ce5f24746654ea40d520c70abd6c44df
|
|
BLAKE2b-256 checksum How to use checksums |
e09406a5ab4fc5f85036c4c1a33c9d1d04d9aa841a697b8808c9cf12997d6d46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.14.6 Linux/7.1.5-arch1-2
|