摘要
文档级关系抽取旨在从文档中抽取出多个实体对之间的关系,具有较高的复杂性。针对文档级关系抽取中的多实体、关系相关性、关系分布不平衡等问题,提出了一种基于注意力机制(Attention)语义增强的文档级关系抽取方法,能够实现实体对之间关系的推理。具体来说,首先在数据编码模块改进编码策略,引入更多实体信息,通过编码网络捕获文档的语义特征,获得实体对矩阵;然后,设计了一个基于Attention门控机制的U-Net网络,对实体对矩阵进行局部信息捕获和全局信息汇总,实现语义增强;最后,使用自适应焦点损失函数缓解关系分布不平衡的问题。在4个公开的文档级关系抽取数据集(DocRED、CDR、GDA和DWIE)上评估了Att-DocuNet模型并取得了良好的实验结果。
关系抽取任务是信息抽取领域中一项重要的子任务,它对于知识库的构建、文本的理解等都有着很重要的作用,也广泛应用于一些自然语言处理中的课题,如知识问
相较于单句的关系抽取,文档级关系抽取面临着更多的问题。首先是多实体问题,文档中存在多个实体且每个实体可能多次出现,模型需要聚合相同实体的多维度提及,还要识别并关注每个实体的相关上下文。第二是关系类别分布不均衡问题,大多数实体对之间没有关系,即使存在关系也是几种常见的关系类别。第三是实体关系的相关性问题,实体对之间的关系可能存在联系,部分实体关系三元组需要通过逻辑推理得到。举个例子,已知“IBM实验室,位于,南美洲”和“IBM实验室,位于,圣保罗”2个三元组,根据这2个关系三元组的相关性可以推理出“圣保罗,位于,南美洲”。注意到关系的相关性问题并加以利用,可以帮助模型实现更好的关系抽取。
注意到多个关系之间存在相关性,DocuNe
同时,上述的方法都没有针对多实体问题进行改进。Zhou和Che
文档级关系抽取中还存在关系类别不平衡问题,大部分实体对之间不包含关系,包含关系时也大多是几种常见的关系类别。本文引入了一个自适应焦点损失函数,能够平衡关系类别的权重,缓解关系分布不平衡的影响。
以往的关系抽取方法主要集中于识别句子中2个实体之间的关系。许多方
文档级关系抽取的各种方法主要包括基于图的方法和基于Transformer的方法。基于图的方法因为其在关系推理中的有效性,在文档级关系抽取中被广泛采用。Jia
相比之下,Transformer架构利用大量的自注意力机制隐式地建模全局依赖关系。一些研究人员尝试了放弃图形结构,直接利用预训练的语言模型进行文档级关系抽取。Wang
给定包含一组实体的文档,文档级关系抽取任务是预测实体对之间的关系类型,其中和分别表示头实体和尾实体。关系集定义为,其中NR表示无关系。一个实体可能在文档中出现多次,因此对于每个实体,可以被多次提及。如果实体对之间不存在关系,则将其标记为。在测试期间,将会预测所有实体对的分类标签。本质上,这是一个多标签分类问题,因为和之间可能存在多种关系。
如

