OpenNRE关系提取

1.安装OpenNRE
git clone https://github.com/thunlp/OpenNRE.git
cd OpenNRE/

pip3 install torch
pip3 install transformers
pip3 install pytest
pip3 install scikit-learn
pip3 install scipy
pip3 install nltk


python3 setup.py install
2.基本使用
import opennre

model = opennre.get_model('wiki80_cnn_softmax')
text = 'January 15,2000 Tech pioneer Bill Gates stepped down today as chief executive officer of Microsoft, the Seattle-headquartered software giant. His long-time fried, Steve Balmor, will take over as CEO of Microsoft.'
bill = 'Bill Gates'
cmp = 'Microsoft'
fri = 'Steve Balmor'

# 查看Bill Gates和Microsoft之间的关系
model.infer({'text': text, 'h': {'pos': (text.index(bill), text.index(bill) + len(bill))},
             't': {'pos': (text.index(cmp), text.index(cmp) + len(cmp))}})

# 查看Bill Gates和Steve Balmor之间的关系
model.infer({'text': text, 'h': {'pos': (text.index(bill), text.index(bill) + len(bill))},
             't': {'pos': (text.index(fri), text.index(fri) + len(fri))}})

你可能感兴趣的:(个人学习记录,python)