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'
model.infer({'text': text, 'h': {'pos': (text.index(bill), text.index(bill) + len(bill))},
't': {'pos': (text.index(cmp), text.index(cmp) + len(cmp))}})
model.infer({'text': text, 'h': {'pos': (text.index(bill), text.index(bill) + len(bill))},
't': {'pos': (text.index(fri), text.index(fri) + len(fri))}})