4种通过LLM进行文本知识图谱的构建方法对比介绍

这篇具有很好参考价值的文章主要介绍了4种通过LLM进行文本知识图谱的构建方法对比介绍。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

我们在以前的文章中已经介绍了使用大语言模型将非结构化文本转换为知识图谱。但是对于知识图谱的创建是一个很复杂的过程,比如需要对属性增加限制,创建符合特定主题/模式的图谱,并且有时文档非常大,无法作为单个提示处理,所以在切分后的提示中创建的图谱需要前后一致。

4种通过LLM进行文本知识图谱的构建方法对比介绍,知识图谱,python,人工智能,深度学习,语言模型

所以本文将介绍和比较使用LLM转换非结构化文本的四种方法,这些方法在不同的场景中都可能会用到。

4种通过LLM进行文本知识图谱的构建方法对比介绍,知识图谱,python,人工智能,深度学习,语言模型

使用LLM预训练本体(ontologies)

LLM似乎已经接受了各种标准本体(如SCHEMA)的预先培训。ORG, FOAF, SKOS, RDF, RDFS, OWL等。所以通过适当的系统提示来指导使用这个预训练的本体,再加上包含非结构化文本的用户提示,我们可以获得想要的转换后的图谱结构。

4种通过LLM进行文本知识图谱的构建方法对比介绍,知识图谱,python,人工智能,深度学习,语言模型

提示如下

 Translate the following user text to an RDF graph using the RDF, RDFS, and OWL ontologies formatted as TTL.
 Use the prefix ex: with IRI <http://example.com/> for any created entities.

LLM的相应如下

 @prefix ex: <http://example.com/> .
 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
 @prefix owl: <http://www.w3.org/2002/07/owl#> .
 ex:PeterJones rdf:type ex:Person ;
   rdf:label "Peter Jones" .
 ex:BethHampton rdf:type ex:Person ;
   rdf:label "Beth Hampton" .
 ex:BrunelUniversity rdf:type ex:University ;
   rdf:label "Brunel University" .
 ex:George rdf:type ex:Person ;
   rdf:label "George" .
 ex:James rdf:type ex:Person ;
   rdf:label "James" .
 ex:Harold rdf:type ex:Person ;
   rdf:label "Harold" .
 ex:PeterJones ex:studiedAt ex:BrunelUniversity ;
   ex:marriedTo ex:BethHampton ;
   ex:hasChild ex:George, ex:James, ex:Harold .

对于gpt-3.5-turbo在创建新属性时没有问题。如果我们修改系统提示符,只使用SCHEMA.ORG

 Translate the following user text to an RDF graph using the SCHEMA.ORG ontologies formatted as TTL.
 Use the prefix ex: with IRI <http://example.com/> for any created entities.

也会得到相应的输出

 @prefix ex: <http://example.com/> .
 @prefix schema: <https://schema.org/> .
 
 ex:PeterJones a schema:Person ;
   schema:spouse ex:BethHampton ;
   schema:alumniOf ex:BrunelUniversity .
 
 ex:BethHampton a schema:Person ;
   schema:spouse ex:PeterJones .
   ex:BrunelUniversity a schema:EducationalOrganization .
 
 ex:George a schema:Person .
 ex:James a schema:Person .
 ex:Harold a schema:Person .
 
 ex:PeterJones schema:children ex:George, ex:James, ex:Harold .
 ex:BethHampton schema:children ex:George, ex:James, ex:Harold .

这是最简单的方法,因为我们不需要做任何的操作,完全的使用LLM已经训练好的内容,并且也能得到很好的输出。提示也非常简洁(约41个token),不会占用太多的字符。

但是转换仅限于LLM预先训练过的那些“标准”本体。如果你问ChatGPT是在什么标准本体上进行训练的,他不会给你想要的答案,这样对我们来说就是一个黑盒。并且在文本到图谱的转换中生成的实体还需要在各个图谱之间进行对齐。

在LLM提示中添加本体

4种通过LLM进行文本知识图谱的构建方法对比介绍,知识图谱,python,人工智能,深度学习,语言模型

在大多多情况下,我们希望使用非标准或自定义本体。LLM不太可能在这样的本体上进行预训练,因此我们需要在提示中包含完整的本体。

 Translate the following user text to an RDF graph using the following schema1: <http://inova8.com/schema/1/> ontologies formatted as TTL.
 Use the prefix ex: with IRI <http://example.com/> for any created entities.
 Only use pre-defined classes and properties from the schema1: <http://inova8.com/schema/1/> ontology.
 Use the properties and classes in the schema1: ontology.
 Include individuals, their data, and relationships.
 
 ... the full ontology in TTL format ...

