OpenNRE 开源关系抽取工具包
首页 http://nlp.csai.tsinghua.edu.cn/project/opennre/
clone代码
git clone https://github.com/thunlp/OpenNRE.git
安装Anaconda,创建环境运行
wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh
bash Anaconda3-2022.05-Linux-x86_64.sh # 按提示输入是否信息
conda create -n py39
conda activate py39
cd OpenNRE
安装依赖,包含torch
pip3 install -r requirements.txt
安装OpenNRE
python3 setup.py install
运行python3,输入代码
import opennre
model = opennre.get_model('wiki80_bert_softmax')
model.infer({'text': 'He was the son of Máel Dúin mac Máele Fithrich, and grandson of the high king Áed Uaridnach (died 612).', 'h': {'pos': (18, 46)}, 't': {'pos': (78, 91)}})
使用模型tacred_bertentity_softmax
model = opennre.get_model('tacred_bertentity_softmax')
model.infer({'text': 'Bill Gates founded Microsoft in 1975.', 'h': {'pos': (19, 28)}, 't': {'pos': (32, 36)}})