以知识图谱为例,结构化知识大模型的前沿趋势

2023-08-18 15:13 819 阅读 ID:1345
将门
将门

本文探讨了面向结构化知识的预训练语言大模型的前沿趋势,重点关注了结构化知识的核心特色和学习方法,以及大语言模型在利用结构化知识方面的表现。以知识图谱为例,本文介绍了我们在 WWW2023 上发表的论文 KGTransformer,强调了结构知识的可迁移模式。同时,本文还初步验证了大语言模型 GPT-3.5 在知识图谱数据推理方面的局限性,表明大语言模型在结构数据学习方面仍有改进空间。

论文链接:

https://arxiv.org/abs/2303.03922

一、引言

知识是人类社会发展沉淀下来的精华,其表示形式多种多样,知识可以被表示于文本、图片、视频、音频等众多形态中,随着这两年预训练语言模型以及大语言模型的成功,大语言模型的知识表示和推理能力被广泛关注和讨论,其中被讨论较多的是以语言(即文本序列)形式表示的知识,也就是我们常说的非结构化知识,近期,结构化知识如代码、表格、图等在大语言模型中的处理与应用逐渐受到关注和讨论,本文将探讨面向结构化知识的预训练语言大模型前沿趋势,主要尝试探索以下两个问题:

1)对比其他形式的知识如文本序列等,结构化知识的核心特色是什么?结构化知识应该如何被有效地学习?

2)目前广受关注的大语言模型作为基于序列数据训练而得的模型,在利用结构化知识方面表现如何?

本文将以知识图谱为例,对这两个问题展开讨论。针对第一个问题,本文将以我们在WWW2023上发表的论文KGTransformer为例进行介绍,说明结构知识的核心特色在于广泛存在于结构表示中的可迁移的模式。针对第二个问题,本文将介绍我们用GPT-3.5对知识图谱数据进行推理的初步验证,说明大语言模型在结构数据学习方面尚有欠缺。

二、 GTransformer-知识结构预训练与提示调优(WWW2023)

2.1 动机

知识图谱(KG)以(头实体、关系、尾实体)的形式将事实表示为三元组,简称(h,r,t),这是一个用于存储世界上常见知识,例如(地球、位置、内太阳系),的存储方式。近年来,已经构建了Wididata、YAGO和NELL等多个大规模知识图谱,并将其作为背景知识提供者应用于机器学习任务中,如问答、图像分类、视觉推理等。

在为与知识图谱相关的任务设计模型时,关键任务之一是设计知识表示与融合(KRF)模块,该模块从知识图谱中学习元素的表示,并将其与任务表示融合。如图1所示,知识图谱补全模型RotatE通过对复数空间中的实体和关系进行嵌入学习来表示KGs中的知识,并通过得分函数计算三元组的真值。零样本图像分类模型GCNZ使用图卷积网络和ResNet分别学习知识图谱和图像的表示,并通过对齐分类器在知识图谱表示和图像表示上的结果来融合它们。基于知识的问答模型QA-GNN首先对query-kg图进行编码,并将表示与查询表示融合以进行预测。由于需要考虑的知识图谱和视角的不同,在知识图谱相关的任务模型中,KRF模块也存在差异,这给临时的KRF模块设计留下了重复的工作。

为了解决这个问题,预训练的KG模型被提出来学习实体和关系的通用嵌入表示,可以应用于许多任务。这些嵌入被认为包含实体相似性、层次结构和关系等信息,可用于推荐系统、实体对齐、问答等任务,有助于隐式访问知识图谱中的知识。然而,这种方式面临两个挑战:

(1)第一个挑战是,如果任务知识图谱与预训练知识图谱包含不同的实体和关系,则基于嵌入的方法由于嵌入缺失而无法将有价值的信息传递给下游任务模型。

(2)第二个挑战是知识图谱和任务数据之间缺少基本的交互和融合,使得融合模块的设计成为下游任务模型设计的一部分。

因此,基于嵌入的知识图谱模型并不是KRF模块跨知识图谱相关任务的理想解决方案。

KGTransformer通过对KG结构进行预训练,并将与特定实体和关系无关的参数转换到下游任务来解决第一个挑战。本文通过提示调优机制解决第二个挑战,以实现KGs和任务数据之间的统一和灵活融合。

2.2 方法

KGTransformer由多个KGTransformer层组成。该模型以采样的子图的三元组序列作为输入。在KGTransformer层中,根据三元组元素之间的邻接矩阵,允许序列中不同元素进行有限的交互,即具有相同元素(实体或关系)的三元组,在Transformer结构中是可见的。在训练阶段,本文提出一种具有三个自监督任务的子图预训练方法,即掩码实体建模、掩码关系建模和实体对建模。

