Skip to content

Jacen789/relation-extraction

Repository files navigation

relation-extraction

中文关系抽取

数据集来源:

https://github.com/buppt/ChineseNRE/raw/master/data/people-relation/train.txt

bert_model

https://huggingface.co/models 下载bert-base-chinese模型,解压在pretrained_models下

bert-base-chinese目录结构如下:

bert-base-chinese/
├── config.json
├── pytorch_model.bin
└── vocab.txt

模型训练20轮的评测结果:

              precision    recall  f1-score   support

     unknown       0.57      0.53      0.55       100
          父母       0.79      0.85      0.82       228
          夫妻       0.81      0.87      0.84       270
          师生       0.79      0.70      0.75        54
        兄弟姐妹       0.75      0.67      0.71        81
          合作       0.89      0.80      0.84       110
          情侣       0.78      0.79      0.78        57
          祖孙       0.75      0.71      0.73        17
          好友       0.69      0.81      0.75        27
          亲戚       0.78      0.54      0.64        13
          同门       0.81      0.71      0.76        24
         上下级       0.60      0.63      0.62        19

    accuracy                           0.78      1000
   macro avg       0.75      0.72      0.73      1000
weighted avg       0.77      0.78      0.77      1000

模型预测效果:

run the demo_predict.py

输入中文句子:陈信宏[阿信]-星路历程1997五月天正式成军!1997[329台湾乐团野台]开唱。
句子中的实体1:陈信宏
句子中的实体2:五月天
最大可能的关系是:合作
No.1:关系(合作)的可能性:8.616347312927246
No.2:关系(情侣)的可能性:3.2267608642578125
No.3:关系(上下级)的可能性:1.1111985445022583
No.4:关系(好友)的可能性:0.6253753304481506
No.5:关系(兄弟姐妹)的可能性:0.3107122778892517
No.6:关系(亲戚)的可能性:-0.9791264533996582
No.7:关系(师生)的可能性:-1.1277936697006226
No.8:关系(unknown)的可能性:-1.3374849557876587
No.9:关系(同门)的可能性:-1.6859681606292725
No.10:关系(祖孙)的可能性:-2.4367446899414062
No.11:关系(父母)的可能性:-2.8472912311553955
No.12:关系(夫妻)的可能性:-3.2687606811523438
输入中文句子:勤曹乘曹京曹棘曹宪曹节[魏]曹华相关人物:曹茂曹叡曾效力过的势力:魏曹操-人物简介曹操一共有二十五个儿子,除了早夭的几个和过继
句子中的实体1:曹节
句子中的实体2:曹操
最大可能的关系是:父母
No.1:关系(父母)的可能性:8.557628631591797
No.2:关系(兄弟姐妹)的可能性:3.39963698387146
No.3:关系(祖孙)的可能性:3.1388494968414307
No.4:关系(unknown)的可能性:3.1104931831359863
No.5:关系(上下级)的可能性:-0.5524467825889587
No.6:关系(情侣)的可能性:-1.0892189741134644
No.7:关系(师生)的可能性:-1.6886475086212158
No.8:关系(合作)的可能性:-2.1440365314483643
No.9:关系(亲戚)的可能性:-3.157778024673462
No.10:关系(夫妻)的可能性:-3.691408395767212
No.11:关系(同门)的可能性:-3.959960699081421
No.12:关系(好友)的可能性:-4.042106628417969
输入中文句子:任教台湾大学后,台静农由于与鲁迅及左翼文坛的亲密关系,再加之他在战前几次锒铛入狱的经历,其行
句子中的实体1:台静农
句子中的实体2:鲁迅
最大可能的关系是:好友
No.1:关系(好友)的可能性:9.790139198303223
No.2:关系(兄弟姐妹)的可能性:1.6511707305908203
No.3:关系(夫妻)的可能性:0.6450995206832886
No.4:关系(情侣)的可能性:0.33425071835517883
No.5:关系(父母)的可能性:-0.2065272182226181
No.6:关系(亲戚)的可能性:-0.5174587965011597
No.7:关系(unknown)的可能性:-0.8007057905197144
No.8:关系(祖孙)的可能性:-0.9827389121055603
No.9:关系(师生)的可能性:-1.908825159072876
No.10:关系(同门)的可能性:-2.645210027694702
No.11:关系(上下级)的可能性:-2.8579206466674805
No.12:关系(合作)的可能性:-4.13227653503418
输入中文句子:张三和李四同床多年
句子中的实体1:张三
句子中的实体2:李四
最大可能的关系是:夫妻
No.1:关系(夫妻)的可能性:5.254703521728516
No.2:关系(同门)的可能性:2.8437232971191406
No.3:关系(情侣)的可能性:2.768967628479004
No.4:关系(兄弟姐妹)的可能性:1.0944303274154663
No.5:关系(unknown)的可能性:0.9157931804656982
No.6:关系(好友)的可能性:0.39977359771728516
No.7:关系(合作)的可能性:0.18726643919944763
No.8:关系(父母)的可能性:-1.9329102039337158
No.9:关系(祖孙)的可能性:-2.6917757987976074
No.10:关系(上下级)的可能性:-3.5351831912994385
No.11:关系(师生)的可能性:-3.941521644592285
No.12:关系(亲戚)的可能性:-5.222504615783691

参考:

https://github.com/thunlp/OpenNRE

https://github.com/monologg/R-BERT

https://github.com/crownpku/Information-Extraction-Chinese