KGLIB provides tools to enable machine learning with TypeDB.
This library is under development and will henceforth be transformed into primarily infrastructure tools and integrations between TypeDB and machine learning libraries.
The pipeline provided helps by allowing us to extract subgraphs from TypeDB. Each subgraph is a training example, which are sent to the learner in batches. Algorithms using this approach are scalable since they do not need to hold the whole graph in memory for training.
The pipeline is as follows:
- Extract data from
TypeDB
into Python NetworkX in-memory subgraphs by specifying multiple TypeQL queries. - Encode the nodes and edges of the NetworkX graphs
- Either (a) transform the encoded values into features, ready for input into a graph/geometric learning pipeline (for example the upcoming PyTorch implementation); or (b) Embed the encoded values according to the Types present in your database (TensorFlow only, PyTorch coming soon). This type-centric embedding is crucial to extracting the context explicitly captured in TypeDB's Type System.
- Feed the features to a learning algorithm (see below)
- Optionally, store the predictions made by the learner in TypeDB. These predictions can then be queried using TypeQL. This means we can trivially run more learning tasks over the knowledge base, including the newly made predictions. This is knowledge graph completion.
This repo contains one algorithmic implementation: Knowledge Graph Convolutional Network (KGCN). This is a generic method for relation predication over any TypeDB database. There is a full worked example and an explanation of how the approach works.
You are encouraged to use the tools available in KGLIB to interface TypeDB to your own algorithmic implementations, or to use/leverage prebuilt implementations available from popular libraries such as PyTorch Geometric or Graph Nets (TensorFlow/Sonnet).
You may find the following resources useful:
- Strongly Typed Data for Machine Learning (YouTube)
- How Can We Complete a Knowledge Graph? (YouTube)
-
Python >= 3.6, <= 3.7.x (TensorFlow 1.14.0 doesn't support later Python versions).
-
KGLIB installed via pip:
pip install typedb-kglib
. -
TypeDB 2.1.1 running in the background.
-
typedb-client-python
2.1.0 (PyPi, GitHub release). This should be installed automatically when youpip install typedb-kglib
.
Take a look at Knowledge Graph Convolutional Networks (KGCNs) to see a walkthrough of how to use the library.
It's expected that you will use Pip to install, but should you need to make your own changes to the library, and import it into your project, you can build from source as follows.
Clone KGLIB:
git clone [email protected]:vaticle/kglib.git
Go into the project directory:
cd kglib
Build all targets:
bazel build //...
Run all tests. Requires Python 3.6+ on your PATH
. Test dependencies are for Linux since that is the CI environment:
bazel test //kglib/... --test_output=streamed --spawn_strategy=standalone --action_env=PATH
Build the pip distribution. Outputs to bazel-bin
:
bazel build //:assemble-pip
To follow the development conversation, please join the Vaticle Discord, and join the #kglib
channel. Alternatively, start a new topic on the Vaticle Discussion Forum.
KGLIB requires that you have migrated your data into a TypeDB or TypeDB Cluster instance. There is an official examples repo for how to go about this, and information available on migration in the docs. Alternatively, there are fantastic community-led projects growing in the TypeDB OSI to facilitate fast and easy data loading.