我们需要对转换的内容进行详细的说明,这导致提示token增加到了~3567,使用与之前相同的输入提示,LLM也可以很好地转换文本:

 ex:PeterJones rdf:type schema1:CC ;
   :dc "Peter" ;
   :de "Jones" ;
   :oa ex:BrunelUniversity ;
   :oh ex:BethHampton ;
   :of ex:business .
 ex:BethHampton rdf:type schema1:CC ;
   :dc "Beth" ;
   :de "Hampton" ;
   :oa ex:BrunelUniversity ;
   :oh ex:PeterJones ;
   :of ex:business .
 ex:BrunelUniversity rdf:type schema1:CA ;
   rdfs:label "Brunel University" .
 ex:George rdf:type schema1:CC ;
   rdfs:label "George" ;
   :od ex:PeterJones ;
   :od ex:BethHampton .
 ex:James rdf:type schema1:CC ;
   rdfs:label "James" ;
   :od ex:PeterJones ;
   :od ex:BethHampton .
 ex:Harold rdf:type schema1:CC ;
   rdfs:label "Harold" ;
   :od ex:PeterJones ;
   :od ex:BethHampton .
 ex:PeterJones :oh ex:BethHampton .
 ex:BethHampton :oh ex:PeterJones .

当我们将自定义的内容包含在提示中时,LLM似乎可以理解用RDF、RDFS和OWL表示的本体,并且能够将非结构化文本转换为自定义本体。

但是这导致提示现在非常长,以为系统提示token开销很大。这将增加成本也会减慢响应时间,因为时间与要处理的token成正比。并且这个结果仍然需要对齐。

使用本体进行微调

4种通过LLM进行文本知识图谱的构建方法对比介绍,知识图谱,python,人工智能,深度学习,语言模型

前两种方法的主要问题是局限于预训练的本体,或者在提示中包含自定义本体时开销很大。所以我们可以对LLM进行微调使用KG对LLM进行微调是非常简单的,因为图的本质是三元组:

 {:subject :predicate :object}

我们可以将其映射到提示中进行训练。下面的内容都是可以从图中自动生成的。

 {“messages”: [
   {"role": "system", "content": "Complete the following graph edge"},
   {"role": "user", "content": "What is <:subject> <predicate>?"},
   {"role": "assistant", "content": " <:subject> is <:predicate> <:object>."}]
 }
 …

这个问题就变成了训练LLM将一种语言(非结构化英语文本)翻译成另一种语言(使用微调本体语义的高度结构化rdf图)。

 messages”: [
   {"role": "system", "content": "Translate the following user text to an RDF graph using the Schema1 ontology."},
   {"role": "user", "content": "{example unstructured text}"},
   {"role": "assistant", "content": "{RDF graph using custom Schema1 ontology semantics}"}]
 }
 …

