Git Product home page Git Product logo

people_relation_extract's Introduction

  运行该项目的模型训练和模型预测脚本需要准备BERT中文版的模型数据,下载网址为:https://github.com/google-research/bert/blob/master/multilingual.md

  利用笔者自己收集的3881个样本,对人物关系抽取进行尝试。人物关系共分为14类,如下:

{
  "unknown": 0,
  "夫妻": 1,
  "父母": 2,
  "兄弟姐妹": 3,
  "上下级": 4,
  "师生": 5,
  "好友": 6,
  "同学": 7,
  "合作": 8,
  "同人": 9,
  "情侣": 10,
  "祖孙": 11,
  "同门": 12,
  "亲戚": 13
}

  人物关系类别频数分布条形图如下:

  模型结构: BERT + 双向GRU + Attention + FC

  模型训练效果:

# 训练集(train), loss: 0.0260, acc: 0.9941
# 最终测试集(test),  loss: 0.9505, acc: 0.7905
# 测试集上效果最好的,  loss: 0.8277, acc: 0.7956

  在测试集上的每一类的classification_report如下:

              precision    recall  f1-score   support

     unknown       0.72      0.77      0.75       159
          夫妻       0.82      0.79      0.81        58
          父母       0.84      0.91      0.87        99
        兄弟姐妹       0.81      0.84      0.82        25
         上下级       0.62      0.67      0.64        24
          师生       0.71      0.83      0.76        29
          好友       0.82      0.67      0.73        27
          同学       0.92      0.69      0.79        16
          合作       0.83      0.77      0.80        44
          同人       1.00      0.84      0.91        25
          情侣       0.79      0.79      0.79        19
          祖孙       0.76      0.62      0.68        21
          同门       0.91      0.88      0.89        24
          亲戚       0.83      0.68      0.75        22

   micro avg       0.79      0.79      0.79       592
   macro avg       0.81      0.77      0.79       592
weighted avg       0.80      0.79      0.79       592

  利用Chinese_wwm_ext + 双向GRU + Attention + FC模型,效果如下:

# 训练集(train), loss: 0.0248, acc: 0.9941
# 最终测试集(test),  loss: 0.8795, acc: 0.7956
# 测试集上效果最好的,  loss: 0.7603, acc: 0.8176

  在测试集上的每一类的classification_report如下:

              precision    recall  f1-score   support

     unknown       0.75      0.72      0.73       159
          夫妻       0.79      0.86      0.83        58
          父母       0.84      0.94      0.89        99
        兄弟姐妹       0.72      0.92      0.81        25
         上下级       0.74      0.71      0.72        24
          师生       0.75      0.83      0.79        29
          好友       0.86      0.70      0.78        27
          同学       0.73      0.69      0.71        16
          合作       0.80      0.75      0.78        44
          同人       1.00      0.88      0.94        25
          情侣       0.84      0.84      0.84        19
          祖孙       0.74      0.67      0.70        21
          同门       0.95      0.79      0.86        24
          亲戚       0.80      0.73      0.76        22

   micro avg       0.80      0.80      0.80       592
   macro avg       0.81      0.79      0.79       592
weighted avg       0.80      0.80      0.79       592

  模型预测:

原文: 润生#润叶#不过,他对润生的姐姐润叶倒怀有一种亲切的感情。
预测人物关系: 兄弟姐妹
原文: 孙玉厚#兰花#脑子里把前后村庄未嫁的女子一个个想过去,最后选定了双水村孙玉厚的大女子兰花。
预测人物关系: 父母
原文: 金波#田福堂#每天来回二十里路,与他一块上学的金波和大队书记田福堂的儿子润生都有自行车,只有他是两条腿走路。
预测人物关系: unknown
原文: 润生#田福堂#每天来回二十里路,与他一块上学的金波和大队书记田福堂的儿子润生都有自行车,只有他是两条腿走路。
预测人物关系: 父母
原文: 周山#李自成#周山原是李自成亲手提拔的将领,闯王对他十分信任,叫他担任中军。
预测人物关系: 上下级
原文: 高桂英#李自成#高桂英是李自成的结发妻子,今年才三十岁。
预测人物关系: 夫妻
原文: 罗斯福#特德#果然,此后罗斯福的政治旅程与长他24岁的特德叔叔如出一辙——纽约州议员、助理海军部长、纽约州州长以至美国总统。
预测人物关系: 亲戚
原文: 詹姆斯#克利夫兰#詹姆斯担任了该公司的经理,作为一名**党人,他曾资助过克利夫兰的再度竞选,两人私交不错。
预测人物关系: 上下级
原文: 高剑父#关山月#高剑父是关山月在艺术道路上非常重要的导师,同时关山月也是最能够贯彻高剑父“折中中西”理念的得意门生。
预测人物关系: 师生
原文: 唐怡莹#唐石霞#唐怡莹,姓他他拉氏,名为他他拉·怡莹,又名唐石霞,隶属于满洲镶红旗。
预测人物关系: 同人

  参考文章:

https://www.cnblogs.com/jclian91/p/12328570.html

people_relation_extract's People

Contributors

jclian91 avatar percent4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

people_relation_extract's Issues

数据中###位置超过实体数目的问题

percent4,您好,看了您的仓库,收获非常大,在使用过程中发现了一个问题:

image

数据集中### 表示实体,但是句子中出现了多次实体,导致无法确定实体在句子中的具体位置,请问可以提供原始的文本数据,进行一下筛选么?筛选成每个句子只挖空两个位置,将大于两个位置的句子进行舍弃。

谢谢!

model_predict.py input_1 shape error

I:BERT_VEC:[graph:opt:144]:write graph to a tmp file: ./tmp_graph11
Traceback (most recent call last):
File "model_predict.py", line 48, in
predicted = model.predict(x_train)

ValueError: Error when checking input: expected input_1 to have shape (128, 768) but got array with shape (80, 768)

pip install h5py==2.10

          pip install h5py==2.10

Hello,when I run you code,I meet the problem as follow,can you give me some help?Thank you very much!
line 72, in as_bytes(bytes_or_text,))
TypeError: Expected binary or unicode string, got None

Originally posted by @longkeyy in #9 (comment)

请教下源文件中使用的tensorflow版本号

运行model_train.py时,会报错:module 'tensorflow' has no attribute 'logging',原因是我使用的tensorflow2.0+中没有logging,所以想请问下源文件中的tensorflow版本号

KeyError: 'val_accuracy'

RuntimeWarning: Early stopping conditioned on metric val_accuracy which is not available. Available metrics are: val_loss,val_acc,loss,acc
(self.monitor, ','.join(list(logs.keys()))), RuntimeWarning

bert文件缺失

您好,跑您的代码发现
model_dir = os.path.join(file_path, 'chinese_L-12_H-768_A-12')
config_name = os.path.join(model_dir, 'bert_config.json')
ckpt_name = os.path.join(model_dir, 'bert_model.ckpt')
vocab_file = os.path.join(model_dir, 'vocab.txt')
这些文件代码里面没有

人物实体的位置

使用bert进行特征提取时,需要考虑每个词距离人物实体的相对位置吗。

请教bert的特征提取用法

看文章,知道是用bert来提取特征,但是如何做的呢,我想学习,

还有fine tuning的方法又是如何做的呢,多谢多谢!

博主您好

我已经看了您的几片关于NLP的文章。但是作为一个初学者,实践起来面对您的项目有点不知从何下手。比如训练模型怎么跑通,您有什么建议吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.