Zincbase logo

ZincBase is a state of the art knowledge base. It does the following:

  • Extract facts (aka triples and rules) from unstructured data/text
  • Store and retrieve those facts efficiently
  • Build them into a graph
  • Provide ways to query the graph, including via bleeding-edge graph neural networks.

Zincbase exists to answer questions like “what is the probability that Tom likes LARPing”, or “who likes LARPing”, or “classify people into LARPers vs normies”:

Example graph for reasoning

It combines the latest in neural networks with symbolic logic (think expert systems and prolog) and graph search.

View full documentation here.


from zincbase import KB
kb = KB()'eats(tom, rice)')
for ans in kb.query('eats(tom, Food)'):
    print(ans['Food']) # prints 'rice'

# The included assets/countries_s1_train.csv contains triples like:
# (namibia, locatedin, africa)
# (lithuania, neighbor, poland)

kb = KB()
kb.build_kg_model(cuda=False, embedding_size=40)
kb.train_kg_model(steps=2000, batch_size=1, verbose=False)
kb.estimate_triple_prob('fiji', 'locatedin', 'melanesia')


  • Python 3
  • Libraries from requirements.txt
  • GPU preferable for large graphs but not required


pip install -r requirements.txt

Note: Requirements might differ for PyTorch depending on your system.


python test/
python test/
python test/
python test/
python test/
python test/
python test/
python -m doctest zincbase/


“Countries” and “FB15k” datasets are included in this repo.

There is a script to evaluate that ZincBase gets at least as good performance on the Countries dataset as the original (2019) RotatE paper. From the repo’s root directory:

python examples/

It tests the hardest Countries task and prints out the AUC ROC, which should be ~ 0.95 to match the paper. It takes about 30 minutes to run on a modern GPU.

There is also a script to evaluate performance on FB15k: python examples/

Building documentation

From docs/ dir: make html. If something changed a lot: sphinx-apidoc -o . ..


  • Refactor so node and edge are their own class
  • Query all edges by attribute
  • Rules (observables) to say ‘on change of attribute, run this small program and propagate changes’
    • Will enable advanced simulation beginning with Abelian sandpile
  • to_csv method
  • To DOT, for visualization (integrate with github/anvaka/word2vec-graph)
  • utilize postgres as backend triple store
  • The to_csv/from_csv methods do not yet support node attributes.
  • Reinforcement learning for graph traversal.


If you use this software, please consider citing:

  author = {{Tom Grek}},
  title = {ZincBase: A state of the art knowledge base},
  url = {},
  version = {0.1.1},
  date = {2019-05-12}


See CONTRIBUTING. And please do!