所以问题就变成了创建一个具有代表性的微调训练集(100~200个)和RDF转换集。但是如何设计提示呢?我们来直接问问LLM,因为她最了解自己,哈。

 I want to fine-tune an LLM on this Schema1 ontology. 
 This training aims to take an example user text and the assistant translates it into an RDF graph based on the Schema1 ontology. 
 Please create a comprehensive set of 50 example system, user, and assistant messages in JSONL message conversational chat format format for fine-tuning an LLM to translate text to Schema1 ontology RDF.
 The system content should be the instruction to translate the user text to the assistant RDF graph response using Sxchema1 ontology.
 The user text should be examples that cover all the concepts within the Schema1 ontology.
 The assistant content should be an RDF graph using the Schema1 ontology of the translation of the user text examples.
 Use the prefix ex: with IRI <http://example.com/> for any created entities.
 Use the message format as follows:
   {"messages": [
     {"role": "system", "content": "<system_content>"}, 
     {"role": "user", "content": "<user_content>}, 
     {"role": "assistant", "content": "<assistant_content>"}
   ]}

gpt-3.5-turbo以正确的格式做出了回应。

 {“messages”: [
   {“role”: “system”, “content”: “
       Translate the following user text to an RDF graph using the Schema1 ontology.”}, 
   {“role”: “user”, “content”: “
       John Smith is a professor who graduated from a reputed college.”}, 
   {“role”: “assistant”, “content”: “
       @prefix ex: <http://example.com/> .
       @prefix schema1: <http://inova8.com/schema/1/> .
       ex:JohnSmith rdf:type schema1:CC ;
         schema1:dc \”John\” ;
         schema1:de \”Smith\” ;
         schema1:of schema1:professor ;
         schema1:oa ex:ReputedCollege .
       ex:ReputedCollege rdf:type schema1:CA .”}]}
 
 … and so on

我们来试试效果,使用它生成了一个适当大小的(160)转换调优数据集。使用3和10个epoch对LLM进行了微调。

System-prompt (34 tokens):

 Translate the following user text to an RDF graph using the Schema1 ontology.
 Use the prefix ex: with IRI <http://example.com/> for any created entities.

User-prompt (28 tokens):

 Peter Jones and Beth Hampton both studied at Brunel University, then got married, and have three children: George, James, and Harold.

LLM的结果

 @prefix ex: <http://example.com/> .
 ex:PeterJones a schema1:CC ;
   schema1:dc "Peter" ;
   schema1:de "Jones" ;
   schema1:of schema1:student .
 ex:BethHampton a schema1:CC ;
   schema1:dc "Beth" ;
   schema1:de "Hampton" ;
   schema1:of schema1:student .
 ex:JonesHamptonMarriage a schema1:CG ;
   schema1:og ex:PeterJones ;
   schema1:oh ex:BethHampton .
 ex:GeorgeJones a schema1:CD ;
   schema1:dc "George" ;
   schema1:od ex:PeterJones ;
   schema1:of ex:BethHampton .
 ex:JamesJones a schema1:CD ;
   schema1:dc "James" ;
   schema1:od ex:PeterJones ;
   schema1:of ex:BethHampton .
 ex:HaroldJones a schema1:CD ;
   schema1:dc "Harold" ;
   schema1:od ex:PeterJones ;
   schema1:of ex:BethHampton .

可以看到,工作的还不错,LLM自己给自己上了一课,我们只是动动嘴(手)。另外在质量上3 epoch和10 epoch微调的LLM之间的转换质量似乎没有什么差别。

LLM可以使用自定义本体进行微调,调优LLM的提示可以非常简洁(约41个token),因此大部分token成本由要转换的非结构化文本组成。

但是微调需要度量llm理解自定义本体的准确性和图谱转换的准确性的指标,如何判断好坏就是一个需要仔细研究的问题,我们生成的图谱仍然需要对齐。

改进微调的提示

通常情况下,单个本体/模式不足以捕获文本的完整语义,所以需要使用两个或更多本体。这里的一个好消息是经过微调,LLM并没有忘记预训练的本体,所以我们可以将它们结合使用。

 Translate the following user text to an RDF graph using both the FOAF, and Schema1 ontologies.
 Use the prefix ex: with IRI <http://example.com/> for any created entities.
 Peter Jones and Beth Hampton both studied at Brunel University, then got married, and have three children: George, James, and Harold. 
 Peter, email address peter.jones@inova8.com, has been friends with Paul Williams because of their shared interest in ornithology.

结果如下:

 @prefix ex: <http://example.com/> .
 ex:PeterJones a schema1:Thing, foaf:Person ;
   schema1:email "peter.jones@inova8.com" ;
   foaf:name "Peter Jones" ;
   foaf:interest ex:Ornithology .
 ex:BethHampton a schema1:Thing, foaf:Person ;
   foaf:name "Beth Hampton" .
 ex:GeorgeJones a schema1:Thing, foaf:Person ;
   foaf:name "George Jones" ;
   foaf:maker ex:PeterJones .
 ex:JamesJones a schema1:Thing, foaf:Person ;
   foaf:name "James Jones" ;
   foaf:maker ex:PeterJones .
 ex:HaroldJones a schema1:Thing, foaf:Person ;
   foaf:name "Harold Jones" ;
   foaf:maker ex:PeterJones .
 ex:BrunelUniversity a schema1:Thing, foaf:Document ;
   foaf:name "Brunel University" .
 ex:JonesHamptonMarriage a schema1:Thing ;
   schema1:spouse ex:PeterJones, ex:BethHampton .
 ex:JonesHamptonFamily a schema1:Thing ;
   schema1:parent ex:PeterJones, ex:BethHampton ;
   schema1:child ex:GeorgeJones, ex:JamesJones, ex:HaroldJones .
 ex:PeterJones foaf:knows ex:PaulWilliams .
 ex:PaulWilliams a schema1:Thing, foaf:Person ;
   foaf:name "Paul Williams" .

可以看到,回复中不仅包含了我们微调的结果,还包含了模型预训练时返回的结果

但是这里有一个问题,当同一概念在本体之间重叠时,我们需要控制LLM返回使用哪个。

总结

对于上面几种方法的对比,我们总结了一个图表:

4种通过LLM进行文本知识图谱的构建方法对比介绍,知识图谱,python,人工智能,深度学习,语言模型

llm可以有效地将非结构化文本转换为RDF图。自定义本体微调模型的token效率要高得多,因为它不需要在每个转换请求提示符中提供完整本体的开销,当需要转换多个文本时,这可以降低生产环境中的转换成本。

但是我们还没有提到如何建立文本到KG转换的“准确性”测试,并且转换后如何进行实体对齐,我们将在后面的文章中继续介绍。

https://avoid.overfit.cn/post/486b8b13131641509d0ae4a6ade4156d

作者:Peter Lawrence文章来源地址https://www.toymoban.com/news/detail-809095.html

到了这里,关于4种通过LLM进行文本知识图谱的构建方法对比介绍的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 当大型语言模型(LLM)遇上知识图谱:两大技术优势互补

    大型语言模型(LLM)已经很强了,但还可以更强。通过结合知识图谱,LLM 有望解决缺乏事实知识、幻觉和可解释性等诸多问题;而反过来 LLM 也能助益知识图谱,让其具备强大的文本和语言理解能力。而如果能将两者充分融合,我们也许还能得到更加全能的人工智能。 今天我

    2024年02月02日
    浏览(48)
  • 【知识图谱】深入浅出讲解知识图谱(技术、构建、应用)

    本文收录于《深入浅出讲解自然语言处理》专栏,此专栏聚焦于自然语言处理领域的各大经典算法,将持续更新,欢迎大家订阅! 个人主页:有梦想的程序星空 个人介绍:小编是人工智能领域硕士,全栈工程师,深耕Flask后端开发、数据挖掘、NLP、Android开发、自动化等领域

    2023年04月08日
    浏览(29)
  • 图论|知识图谱——详解自下而上构建知识图谱全过程

    导读:知识图谱的构建技术主要有自顶向下和自底向上两种。其中自顶向下构建是指借助百科类网站等结构化数据源,从高质量数据中提取本体和模式信息,加入到知识库里。而自底向上构建,则是借助一定的技术手段,从公开采集的数据中提取出资源模式,选择其中置信度

    2024年02月04日
    浏览(31)
  • 开源开放 | 开源知识图谱抽取工具发布大模型版DeepKE-LLM

    DeepKE-LLM链接: https://github.com/zjunlp/DeepKE/tree/main/example/llm OpenKG地址: http://openkg.cn/tool/deepke Gitee地址: https://gitee.com/openkg/deepke/tree/main/example/llm 开放许可协议:Apache-2.0 license 贡献者:浙江大学(张宁豫、张锦添、王潇寒、桂鸿浩、姜一诺、陈华钧) 1、背景 DeepKE是一个开源可

    2024年02月09日
    浏览(26)
  • 知识图谱实战应用1-知识图谱的构建与可视化应用

    大家好,今天给大家带来知识图谱实战应用1-知识图谱的构建与可视化应用。知识图谱是一种概念模型,用于表示和组织实体之间的关系,从而实现大规模的语义查询和推理。 一、知识图谱的应用领域 1. 搜索引擎 :知识图谱可以帮助搜索引擎更好地理解用户的搜索查询,提

    2024年02月10日
    浏览(32)
  • 知识图谱实战应用8-从文本关系抽取到知识图谱关系构建流程贯通

    大家好,我是微学AI,今天给大家介绍一下知识图谱实战应用8-从文本关系抽取到知识图谱关系构建流程贯通。我们从文本数据中采集到关键信息,并抽取出其中的关系信息,然后在存入图数据库中,整个过程实现自动化,我这里将举一个文本例子进行抽取。 对于知识图谱的

    2024年02月02日
    浏览(35)
  • 知识图谱构建全流程

    知识图谱,是 结构化的语义知识库 ,用于迅速描述 物理世界 中的 概念 及其 相互关系 ,通过知识图谱能够将Web上的信息、数据以及 链接关系聚集为知识 ,使信息资源更易于计算、理解以及评价,并能实现知识的快速响应和推理。 1.1 广泛应用于各领域 当下知识图谱已在工

    2024年01月22日
    浏览(31)
  • 构建知识图谱的详细步骤

    研究方向是知识图谱,需要整理数据集,所以这里想简单分享一下构建知识图谱的完整步骤,也算记录一下我的学习进程! 网上说的最多的知识图谱构建的步骤就是:知识抽取、知识融合、知识存储 但是在这些步骤之前我们还要先完成 “构建模式、概念本体设计” 两个步骤

    2024年02月12日
    浏览(34)
  • 知识图谱构建流程步骤详解

    (1)实体识别与抽取 任务:识别出待处理文本中七类(人名、机构名、地名、时间、日期、货币和百分比)命名实体。 两个子任务:实体边界识别和确定实体类型。 (2)关系抽取 任务:关系抽取是从文本中抽取出两个或多个实体之间的语义关系。它是信息抽取研究领域的

    2024年01月17日
    浏览(27)
  • 图技术在 LLM 下的应用:知识图谱驱动的大语言模型 Llama Index

    LLM 如火如荼地发展了大半年,各类大模型和相关框架也逐步成型,可被大家应用到业务实际中。在这个过程中,我们可能会遇到一类问题是:现有的哪些数据,如何更好地与 LLM 对接上。像是大家都在用的知识图谱,现在的图谱该如何借助大模型,发挥更大的价值呢? 在本文

    2024年02月15日
    浏览(36)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包