文章指出,在以前的方法中,使用LLM生成三元组时,必须预定义好schema,假如schema数量很多/复杂,很容易超过LLM的上下文窗口长度。并且,在某些情况下,没有可用的固定预定义schema。
方法
一、EDC框架
提出了一个名为提取-定义-规范化(EDC)的三阶段框架:先进行开放信息提取,然后定义schema,最后进行规范化。解决知识图谱构建问题。
1.开放信息提取(Open Information Extraction):
利用LLMs进行开放信息提取,通过少量的提示,LLMs从输入文本中识别并提取关系三元组([主体, 关系, 对象]),不依赖于任何特定Schema。
OIE Prompt示例:
Given a piece of text, extract relational triplets in
the form of [Subject, Relation, Object] from it.
Here are some examples:
Example 1:
Text: The 17068.8 millimeter long ALCO RS-3
has a diesel-electric transmission.
Triplets: [[‘ALCO RS-3’, ‘powerType’, ‘Dieselelectric transmission’], [‘ALCO RS-3’, ‘length’,
‘17068.8 (millimetres)’]] ...
Now please extract triplets from the following
text: Alan Shepard was born on Nov 18, 1923
and selected by NASA in 1959. He was a member of the Apollo 14 crew.
提取的三元组:[‘Alan Shepard’, ‘bornOn’, ‘Nov 18, 1923’], [‘Alan Shepard’, ‘participatedIn’, ‘Apollo 14’]
2.Schema定义(Schema Definition):
提示LLMs为提取的Schema组件(如实体类型和关系类型)提供自然语言定义。然后将这些定义作为用于规范化的辅助信息传递到下一阶段。
Schema Definition Prompt示例:
Given a piece of text and a list of relational triplets
extracted from it, write a definition for each relation present.
Example 1:
Text: The 17068.8 millimeter long ALCO RS-3
has a diesel-electric transmission.
Triplets: [[‘ALCO RS-3’, ‘powerType’, ‘Dieselelectric transmission’], [‘ALCO RS-3’, ‘length’,
‘17068.8 (millimetres)’]]
Definitions:
powerType: The subject entity uses the type of
power or energy source specified by the object
entity.
...
Now write a definition for each relation present
in the triplets extracted from the following text:
Text: Alan Shepard was an American who was
born on Nov 18, 1923 in New Hampshire, was
selected by NASA in 1959, was a member of the
Apollo 14 crew and died in California
Triplets: [[‘Alan Shepard’, ‘bornOn’, ‘Nov 18,
1923’], [‘Alan Shepard’, ‘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提示示例:
Given a piece of text, a relational triplet extracted
from it, and the definition of the relation in it,
choose the most appropriate relation to replace it
in this context if there is any.
Text: Alan Shepard was born on Nov 18, 1923
and selected by NASA in 1959. He was a member
of the Apollo 14 crew.
Triplets: [‘Alan Shepard’, ‘participatedIn’,
‘Apollo 14’]
Definition of ‘participatedIn’: The subject entitytook part in the event or mission specified by the
object entity.
Choices:
A. ‘mission’: The subject entity participated in
the event or operation specified by the object entity.
B. ‘season’: The subject entity participated in the
season of a series specified by the object entity.
...
F. None of the above
结果:[‘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组件在输入文本中出现的概率。
训练数据集由文本和它们对应的定义关系对组成。微调的是一个嵌入模型,目标是区分与给定文本相关联的正确关系和其他不相关的关系。
参考文献
- paper:Extract, Define, Canonicalize: An LLM-based Framework for Knowledge Graph Construction,https://arxiv.org/pdf/2404.03868v2
- code:https://github.com/clear-nus/edc