包括NLP工具包的最新知识库和电池
Zincbase的Python项目详细描述
Zincbase是一个电池包,用于构建知识库。存在以下问题:
- 从非结构化数据/文本中提取事实(也称为三元组和规则)
- 有效地存储和检索这些事实
- 将它们构建为图形
- 提供查询图的方法,包括通过出血边缘图神经网络。
它将最新的神经网络与符号逻辑(思考专家系统和prolog)和图形搜索相结合。
查看完整文档here。
快速启动
from 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)
# Note that it won't be included if you pip install, only if you git clone.
kb = KB()
kb.from_csv('./assets/countries.csv')
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')
0.8467
要求
- 巨蟒3
- Requirements.txt中的库
- GPU最好用于大型图形,但不是必需的
安装
pip install zincbase
这不会为您提供示例或资产(除了那些自动 可根据需要下载,如NER型号。)高级用户可能希望:
git clone https://github.com/tomgrek/zincbase.git
pip install -r requirements.txt
注意:pytorch的需求可能因系统而异。在Mac OSX上
您可能需要首先brew install libomp
。
测试
python -m doctest zincbase/zincbase.py
python test/test_main.py
python test/test_graph.py
python test/test_lists.py
python test/test_nn_basic.py
python test/test_nn.py
python test/test_neg_examples.py
python test/test_truthiness.py
验证
“国家”和“FB15K”数据集包含在本回购协议中。
有一个脚本可以评估zincbase至少可以 作为原始(2019年)轮换文件的国家数据集的表现。从回购协议 根目录:
python examples/eval_countries_s3.py
它测试最困难的国家的任务并打印出auc roc,它应该是 约0.95以匹配纸张。在现代gpu上运行大约需要30分钟。
还有一个脚本用于评估FB15K上的性能:python examples/fb15k_mrr.py
。
建筑文档
来自docs/dir:make html
。如果发生了很大变化:sphinx-apidoc -o . ..
构建pypi轮
从回购的根目录:
python setup.py sdist
twine upload dist/*
待办事项
- 添加文档
- to_csv方法
- 利用Postgres作为后端三重存储
- to-csv/from-csv方法尚不支持节点属性。
- 从任意非结构化文本中添加关系提取
- 将上下文添加到triple-由bert/ulm/gpt-2解释,类似于 把它放进一个包里,和KG包里一样。
- 图遍历的强化学习。
参考和确认
L334: Computational Syntax and Semantics -- Introduction to Prolog, Steve Harlow
Open Book Project: Prolog in Python, Chris Meyers
Prolog Interpreter in Javascript
引用
如果您使用本软件,请考虑引用:
@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}
}
贡献
见贡献。请做!