图 1 Att-DocuNet模型架构
Fig. 1 Architecture of Att-DocuNet
使用预训练模型作为编码器。将文档视为包含个单词的序列,表示第个单词。在实体的编码时添加实体类型信息可以筛选出不可能的关系,例如,2个类型为PER的实体不可能存在“位于”的关系。因此,本文改进实体标记模块,引入实体类型信息。在每个实体提及的开始和结束位置分别插入和,其中表示实体类型,表示实体id。这样一方面添加实体类型信息可以补充相关信息,提高关系抽取性能;另一方面,在文档中一个实体可能多次提及,利用实体id信息可以辅助对齐同一实体中不同提及的信息。
然后,将标记处理后的文档输入预训练语言模型,获得文档中每一个单词的上下文向量表示。
(1) |
式中:表示使用BERT模型进行编码;表示文档中向量表示的集合。
在这之后,使用和的向量的平均值来表示提及的向量,记为。
针对实体,假设其有个提及,第j个提及表示为。参考Zhou
(2) |
更进一步地,针对每一个实体对构造一个实体级关系矩阵。先计算一个基于实体对的上下文表示,它表示实体和共同关注的文档中的上下文。在实体对上下文表示根据仿射变换得到D维特征向量,其计算式为
(3) |
(4) |
(5) |
式中:表示softmax函数计算;是指实体对文档中每个单词的注意力得分;*表示逐元素相乘;是文档的嵌入向量;是可学习的权重矩阵。
将实体级关系矩阵视为一幅通道图像,进一步将文档级关系抽取作为中的像素级分类问题。其中,是从所有数据集样本中计算的最大实体数。为此,本文利用语义分割中的经典模型U-Net,并添加Attention Gate优化分类效果,整合成为Attention-Unet语义增强模块。实体级关系矩阵中的每一个元素就是实体间的关系分类特征,Attention-Une
总而言之,本文使用了一个Attention-Unet语义增强模块,以捕获局部和全局信息,并使用注意力门控机制,帮助模型更好地进行关系分类,如
(6) |
式中:表示使用Attention-Unet语义增强模块进行编码;为实体级关系矩阵;是为了降低的维数而得到的可学习权矩阵。远小于。
给定实体对嵌入和与实体级关系矩阵Y,使用前馈神经网络将它们映射到隐藏表示。然后,通过双线性函数得到关系的概率。具体计算公式为
(7) |
(8) |
(9) |
式中:是矩阵中(s,o)的实体对表示;,,和都是可学习的参数。
针对类别不平衡问题,使用自适应焦点损失函
(10) |
为简单起见,表示为,因为只讨论。对于负类,使用其Logit计算阈值类(TH)的概率,如
(11) |
同样,被称为。由于正面标签的分布高度不平衡,利用焦点损失的概念来平衡正面类别的Logit。最终的损失函数为
(12) |
其中是一个超参数。这一损失函数是为了把更多的注意力放在分数较低、更难分的类上。如果较低,则相关类别的损失权重将更高,从而可以更好地优化长尾类别。
在4个公开的文档级关系抽取数据集上对模型进行评估。数据集统计数据如
指标 | DocRED | CDR | GDA | DWIE |
---|---|---|---|---|
训练集 | 3 053 | 500 | 23 353 | 602 |
验证集 | 1 000 | 500 | 5 839 | 98 |
测试集 | 1 000 | 500 | 1 000 | 99 |
关系类别数 | 97 | 2 | 2 | 65 |
每篇文档实体数 | 19.5 | 7.6 | 5.4 | 27.4 |
每个实体提及数 | 1.4 | 2.7 | 3.3 | 1.98 |
(1)DocRE
(2)CD
(3)GD
(4)DWI
本文模型基于Pytorch实现,在DocRED和DWIE上使用cased-BERT-bas
实验结果如
模型 | 验证集 | 测试集 | ||
---|---|---|---|---|
Ign F1 | F1 | Ign F1 | F1 | |
GEDA-BERTbase | 54.52 | 56.16 | 53.17 | 55.74 |
LSR-BERTbase | 52.43 | 59.00 | 56.97 | 59.05 |
HeterGSAN-BERTbase | 58.13 | 60.18 | 57.12 | 59.45 |
GAIN-BERTbase | 59.14 | 61.22 | 59.00 | 61.24 |
BERTbase | 54.16 | 53.20 | ||
HIN-BERTbase | 54.29 | 56.31 | 53.70 | 55.60 |
ATLOP-BERTbase | 59.22 | 61.09 | 59.31 | 61.30 |
DocuNet-BERTbase | 59.86 | 61.83 | 59.93 | 61.86 |
Att-DocuNet-BERTbase | 60.35 | 62.28 | 60.42 | 62.32 |
(1)基于图的模型:这类模型先对文档建立图结构,再通过GCN进行推理。主要对比的方法包括GED
(2)基于Transformer的模型:这类模型直接使用预训练模型BERT进行文档级关系抽取。对比的方法包括BER
本文模型在训练集和测试集中分别达到62.28%F1和62.32%F1,这分别优于DocuNet模型0.45%F1和0.46%F1。与基于图的方法的最先进模型GAIN模型相比,Att-DocuNet在训练集上超过它1.06%F1,在测试集上超过它1.08%F1。这证明本模型在实体对层次上的推理能力比之前方法更强。
在生物医学数据集CDR和GDA上,本文将模型与众多基线模型进行对比,包括: Eo
模型 | CDR | GDA |
---|---|---|
EoG | 63.6 | 81.5 |
LSR | 64.8 | 82.2 |
DHG | 65.9 | 83.1 |
GLRE | 68.5 | |
SciBERTbase | 65.1 | 82.5 |
ATLOP-SciBERTbase | 69.4 | 83.9 |
DocuNet-SciBERTbase | 76.3 | 85.3 |
Att-DocuNet-SciBERTbase | 76.8 | 86.1 |
本文模型在2个数据集上分别达到76.8%F1和86.1%F1,相较于DocuNet模型提升了0.5%和0.8%,与基于图的模型GLRE相比,在CDR上的性能提升了8.3%。这些结果证明了模型在生物医学领域的良好性能和通用性。
在DWIE数据集上,选择的基线模型包括:GAIN、BERT、ATLOP、DocuNet。实验结果如
模型 | 验证集 | 测试集 | ||
---|---|---|---|---|
Ign F1 | F1 | Ign F1 | F1 | |
GAIN-BERTbase | 55.63 | 62.55 | 62.37 | 67.57 |
BERTbase | 58.40 | 63.38 | 62.92 | 69.12 |
ATLOP-BERTbase | 59.03 | 64.48 | 62.09 | 69.94 |
DocuNet-BERTbase | 61.88 | 67.90 | 64.23 | 70.04 |
Att-DocuNet-BERTbase | 63.91 | 69.20 | 65.49 | 71.40 |
本文模型在训练集和测试集中分别达到69.20%F1和71.40%F1,相较于DocuNet模型提升了1.30%和1.36%,与基于图的方法的最先进模型GAIN模型相比,Att-DocuNet在训练集上超过它5.82%F1,在测试集上超过它3.83%F1。这更全面地证明了本模型在文档级关系抽取任务上的性能优越性。
为了进一步验证每一个模块的有效性,在DocRED数据集上进行了消融实验,实验结果如
模型 | Ign F1 | F1 |
---|---|---|
Att-DocuNet-BERTbase | 60.35 | 62.28 |
w/o Entity Type | 60.01 | 61.95 |
w/o Attention | 59.96 | 61.88 |
w/o Focal Loss | 60.03 | 61.99 |
从
针对文档级关系抽取任务提出Att-DocuNet模型,改进实体标记模块为模型添加实体类型信息,并提出Attention-Unet语义增强模块,引入焦点自适应损失函数,改善文档级关系抽取中的关系相关性问题、类别不平衡问题,实现文档级关系信息的全局汇聚与局部捕获。实验结果表明,与基线模型相比,本文模型可以获得更好的性能。未来希望将本方法应用于其他的分类任务,例如嵌套命名实体识别、多模态关系抽取、远程监督关系抽取等任务。
作者贡献声明
柳先辉:设计框架、技术指导、论文审定。
吴文达:实验研究、论文撰写。
赵卫东:技术指导、论文审定。
侯文龙:技术指导。
参考文献
HAO Y, LIU X, WU J, et al. Exploiting sentence embedding for medical question answering[C] //Proceedings of the AAAI Conference on Artificial Intelligence. Honolulu: AAAI Press, 2019: 938-945. [百度学术]
JI S, PAN S, CAMBRIA E, et al. A survey on knowledge graphs: representation, acquisition, and applications[J]. IEEE Transactions on Neural Networks and Learning Systems, 2021, 33(2): 494. [百度学术]
YAO Y, YE D, Li P, et al. DocRED: A large-scale document-level relation extraction dataset[C]//Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics. Florence : Association for Computational Linguistics, 2019: 764-777. [百度学术]
ZHANG N, CHEN X, XIE X, et al. Document-level relation extraction as semantic segmentation[C]//IJCAI. Montreal: International Joint Conferences on Artificial Intelligence Organization, 2021: 3999–4006. [百度学术]
RONNEBERGER O, FISCHER P, BROX T. U-net: Convolutional networks for biomedical image segmentation[C]//International Conference on Medical Image Computing and Computer-assisted Intervention. Cham: Springer, 2015: 234-241. [百度学术]
ZHOU W, CHEN M. An improved baseline for sentence-level relation extraction[C]//AACL-IJCNLP 2022. [s.l.]: Association for Computational Linguistics, 2022: 161-168. [百度学术]
CHEN X, ZHANG N, XIE X, et al. Knowprompt: Knowledge-aware prompt-tuning with synergistic optimization for relation extraction[C]//Proceedings of the ACM Web Conference 2022. New York: Association for Computing Machinery, 2022: 2778-2788. [百度学术]
ZHENG H, WEN R, CHEN X, et al. PRGC: Potential relation and global correspondence based joint relational triple extraction[C]//Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers). [s.l.]: Association for Computational Linguistics, 2021: 6225-6235. [百度学术]
WEI Z, SU J, WANG Y, et al. A novel cascade binary tagging framework for relational triple extraction[C]//Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics. [s.l.]: Association for Computational Linguistics, 2020: 1476-1488. [百度学术]
JIA R, WONG C, POON H. Document-Level N-ary relation extraction with multiscale representation learning[C]//Proceedings of NAACL-HLT. Minneapolis: Association for Computational Linguistics, 2019: 3693-3704. [百度学术]
CHRISTOPOULOU F, MIWA M, ANANIADOU S. Connecting the dots: Document-level neural relation extraction with edge-oriented graphs[C]//Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP). Hong Kong: Association for Computational Linguistics, 2019: 4925-4936. [百度学术]
NAN G, GUO Z, Sekulić I, et al. Reasoning with latent structure refinement for document-level relation extraction[C]//Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics. [s.l.]: Association for Computational Linguistics, 2020: 1546-1557. [百度学术]
LI B, YE W, SHENG Z, et al. Graph enhanced dual attention network for document-level relation extraction[C]// Proceedings of the 28th International Conference on Computational Linguistics. Barcelona: International Committee on Computational Linguistics, 2020: 1551-1560. [百度学术]
ZHANG Z, YU B, SHU X, et al. Document-level relation extraction with dual-tier heterogeneous graph[C]//Proceedings of the 28th International Conference on Computational Linguistics. Barcelona: International Committee on Computational Linguistics, 2020: 1630-1641. [百度学术]
ZHOU H, XU Y, YAO W, et al. Global context-enhanced graph convolutional networks for document-level relation extraction[C]//Proceedings of the 28th International Conference on Computational Linguistics. Barcelona: International Committee on Computational Linguistics, 2020: 5259-5270. [百度学术]
WANG D, HU W, CAO E, et al. Global-to-local neural networks for document-level relation extraction[C]//Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP). [s.l.]: Association for Computational Linguistics, 2020: 3711-3721. [百度学术]
ZENG S, XU R, CHANG B, et al. Double graph based reasoning for document-level relation extraction[C]//Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP). [s.l.]: Association for Computational Linguistics, 2020: 1630-1640. [百度学术]
XU W, CHEN K, ZHAO T. Document-level relation extraction with reconstruction[C]//Proceedings of the AAAI Conference on Artificial Intelligence. Palo Alto: Assoc Advancement Artificial Intelligence, 2021, 35(16): 14167-14175. [百度学术]
WANG H, FOCKE C, SYLVESTER R, et al. Fine-tune Bert for DocRED with two-step process[J]. arXiv e-prints, 2019: arXiv:1909.11898. [百度学术]
TANG H, CAO Y, ZHANG Z, et al. Hin: Hierarchical inference network for document-level relation extraction[C]//Pacific-Asia Conference on Knowledge Discovery and Data Mining. [s.l.]: Springer,2020: 197-209. [百度学术]
ZHOU W, HUANG K, MA T, et al. Document-level relation extraction with adaptive thresholding and localized context pooling[C]//Proceedings of the AAAI conference on artificial intelligence. Palo Alto: Assoc Advancement Artificial Intelligence, 2021, 35(16): 14612-14620. [百度学术]
OKTAY O, SCHLEMPER J, LE FOLGOC L, et al. Attention U-Net: Learning where to look for the pancreas[J]. arXiv e-prints, 2018: arXiv: 1804.03999. [百度学术]
TAN Q, HE R, BING L, et al. Document-level relation extraction with adaptive focal loss and knowledge distillation[C]//Findings of the Association for Computational Linguistics: ACL 2022. Dublin: Association for Computational Linguistics, 2022: 1672-1681. [百度学术]
LI J, SUN Y, JOHNSON R J, et al. BioCreative V CDR task corpus: a resource for chemical disease relation extraction[J]. Database, 2016, 1: 10. [百度学术]
WU Y, LUO R, LEUNG H, et al. Renet: A deep learning approach for extracting gene-disease associations from literature[C]//International Conference on Research in Computational Molecular Biology. [s.l.]: Springer, 2019: 272-284. [百度学术]
ZAPOROJETS K, DELEU J, DEVELDER C, et al. DWIE: An entity-centric dataset for multi-task document-level information extraction[J]. Information Processing & Management, 2021, 58(4): 102563. [百度学术]
DEVLIN J, CHANG M W, LEE K, et al. BERT: Pre-training of deep bidirectional transformers for language understanding[J]. arXiv e-prints, 2018: arXiv: 1810.04805. [百度学术]
BELTAGY I, LO K, COHAN A. SciBERT: A pretrained language model for scientific text[C]//Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP). Hong Kong: Association for Computational Linguistics,2019: 3615-3620. [百度学术]
LOSHCHILOV I, HUTTER F. Decoupled weight decay regularization[C]//7th International Conference on Learning Representations (ICLR). New Orleans: [S.n.], 2019:1-8. [百度学术]
GOYAL P, DOLLAR P, GIRSHICK R, et al. Accurate, large minibatch SGD: training ImageNet in 1 Hour[J]. arXiv e-prints, 2017: arXiv: 1706.02677. [百度学术]