Package: zincbase
ZincBase is a state of the art knowledge base and complex simulation suite. It does the following:Store and retrieve graph structured data efficiently.Provide ways to query the graph, including via bleeding-edge graph neural networks.Simulate complex effects playing out across the graph and see how predictions change.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", or simulations like "what happens if all the LARPers become normies".It combines the latest in neural networks with symbolic logic (think expert systems and prolog), graph search, and complexity theory.View full documentationhere.Quickstartpip3 install zincbasefrom zincbase import KB
kb = KB()
kb.store('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.from_csv('./assets/countries_s1_train.csv', delimiter='\t')
kb.build_kg_model(cuda=False, embedding_size=40)
kb.train_kg_model(steps=8000, batch_size=1, verbose=False)
kb.estimate_triple_prob('fiji', 'locatedin', 'melanesia')
0.9607RequirementsPython 3Libraries from requirements.txtGPU preferable for large graphs but not requiredInstallationpip install -r requirements.txtNote:Requirements might differ for PyTorch depending on your system.Web UIZincbase can serve live-updating force-directed graphs in 3D to a web browser. The commandpython -m zincbase.webwill set up a static file server and a websocket
server for live updates. Visithttp://localhost:5000/in your browser
and you'll see the graph UI. As you build a graph in Python, you can
visualize it (and changes to it) in realtime through this UI.Here are a couple of examples (source codehere):Complexity (Graph/Network) ExamplesTwo such examples are included (right now; we intend to include more soon such
as virus spread and neural nets that communicate.) The examples are
basic ones: Conway's Game of Life and the Abelian Sandpile. Here are some
screencaps; source code ishere,
performance can be lightning fast depending how you tweak Zincbase recursion
and propagation settings.Required for the UIYou shouldpip install zincbase[web]to get the optional web extra.You should have Redis running; by default, atlocalhost:6379. This
is easily achievable, just dodocker run -p 6379:6379 -d redisTestingpython test/test_main.py
python test/test_graph.py
... etc ... all the test files there
python -m doctest zincbase/zincbase.pyValidation"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/eval_countries_s3.pyIt 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/fb15k_mrr.py.Running the web UIThere are a couple of extra requirements -- install withpip3 install zincbase[web].
You also need an accessible Redis instance somewhere. This one-liner will get it running
locally:docker run -p 6379:6379 -d redis(requires Docker, of course.)You then need a Zincbase server instance running:Building documentationFrom docs/ dir:make html. If something changed a lot:sphinx-apidoc -o . ..Pushing to pypiNOTE: This is now all automatic via CircleCI, but here are the manual steps for reference:Editsetup.pyas appropriate (probably not necessary)Edit the version inzincbase/__init__.pyFrom the top project directorypython setup.py sdist bdist_wheel --universaltwine upload dist/*TODOadd ability tokb = KB(backend='complexdb://my_api_key')utilize postgres as backend triple storeReinforcement learning for graph traversal.Rete algorithm (maybe)References & AcknowledgementsTheo Trouillon. Complex-Valued Embedding Models for Knowledge Graphs. Machine Learning[cs.LG]. Université Grenoble Alpes, 2017. English. ffNNT : 2017GREAM048L334: Computational Syntax and Semantics -- Introduction to Prolog, Steve HarlowOpen Book Project: Prolog in Python, Chris MeyersProlog Interpreter in JavascriptRotatE: Knowledge Graph Embedding by Relational Rotation in Complex Space, Zhiqing Sun and Zhi-Hong Deng and Jian-Yun Nie and Jian Tang, International Conference on Learning Representations, 2019CitingIf you use this software, please consider citing:@software{zincbase,
  author = {{Tom Grek}},
  title = {ZincBase: A state of the art knowledge base},
  url = {https://github.com/tomgrek/zincbase},
  version = {0.1.1},
  date = {2019-05-12}
}ContributingSee CONTRIBUTING. And please do!