在下游任务阶段,KGTransformer层中的参数𝜃M有助于将与特定实体和关系无关的图结构知识从预训练KG转移到任务KG。本文提出一种通用的提示调优机制,将每个任务样本作为一个连接在任务KG序列末尾的提示。最后,我们从最后一个KGTransformer层取出一些隐藏状态,并将它们输入到任务层进行预测。此阶段KGTransformer层参数𝜃M被冻结,以保持与预训练期间学习的特定实体和关系无关的图结构知识。

2.3 实验验证

我们在由wn18rr, fb15k-237,codex组成的WFC数据集上对KGTransformer层进行了预训练,并将其应用于三种任务中,包括三元组分类、零样本图片分类、问答,每种任务所使用的任务图谱均不一样。下面为三种任务的实验效果

实验1:三元组分类实验效果

实验2:零样本图片分类实验效果

实验3:问答实验效果

根据以上三种不同任务的实验结果,我们可以得出结论:

(1)在具有不同结构的知识图谱上预训练KGTransformer,使其能够学习知识图谱中的全局图结构知识,而仅基于任务图谱无法充分学习这些知识;

(2)建议用固定参数𝜃M的方式调整预训练的KGTransformer,以更好、更快地保持从预训练的KG中学到的图结构知识并将其迁移到下游任务。

KGTransformer的工作证明了不同的结构数据之间具有共性的可迁移的知识,形象化地描述,结构推理规则、元图模式如环状结构、路径、星状结构等都可以被看作是可迁移的结构知识。虽然结构化表示的对象本身可以通常也可以被表示为序列的文本,例如(中国,首都,北京)这样的三元组可以被表示为“中国的首都是北京”,但是结构化表示的好处是其广泛存在的可迁移的结构模式,这种结构模式是容易被算法挖掘并用于预测推理的。因此充分挖掘和利用结构知识表示中存在的模式,是发挥结构知识优势的核心。

接下来,我们将介绍大语言模型对结构化知识的利用能力如何,我们以GPT-3.5为实验对象,重点针对大语言模型挖掘结构化知识模式展开探索。

三、GPT3.5的结构化知识处理能力评估

这一部分我们尝试使用GPT的in-context learning能力,探索当前的大规模语言模型在理解如知识图谱这样结构化信息的能力。我们首先在一个比较小的Kinship数据集进行探索其链接预测能力(如给定头实体和关系,预测尾实体),我们考虑将实体和关系的周围信息放入pormpt,让LLM尽可能多的理解当前问题中的头实体和关系。但随着知识图谱的增大,实体的周围信息会非常多,很难直接放入prompt中,所以接着我们尝试在一个更大的CoDEx-S数据集上探索,利用类比的方式进行关系预测,利用给定头尾实体间的子图结构预测其关系。

3.1 基于实体和关系周围结构的链接预测

在这个问题下面,我们给定一个知识图谱(如描述亲属关系的Kinship),测试利用LLM回答关于一个链接预测的自然语言问题(如Who is Arthur’s wife?)。

实验设定:

