Giter Site home page Giter Site logo

entity-recognition-and-relation-extraction's Introduction

实体关系抽取是信息抽取任务中非常基础且必要的工作。实体关系主要有一对一、多对一、多对多等。今天从实践的角度介绍一下实体关系抽取的相关工作。仅为了简单介绍实体关系抽取相关的实践过程,模型我没有进行深度调优,故不适用实际生产中。仅在此介绍下方法,模型主要结构使用的双向GRU网络, 以及BERT。Joint entity recognition and relation extraction as a multi-head selection problem
模型依据论文“Joint entity recognition and relation extraction as a multi-head selection problem”进行改造而成,舍弃了Label Embeddings部分;没有使用CRF层进行实体的识别,主要是没有发现与TF2.0搭配的CRF库,进而用Softmax代替。 (tf2.2可以和Addons中crf搭配使用)

数据来源

百度2019语言与智能技术竞赛信息抽取

模型要求

Tensorflow-gpu=2.0.0 transformers

一、实体关系联合抽取

目的是提取三元组[subject, predicate,object]; 基本简单再简单的原则,实体标签{O:0, B:1, I:2}, 进行subject,object提取; 关系部分,是一个多头选择策略(本文主要也是介绍这种方法),对任一序列,构建[sequence_length, sequence_length]数组,Subject头位置[第N行]对应Object头位置[第M列],该处数字表示第C种关系。

模型一

使用双向GRU构建实体关系联合抽取模型。 使用字向量,首先制作字典,选取前4996个字; 构建模型输入数据,最大长度128,构建文本token,实体label, 关系label; 双向GRU输出+softmax提取实体;双向GRU输出+sigmoid提取关系。

模型使用64000条训练数据,最后对测试集前100进行验证,最大F1值是51%; 主要原因是单靠双向GRU的学习能力不够。

模型二

使用BERT构建实体关系联合抽取模型。 构建模型输入数据,最大长度128,BERT输入又三部分构成[文本token, mask_token, segment_token],实体label, 关系label; BERT输出+softmax提取实体;BERT输出+sigmoid提取关系。

模型使用30000条训练数据,最后对测试集前100进行验证,最大F1值是81.8%; 模型太重,没有取过多数据训练,应该还可以继续提高的。

在模型二的基础上增加label_embeddings层,但模型并没有获得提升,F1值78.9%;猜测原因可能是实体标签(原论文里面包含标签的类型信息)过于简单,损失的信息过多,如此将label_embedding与bert输出结合,并没有起到作用。

二、关系抽取

模型一

不进行实体提取,当做已有实体直接进行关系预测。 使用双向GRU构建关系抽取模型。 使用字向量,首先制作字典,选取前4996个字; 构建模型输入数据,最大长度128,构建文本token,实体label, 关系label;双向GRU输出+sigmoid提取关系。

模型使用64000条训练数据,最后对测试集前100进行验证,关系提取最大F1值是81.8%,跟模型一对比,也验证了单靠双向GRU进行联合。

模型二

使用BERT构建关系抽取模型。 构建模型输入数据,最大长度128,BERT输入又三部分构成[文本token, mask_token, segment_token],实体label, 关系label; BERT输出+sigmoid提取关系。

模型使用30000条训练数据,最后对测试集前100进行验证,模型没有跑完,前10个epoch时,模型F1已经超过85%。

新增模型

A Novel Cascade Binary Tagging Framework for Relational Triple Extraction

A Novel Cascade Binary Tagging Framework for Relational Triple Extraction[ACL_2020],操作上主要是先预测Subject, 然后将关系建模为头实体(Subjects)映射到尾实体(Object)的函数, 进行relation-object同时预测。采用指针标注的方式,可以有效解决多个三元组重叠的实体关系抽取问题。

模型实现程序:Entity_Relationship_version1.py

用BiGru代替了Bert结构(纯粹为了节省时间)

20个epoch,F1值最高68(仅仅用BiGru,数值感觉蛮不错的),感觉还可以迭代下去,loss还可以继续下降。

entity-recognition-and-relation-extraction's People

Contributors

x-jun-0130 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

Watchers

 avatar  avatar

entity-recognition-and-relation-extraction's Issues

预测的脚本

你好,请问预测的脚本有吗,我尝试自己去构建预测函数,对一条文本使用得到的模型去预测实体和关系,但是没有成功

代码疑问

你好,谢谢您提供的代码,我看到您在readme中模型一里说“使用字向量,首先制作字典,选取前4996个字”,在代码里没有看到呢,能解释一下吗?而且我用模型一在自己的数据集,跑出来F1值为0.

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.