[论文阅读笔记64]A Unified Generative Framework for Various NER Subtasks

39 篇文章 14 订阅

1. 基本信息

题目论文作者与单位来源年份
A Unified Generative Framework for Various NER Subtasks复旦大学,邱锡鹏组ACL2021

13 Citations, 70 References

论文链接: https://arxiv.org/pdf/2106.01223.pdf

论文代码:https://github.com/yhcc/BARTNER

2. 要点

研究主题问题背景核心方法流程亮点数据集结论论文类型关键字
三种实体抽取类型统一模型三种NER任务(一般是分开来解决):
a. flat NER(简单、扁平实体抽取);
b. nested NER(嵌套实体抽取);
c. discontinuous NER(不连续实体抽取)
使用了指针方式,将标注任务转化为一个序列生成任务(本文的主要贡献也正在这里),并使用了 seq2seq 的范式来进行生成,生成过程使用了预训练模型 BART,这是一个利用从被破坏掉的文本中还原文本的任务作为预训练目标的模型。将标注任务转化为一个序列生成任务CoNLL-2003,OntoNotes dataset;ACE 2004,ACE 2005,Genia corpus;CADEC,ShARe13,ShARe14;NER的三大变型任务可以通过brat的生成模型来统一解决。NER,Seq2Seq,BART

3. 模型

3.1 三种典型的NER

flat NER:是比较经典的一种方法,一个字符给一个标注去标出来;

nested NER:方法1:枚举所有可能的跨度,并进行跨度级分类;方法2:运用n. 超图的方法;

可见,基于经典的方法不可能解决nested and discontinuous这两种情况的,对于枚举的跨度方面,解决解discontinuous的情况也是比较困难的;这个方法的算法复杂也是比较高的。

超图虽可以很好在表达,所以span的可能,可是解码还是比较困难的。

discontinuous: transition-discontinuous-ner

[12]An Effective Transition-based Model for Discontinuous NER.md

https://github.com/daixiangau/acl2020-transition-discontinuous-ner

3.2 提出的内容

使用了指针方式,使用将标注任务转化为一个序列生成任务(本文的主要贡献也正在这里),并使用了 seq2seq 的范式来进行生成,生成过程使用了预训练模型 BART,这是一个利用从被破坏掉的文本中还原文本的任务作为预训练目标的模型。

  1. Seq2Seq mode

  1. 编码:

img

把句子转变成向量。

  1. 解码:

每步获取下标概率分布:

img

其中,

img

Index2Token:

img

img

img

TokenEmbed:token嵌入,encoder与decoder共享;

a: 表示超参;

[****· ; **·****]😗*表示在第一个维度并接起来;

**⊗:**表示点乘;

**G_d:**表示tag向量;

从上面的图可以看到,最后的Softmax是两个分布合并之后的,一个是token部分,即H_e,一个是tag部分,即G_d。

  1. 训练阶段: negative log-likelihood loss,the teacher forcing method

  2. 预测阶段:一种自回归的方法来生成目标序列;

  3. 解码算法,将索引序列转换为实体跨度。

img

  1. 基于bart的实体表示:

    原来的表示基于:Byte Pair-Encoding (BPE) tokenization

    BEP算法很简单,它主要是用来寻找字符串中的高频子串的方法。这些子符串是介于word与char之间的subword的内容,这里一般都是说英文。

提出了三种基于指针的实体表示来明确地定位原句子中的实体:Span,BPE,Word

  • Span:实体每个起始点与结束点,若不连续则连着写
  • BPE:所有的Token位置
  • Word:只记录开始位置

img

4. 实验与分析

4.1 Flat的结果

Flat NER: CoNLL-2003,OntoNotes dataset;

img

4.2 Nested情况的结果

Nested NER:ACE 2004,ACE 2005,Genia corpus;

img

4.3 Discontinuous的情况

Discontinuous NER:CADEC,ShARe13,ShARe14;

img

4.4 对论文提出的三种实体表示进行了对比

img

4.5 实体不同表示与预测结果对比

img

4.6 非连续性的单独对比

img

5. 代码

基于fastNLP之上,借用了fitlog工具包。这里记录一下操作过程中与github不一致还未提到的地方。

关于fastNLP的学习文档:http://www.fastnlp.top/docs/fastNLP/index.html

5.1 环境

python 3.6 不可用,后来用了python-3.7.11;

对于fitlog要求要安装git,要不要报错找不到git;

5.2 数据(以conll2003为例)

对于conll2003,具体的路径不用到到父目录,在当前的目录就可以了,要不会找不到的。

DataBundle显示为:

In total 3 datasets:

​ test has 3453 instances.

​ train has 14041 instances.

​ dev has 3250 instances.

5.3 训练

第一次运行会慢一些,要处理数据及下载预训练模型

数据caches: ‘caches/data_facebook/bart-large_conll2003_word.pt’

预测训练模型:1.02G,bart_name = ‘facebook/bart-large’,下载的速度还可以了。

batch_size = 16,产生了显存不足(一张GeForce RTX 2080 Ti );后来设置了batch_size = 8;

结果

