文章指出,在以前的方法中,使用LLM生成三元组时,必须预定义好schema,假如schema数量很多/复杂,很容易超过LLM的上下文窗口长度。并且,在某些情况下,没有可用的固定预定义schema。
方法 一、EDC框架 提出了一个名为提取-定义-规范化(EDC)的三阶段框架:先进行开放信息提取,然后定义schema,最后进行规范化。解决知识图谱构建问题。
1.开放信息提取(Open Information Extraction): 利用LLMs进行开放信息提取,通过少量的提示,LLMs从输入文本中识别并提取关系三元组([主体, 关系, 对象]),不依赖于任何特定Schema。
OIE Prompt示例:
Givenapieceoftext,extractrelationaltripletsin theformof[Subject,Relation,Object]fromit. Herearesomeexamples: Example1: Text:The17068.8millimeterlongALCORS-3 hasadiesel-electrictransmission. Triplets:[[‘ALCORS-3’,‘powerType’,‘Dieselelectrictransmission’],[‘ALCORS-3’,‘length’, ‘17068.8(millimetres)’]]... Nowpleaseextracttripletsfromthefollowing text:AlanShepardwasbornonNov18,1923 andselectedbyNASAin1959.HewasamemberoftheApollo14crew.提取的三元组:[‘Alan Shepard’, ‘bornOn’, ‘Nov 18, 1923’], [‘Alan Shepard’, ‘participatedIn’, ‘Apollo 14’]
2.Schema定义(Schema Definition): 提示LLMs为提取的Schema组件(如实体类型和关系类型)提供自然语言定义。然后将这些定义作为用于规范化的辅助信息传递到下一阶段。
Schema Definition Prompt示例:
Givenapieceoftextandalistofrelationaltriplets extractedfromit,writeadefinitionforeachrelationpresent. Example1: Text:The17068.8millimeterlongALCORS-3 hasadiesel-electrictransmission. Triplets:[[‘ALCORS-3’,‘powerType’,‘Dieselelectrictransmission’],[‘ALCORS-3’,‘length’, ‘17068.8(millimetres)’]] Definitions: powerType:Thesubjectentityusesthetypeof powerorenergysourcespecifiedbytheobject entity. ... Nowwriteadefinitionforeachrelationpresent inthetripletsextractedfromthefollowingtext: Text:AlanShepardwasanAmericanwhowas bornonNov18,1923inNewHampshire,was selectedbyNASAin1959,wasamemberofthe Apollo14crewanddiedinCalifornia Triplets:[[‘AlanShepard’,‘bornOn’,‘Nov18, 1923’],[‘AlanShepard’,‘participatedIn’,‘Apollo14’]]结果: (bornOn: The subject entity was born on the date specified by the object entity.) and (participatedIn: The subject entity took part in the event or mission specified by the object entity.)
3.Schema标准化(Schema Canonicalization): 第三阶段将开放知识库(KG)精炼成规范化的形式,消除冗余和歧义。首先使用句子变换器对每个schema组件的定义进行向量化,创建嵌入。然后根据目标Schema的可用性,规范化以两种方式之一进行:
目标对齐 (Target Alignment):如果有预定义的目标Schema,识别目标Schema中与每个元素最相关的组件进行标准化。LLMs评估每个潜在转换的可行性,以确保不会过度泛化。自我标准化 (Self Canonicalization):如果没有预定义的目标Schema,目标是合并语义相似(向量相似性)的组件,并将它们标准化为一个单一表示。通过向量和LLM验证来搜索潜在的合并候选者。与目标对齐不同,认为不可转换的组件被添加到规范Schema中,从而扩展它。Schema Canonicalization提示示例:
Givenapieceoftext,arelationaltripletextracted fromit,andthedefinitionoftherelationinit, choosethemostappropriaterelationtoreplaceit inthiscontextifthereisany. Text:AlanShepardwasbornonNov18,1923 andselectedbyNASAin1959.Hewasamember oftheApollo14crew. Triplets:[‘AlanShepard’,‘participatedIn’, ‘Apollo14’] Definitionof‘participatedIn’:Thesubjectentitytookpartintheeventormissionspecifiedbythe objectentity. Choices: A.‘mission’:Thesubjectentityparticipatedin theeventoroperationspecifiedbytheobjectentity. B.‘season’:Thesubjectentityparticipatedinthe seasonofaseriesspecifiedbytheobjectentity. ... F.Noneoftheabove结果:[‘Alan Shepard’, ‘birthDate’, ‘Nov 18, 1923’],[‘Alan Shepard’, ‘mission’, ‘Apollo 14’],构成了规范化的知识图谱。
二、EDC+R:迭代使用Schema检索器精炼EDC EDC+R 是对 EDC 的改进,通过引入一个额外的迭代步骤来进一步提升知识图谱的质量。这个过程类似于RAG ,通过在初始提取阶段的提示(prompt)中提供先前提取的三元组和相关Schema部分来实现。目标是利用从 EDC 过程中产生的数据来提高提取三元组的质量 。
精炼过程由以下两个主要元素组成:
候选实体 :这是之前迭代中由 EDC 提取的实体,以及使用 LLM 从文本中提取的实体。候选关系 :这是之前由 EDC 提取的关系,以及通过训练有素的 Schema Retriever 从预定义/规范化的Schema中检索到的关系。Schema Retriever 的作用:Schema Retriever是可以训练的,Schema Retriever 通过将Schema组件和输入文本投影到向量空间中,使得余弦相似度能够捕捉二者之间的相关性 ,即Schema组件在输入文本中出现的概率。
训练数据集由文本和它们对应的定义关系对组成 。微调的是一个嵌入模型,目标是区分与给定文本相关联的正确关系和其他不相关的关系 。