我们使用Kinship数据集(https://archive.ics.uci.edu/dataset/55/kinship),该数据集总共有112条三元组,包含12种家庭关系,例如父亲、母亲、哥哥等。随机分出20%(22条三元组)作为测试,其余的作为背景知识。我们使用gpt-3.5-turbo的API提供LLM能力。我们将该问题分解成多个步骤,包括Parse、Entity Context、Relation Context、Thought和Answer。其中Parse是将自然语言的问句转换成一个三元组的尾实体预测问题,Entity Context提供了问句中头实体的周围两跳三元组,Relation Context提供了问句中关系的一些周围结构,从而让模型对这个关系进行理解。在instruction中我们也做了具体的描述如下:


Imagine you're an explorer on a quest to uncover new connections in a 'Kinship' knowledge graph. The graph's relational set includes: aunt, brother, daughter, father, husband, mother, nephew, niece, sister, son, uncle, and wife.Here's how your quest will unfold:  Parse: Translate a natural language question into an incomplete fact or a triple, like (Entity, Relation, ?).Entity Context: Analyze the two-hop neighbor facts linked to the parsed entity to comprehend its context.Relation Context: Learn about the parsed relation from given examples.Thought: Find useful information from the entity context and relation context to answer the question.Answer: Deliver the final answer to the question.Remember, your aim is to predict new facts using logical reasoning based on the existing facts in the graph. Let the discovery begin!

同时我们也会给出一个具体的例子作为demonstration,如下:


Here is an example:
[Question]
Who is Arthur's wife?

[Parse]
(arthur, wife, ?)

[Entity Context]
arthur: arthur's father is christopher; arthur's mother is penelope; arthur's sister is victoria.
victoria: victoria's brother is arthur; victoria's father is christopher; victoria's daughter is charlotte; victoria's husband is james.
margaret: margaret's husband is arthur; margaret's niece is charlotte; margaret's nephew is colin.
… …

[Relation Context]
Around the fact christopher's wife is penelope, we find penelope's husband is christopher. christopher's son is arthur and arthur's mother is penelope. 
Around the fact andrew's wife is christine, we find christine's husband is andrew. andrew's son is james and james's mother is christine. 
… …

[Thought]
Let's use logical reasoning to think step by step based on entity context and relation context. First, we know from the parsed question we're trying to find out who is Arthur's wife. Looking at the Entity Context, we can see a direct statement that "margaret's husband is arthur". This implies that Margaret is Arthur's wife. Confirming this with the Relation Context, which defines how husband and wife relationships work in the knowledge graph, we see several examples of the reciprocal relationship between husbands and wives. For instance, "christopher's wife is penelope" and "penelope's husband is christopher" - this tells us that if person A is person B's husband, then person B is person A's wife. Therefore, applying this reciprocal rule to the fact "margaret's husband is arthur", we can confidently say that Arthur's wife is Margaret.

[Answer]
Margaret

实验结果:

其中Entity Context和Relation Context表示是否使用了相应的实体和关系周围结构,Surface Form表示是否使用了实体和关系文本信息,如果不使用文本信息,则用编号来代替实体和关系。我们可以看出当同时使用Entity Context和Relation Context的时候,准确率达到0.9。当将Relation Context去掉后,准确率降到0.77,说明LLM并不能完全根据关系的文本信息对关系进行推理,在prompt中添加对关系的结构信息描述可以增强LLM对关系的理解。最后将Surface Form去掉,也就是将原本的文本改为编号后,准确率降为0.55,说明自然语言的表达形式有利于LLM的推理能力的释放。

3.2 基于类比的关系预测

上述3.1中描述的试验方法需要获得问题中头实体的Entity Context(这里取的是周围两跳的三元组信息),这样的方法很难拓展到大规模的知识图谱上。因为在较大的知识图谱中,实体的周围两跳三元组会非常多,很难直接放到LLM中。所以在该问题中,我们考虑给定三元组头尾实体和关系,预测该三元组正确或者错误。因为当头尾实体固定下来后,我们可以根据它们之间的子图结构推断之间的关系,该子图结构远远小于某个实体的两跳周围三元组。

实验设定:

我们使用CoDEx-S数据集(https://github.com/tsafavi/codex),该数据集是从Wikidata中抽取,有32888条训练三元组和1828条测试三元组。我们拿1828条测试三元组的前400条三元组作为正三元组,对每条三元组中的关系进行三次随机替换为其他关系构造负三元组。对于判断每天测试三元组是否正确还是错误的,我们构造了一种基于类比的prompt如下:


Given a state about two entities and their connected paths, return a judgement about the validity (valid/invalid) of the state.
I will give you some examples about valid states and invalid states, and you can use them to compare.
Here are some valid examples:
State:
ENT0 holds citizenship of ENT1
Connected paths between ENT0 and ENT1, as well as their frequencies:
(1 times) ENT0 was born in ENT2, and ENT2 is located in the country ENT1.
(1 times) ENT0 speaks, writes, or signs in the language ENT3, and ENT3 is the official language of ENT1.
(32 times) ENT0 plays the instrument ENT4, and ENT4 is an instrument played by ENT5, and ENT5 holds citizenship of ENT1
(2 times) ENT0 plays the instrument ENT4, and ENT4 is an instrument played by ENT6, and ENT6 resides in ENT1
State:
ENT14 holds citizenship of ENT15
Connected paths between ENT14 and ENT15, as well as their frequencies:
(1 times) ENT14 resides in ENT16, and ENT16 is located in the country ENT15.
(1 times) ENT14 died in ENT16, and ENT16 is located in the country ENT15.
(1 times) ENT14 is employed by ENT17, and ENT17 is located in the country ENT15.
(1 times) ENT14 is a member of ENT17, and ENT17 is located in the country ENT15.
(1 times) ENT14 speaks, writes, or signs in the language ENT18, and ENT18 is the official language of ENT15.
Here are some invalid examples:
State:
ENT43 holds citizenship of ENT44
Connected paths between ENT43 and ENT44, as well as their frequencies:
(1 times) ENT43 holds citizenship of ENT45, and ENT45 has diplomatic relations with ENT44.
(1 times) ENT43 holds citizenship of ENT45, and ENT45 has diplomatic relations with ENT44.
(201 times) ENT43's occupation is ENT46, and ENT46 is the occupation of ENT47, and ENT47 holds citizenship of ENT44
(15 times) ENT43's occupation is ENT46, and ENT46 is the occupation of ENT47, and ENT47 resides in ENT44
(2 times) ENT43's occupation is ENT48, and ENT48 is the occupation of ENT49, and ENT49 is buried in ENT44
State:
ENT59 holds citizenship of ENT60
Connected paths between ENT59 and ENT60, as well as their frequencies:
(2 times) ENT59 holds citizenship of ENT61, and ENT61 has diplomatic relations with ENT60.
(2 times) ENT59 holds citizenship of ENT61, and ENT61 has diplomatic relations with ENT60.
(1 times) ENT59 holds citizenship of ENT62, and ENT62 is located in the continent of ENT63, and ENT63 is the continent where ENT60 is located
(41 times) ENT59 holds citizenship of ENT61, and ENT61 has diplomatic relations with ENT64, and ENT64 has diplomatic relations with ENT60
(44 times) ENT59 holds citizenship of ENT61, and ENT61 has diplomatic relations with ENT64, and ENT64 has diplomatic relations with ENT60
Please return a judgement about the validity (valid/invalid) of the following state by comparing with previous valid and invalid examples.
State:
Gloria Trevi holds citizenship of United States of America
Connected paths between Gloria Trevi and United States of America, as well as their frequencies:
(1 times) Gloria Trevi is signed to the record label Universal Music Group, and Universal Music Group is located in the country United States of America.
(17 times) Gloria Trevi is signed to the record label Universal Music Group, and Universal Music Group is the record label that Wang Leehom is signed to, and Wang Leehom holds citizenship of United States of America
(6 times) Gloria Trevi is signed to the record label Universal Music Group, and Universal Music Group is the parent organization of Def Jam Recordings, and Def Jam Recordings is located in the country United States of America
(1 times) Gloria Trevi is signed to the record label Universal Music Group, and Universal Music Group contains Interscope Records as a part, and Interscope Records is located in the country United States of America
Judgement:
By comparing the connected paths with connected paths of previous valid and invalid examples, we think the validity (valid/invalid) of this state is

在该prompt中,我们给出需要被预测的三元组中的关系的正样本(valid)及相应的子图结构,以及负样本及相应的子图结构,最后给出需要被预测的三元组的描述和子图结构,我们希望LLM根据给出的正负样本,通过类比的方法将需要被预测的三元组进行正确的分类。同时在prompt中对正负样本举例的时候,我们讲具体的实体进行匿名化,让LLM更加专注学习结构信息。

实验结果:

我们首先使用传统的知识图谱表示学习方法TransE进行预测,然后使用我们上面提出的Analogy Prompt,并且使用不同的正负样本数量(如2Pos-2Neg表示两个正样本两个负样本)。可以看出使用LLM相比于传统的TransE在这里并没有优势,并且随着prompt中正负样本的增加,模型的效果并没有有效的提升,说明模型并没有很好的通过正负样本进行类比从而对新的三元组进行推理。

3.3 总结

根据上面的探索实验,我们可以初步得到以下结论:

  • 仅LLM的in-contextlearning能力,其在常见的链接预测任务上总体性能低于TransE这类传统模型。
  • LLM从结构数据中学习新知识的能力较差,在屏蔽掉实体的文本信息之后,LLM的预测能力出现显著下降。
  • LLM的结构类比能力较差,较难从给定的头尾实体间的子图结构归纳总结出关于对于某个关系的预测。

四、总结和展望:结构化知识大模型

本文以知识图谱为例,说明了在结构化数据中广泛存在着可迁移的模式,而LLM挖掘结构化数据模式的能力尚有欠缺,其性能显著弱于传统的知识图谱嵌入模型。LLM基于结构化数据进行推理的难点有以下几个:

(1)缺乏结构数据全局视野,受限于输入的长度,LLM无法感知全局的结构数据;

(2)难以捕捉结构复杂关联,结构数据的依赖和关联关系复杂,相距较远的节点之间可能有巨大的影响,一个节点可能受到多个多阶邻居的综合影响;

(3)受到线性输入输出制约,结构数据的推理具有显著的非线性性,具有一定的层次性和组合性,LLM线性的序列输入输出难以捕捉这类信息。

因此,我们认为有必要研究结构化知识大模型,通过结构化知识指令等方式提升LLM的结构知识感知能力,通过结合外部工具捕捉结构知识的复杂关联,借助联合微调增强LLM的非线性思考能力等。最终实现可以理解多种知识表示方式并具有基于多种知识表示方法进行推理的大模型。

作者:张文、朱渝珊、陈名杨、陈华钧

来源:公众号【ZJUKG】

免责声明:作者保留权利,不代表本站立场。如想了解更多和作者有关的信息可以查看页面右侧作者信息卡片。
反馈
to-top--btn