max_len_a:0.6, max_len:10
In total 3 datasets:
	test has 3453 instances.
	train has 14041 instances.
	dev has 3250 instances.

The number of tokens in tokenizer  50265
50269 50274
input fields after batch(if batch size is 2):
	tgt_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 8]) 
	src_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 11]) 
	first: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 11]) 
	src_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2]) 
	tgt_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2]) 
target fields after batch(if batch size is 2):
	entities: (1)type:numpy.ndarray (2)dtype:object, (3)shape:(2,) 
	tgt_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 8]) 
	target_span: (1)type:numpy.ndarray (2)dtype:object, (3)shape:(2,) 
	tgt_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2]) 
 ......
 Epoch 16/30:  53%|█████▎    | 34592/64860 [2:50:07<2:13:58,  3.77it/s, loss:0.00078]
Epoch 17/30:  53%|█████▎    | 34592/64860 [2:50:07<2:13:58,  3.77it/s, loss:0.00078]Evaluate data in 58.98 seconds!
Evaluation on dev at Epoch 16/30. Step:34592/64860: 
Seq2SeqSpanMetric: f=92.80000000000001, rec=93.28999999999999, pre=92.33, em=0.8784
......
......
......
Epoch 23/30:  77%|███████▋  | 49726/64860 [4:08:28<50:44,  4.97it/s, loss:0.00012]
                                                                                  

Epoch 23/30:  77%|███████▋  | 49726/64860 [4:08:28<50:44,  4.97it/s, loss:0.00012]
......
......                                                                                  
......
Epoch 23/30:  77%|███████▋  | 49726/64860 [4:08:28<50:44,  4.97it/s, loss:0.00012]
Epoch 24/30:  77%|███████▋  | 49726/64860 [4:08:28<50:44,  4.97it/s, loss:0.00012]Evaluate data in 58.7 seconds!
Evaluation on dev at Epoch 23/30. Step:49726/64860: 
Seq2SeqSpanMetric: f=92.84, rec=93.4, pre=92.28, em=0.8769
......
......
.......
Evaluate data in 56.74 seconds!
Evaluation on dev at Epoch 30/30. Step:64860/64860: 
Seq2SeqSpanMetric: f=93.07, rec=93.58999999999999, pre=92.56, em=0.8798


In Epoch:25/Step:54050, got best dev performance:
Seq2SeqSpanMetric: f=93.13, rec=93.57, pre=92.69, em=0.881
    

大概跑了5个多小时,结果为r:93.57,p:92.69,f=93.13,跟论文的r=93.87,p=92.62,f=93.24差不多。

关于CADEC语料复现实验

首先要参考之前的一篇论文:An Effective Transition-based Model for Discontinuous NER.pdf

代码: https://github.com/daixiangau/acl2020-transition-discontinuous-ner

找到预测处理代码:

img

查看build_data_for_transition_discontinuous_ner.sh文件,按照这个脚本来修改一下目录就可以可以生成数据了,完成操作数据输出样子为(与论文要求的一样了):

During this time I experienced extreme pain in both shoulders , sometimes in the neck also , causing me to wake several times each night .
5,7,14,14 ADR|5,9 ADR

Pain was worse in the morning but rarely went away completely during the day .
0,2 ADR

Most mornings it was impossible to wash my hair in the shower as I was unable to reach the top of my head with my hands .
15,25 ADR

Pain and restricted movement often prevented me from putting on shoes and socks without assistance .
0,0 ADR|2,3 ADR

In January this year I started experiencing discomfort in my left hand for the first time .
7,11 ADR

回到bartenr项目中,找一个目录放好就可以了。后面跑的时候**注意一下路径**是否正确就OK了。

在训练过程中,发现显示会有所增加,后来设置为4方向顺利训练完,运行的结果如下显示:

运行的结果为:

Evaluate data in 128.07 seconds! s:0.00010]

Evaluation on dev at Epoch 30/30. Step:40050/40050: 3.05it/s]

Seq2SeqSpanMetric: f=68.44, rec=68.93, pre=67.95, em=0.7885

Best test performance(may not correspond to the best dev performance):{‘Seq2SeqSpanMetric’: {‘f’: 70.72, ‘rec’: 69.39, ‘pre’: 72.09, ‘em’: 0.7784}} achieved at Epoch:12.

Best test performance(correspond to the best dev performance):{‘Seq2SeqSpanMetric’: {‘f’: 68.60000000000001, ‘rec’: 66.97, ‘pre’: 70.30999999999999, ‘em’: 0.7681}} achieved at Epoch:17.

In Epoch:17/Step:22695, got best dev performance:

Seq2SeqSpanMetric: f=69.97, rec=70.04, pre=69.89, em=0.8013

f=69.97, rec=70.04, pre=69.89与论文报告的也是很相近的。

6. 总结

看完了,一篇不错的文章,加上最近也又在思考能通过生成模型去实现非连接实体,很幸运也很偶尔给我遇上了它。

解决目标比较明确,提出了一套解决了三个典型的NER典型任务的统一方法。

7. 知识整理(知识点,文献分类,摘取原文)

8. 参考文献

made by happyprince

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值