LLM 已经展示了将非结构化文本转化为知识图谱的能力。不过,我看到的大多数例子都允许 LLM 决定使用什么本体/模式。有些例子还增加了使用哪些属性的限制。我想创建符合特定本体/模式的图,原因如下:
使用 LLM 将非结构化文本转换为 KG
我想对四种使用 LLM 转换非结构化文本的方法进行描述和比较,并用符合预定义本体的 KG 进行响应:
方法 1:使用预训练本体的 LLM
LLM 似乎已经在各种标准本体(如 SCHEMA.ORG、FOAF、SKOS、RDF、RDFS、OWL 等)上进行过预先训练。因此,只要有一个合适的系统提示,指示使用这些预先训练好的本体,再加上一个包含非结构化文本的用户提示,我们就能得到想要的转换图。
预先训练好的本体系统提示将说明
实际的系统提示如下
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.
该系统提示使用 ~41 个令牌。
相应的用户提示提供:
例如,我将使用的用户提示是
Peter Jones and Beth Hampton studied at Brunel University, then married, and had three children: George, James, and Harold.
该用户提示使用 ~26 个令牌。
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 .
请注意,LLM(本例中为 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.
LLM 的辅助响应尽可能使用正确的模式类和属性:
@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 .
优点:
缺点
- 我曾试着礼貌地询问 ChatGPT 在哪些标准本体上进行过训练,但得到的答案可以说是闪烁其词。
方法 2:用本体提示 LLM
在很多情况下,我们需要使用非标准或自定义本体。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 ...
我们立刻就会发现,即使是这样一个规模不大的本体,也会将系统提示标记数大大增加到 ~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(如 GPT-4)在创建婚姻的二阶(多对多)概念方面做得更好。
缺点:
- 这将增加成本,因为成本与处理的令牌成正比。
- 这会减慢响应时间,因为时间与需要处理的标记成正比。
方法 3:使用本体对LLM进行微调
局限于预先训练好的本体,或者在系统提示中加入自定义本体时会产生标记开销,这些都是前两种方法存在的重大问题。
我们知道,受过良好训练的 LLM 可以理解本体,并且 LLM 可以利用这种理解来转换非结构化文本。因此,在其他本体上训练 LLM 应该是可能的。遗憾的是,我的预算不足以进行全面训练,但微调却完全在我的能力范围之内。然而,这就产生了创建一个合适的调整数据集的问题。
在以前的论文中,知识图谱+大型语言模型=用户提出自己问题的能力?和大型语言模型=知识图谱存储?是的,通过用知识图谱微调 LLM,我展示了用图谱微调 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 图)。
利用其他地方已经使用过的语言翻译数据集示例,我需要创建一个具有合适内容的数据集,例如以下内容:
样本系统提示: "使用 Schema1 本体将以下用户文本翻译成 RDF 图形"。
示例用户提示:"{非结构化文本示例}"
示例助手响应:"{使用自定义 Schema1 本体语义的 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。
微调数据集生成器:使用本体模板
回溯根源,我的第一种方法是从本体的 "片段 "中通过算法生成非结构化文本。
例如,根据以下对象属性 “fragment”
:of
rdf:type owl:ObjectProperty ;
rdfs:domain :CC ;
rdfs:label "has profession" ;
rdfs:comment "The people who do a particular type of work, considered as a group.
Any type of work that needs special training or a particular skill, often one that is respected because it involves a high level of education" ;
rdfs:range :CF .
以下用户 "非结构化 "文本是使用以下模板生成的。
{randomDomainInstance},
which is a {synonymDomainLabel},
has {synonymPropertyLabel} {randonRangeInstance},
which is a {synonymRangeLabel}.
算法生成用户文本的实际例子如下:
EpentheticShowed,
which is a Person,
has profession ShelffulKnuckleheads,
which is a Profession.
成为使用以下模板合成的 RDF 样本助理回复:
ex:{randomDomainInstance} rdf:type {domain} ;
rdfs:label {randomDomainInstance}
{property} ex:{randonRangeInstance} .
ex:{randonRangeInstance} rdf:type {range} ;
rdfs:label {randomRangeInstance} .
{domain} rdfs:label {domainLabel} .
{range} rdfs:label {rangeLabel} .
{property} rdfs:label {propertyLabel} .
算法生成的辅助文本的实际示例如下:
ex:EpentheticShowed a :CC ;
rdfs:label "EpentheticShowed" ;
:of ex:ShelffulKnuckleheads .
ex:ShelffulKnuckleheads a :CF ;
rdfs:label "ShelffulKnuckleheads" ;
:CC rdfs:label "Person" .
:CF rdfs:label "Profession" .
:of rdfs:label "has profession" .
算法调整数据集生成结论
既然结果如此糟糕,那么在这里介绍这种方法还有什么意义呢?失败也是学习的机会。回顾样本数据集,生成的文本在语法上是正确的,因为它是结构正确的英语。但是,它在语义上还可以更有意义。
我的结论是
EpentheticShowed,
which is a Person,
has profession ShelffulKnuckleheads,
which is a Profession.
与更有意义的调整示例相差太远:
Peter,
who is a Person,
has a profession Developer,
which is a Profession.
微调数据集生成器:向LLM请教
我的算法失败了。怎样才能从本体中创建有意义的示例呢?答案就在眼前:询问 LLM!生成合适的调整示例的要求如下:
系统提示包含我们希望 LLM 执行的角色,即从文本到图形的翻译角色,还包括我们希望 LLM 调谐的 RDF TTL 本体。
因此,我们使用的系统提示是(不包括本体的全文):
You are a helpful assistant who will use the :Schema1 ontology that follows.
This schema is called :Schema1 with IRI <http://inova8.com/schema/1/>
…. ontology in TTL ….
用户提示告诉 LLM,我们希望对 LLM 进行微调,我们需要用户文本示例以及 RDF 图形,以便将其翻译成 RDF 图形。
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>"}
]}
正如所希望的那样,LLM按照要求提供了微调示例。不仅如此,LLM还以正确的格式做出了回复。
{“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 个历时对 LLM 进行了微调。
质疑微调后的 LLM
任何事情都是吃出来的。向微调后的 LLM 提交同样的请求,翻译一段非结构化文本,结果与我们预期的一样。成功!
系统提示(34 个 token):
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.
用户提示(28 个 token):
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 .
请注意,至少从质量上看,3 个时相和 10 个时相微调 LLM 的翻译质量似乎差别不大。
优点:
缺点:
方法 4:微调和预训练的混合方法
通常情况下,单一本体/模式不足以捕捉文本的全部语义。因此,我们可能需要使用两个或多个本体。幸运的是,如下例所示,使用自定义本体对 LLM 进行微调似乎并没有导致它忘记 FOAF 等预训练本体。
系统提示,现在同时引用预训练和微调过的本体:
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.
而LLM的辅助响应则使用了这两种本体:
@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的提示和回答放在本文正文中会使阅读变得困难。因此,我将提示包含在本文中,并在正文中留下提示说明。
方法 1:使用预训练本体的 LLM
使用RDF、RDFS和OWL本体进行文本到图的翻译请求
RDF、RDFS和OWL系统提示
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.
RDF、RDFS 和 OWL 用户提示
Peter Jones and Beth Hampton studied at Brunel University, then married, and had three children: George, James, and Harold.
RDF、RDFS 和 OWL 助理响应
@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 .
使用 SCHEMA.ORG 进行文本到图形翻译的请求
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.
SCHEMA.ORG 用户提示
Peter Jones and Beth Hampton studied at Brunel University, then married, and had three children: George, James, and Harold.
SCHEMA.ORG 助理回应
@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 .
方法 2:使用本体提示 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.
@prefix : <http://inova8.com/schema/1/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema1: <http://inova8.com/schema/1/> .
@base <http://inova8.com/schema/1/> .
<http://inova8.com/schema/1/> rdf:type owl:Ontology .
#################################################################
# Object Properties
#################################################################
### http://inova8.com/schema/1/oa
schema1:oa rdf:type owl:ObjectProperty ;
rdfs:domain schema1:CC ;
rdfs:range schema1:CA ;
rdfs:comment """The university, school, or college that one formerly attended.
\"he started teaching at his alma mater\"""" ;
rdfs:label "alma mater" .
### http://inova8.com/schema/1/ob
schema1:ob rdf:type owl:ObjectProperty ;
rdfs:domain schema1:CC ;
rdfs:range schema1:CC ;
rdfs:comment "Inverse of 'parent'" ;
rdfs:label "child" .
…
#################################################################
# Data properties
#################################################################
### http://inova8.com/schema/1/da
schema1:da rdf:type owl:DatatypeProperty ;
rdfs:domain schema1:CC ;
rdfs:range xsd:int ;
rdfs:comment "The day they were born, shown in numbers, or words and numbers" ;
rdfs:label "year of birth" .
### http://inova8.com/schema/1/db
schema1:db rdf:type owl:DatatypeProperty ;
rdfs:domain schema1:CC ;
rdfs:range xsd:int ;
rdfs:comment "The day they died, shown in numbers, or words and numbers" ;
rdfs:label "year of death" .
### http://inova8.com/schema/1/dc
schema1:dc rdf:type owl:DatatypeProperty ;
rdfs:domain schema1:CC ;
rdfs:range xsd:string ;
rdfs:comment "The name that was given to you when you were born and that comes before your family name:" ;
rdfs:label "first name" .
…
#################################################################
# Classes
#################################################################
### http://inova8.com/schema/1/CA
schema1:CA rdf:type owl:Class ;
rdfs:subClassOf owl:Thing ;
rdfs:label "College" .
…
### http://inova8.com/schema/1/CF
schema1:CF rdf:type owl:Class ;
rdfs:subClassOf owl:Thing ;
rdfs:label "Profession" .
### http://inova8.com/schema/1/CG
schema1:CG rdf:type owl:Class ;
rdfs:subClassOf owl:Thing ;
rdfs:label "Marriage" .
#################################################################
# Individuals
#################################################################
### http://inova8.com/schema/1/Lt-governor
schema1:Lt-governor rdf:type owl:NamedIndividual ,
schema1:CF ;
rdfs:label "Lt-governor" .
### http://inova8.com/schema/1/PR
schema1:PR rdf:type owl:NamedIndividual ,
…
schema1:CF ;
rdfs:label "PR" .
提供本体用户提示
Peter Jones and Beth Hampton studied at Brunel University, then married, and had three children: George, James, and Harold.
提供本体助理响应
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 .
方法 3:利用本体对 LLM 进行微调
微调示例请求
微调示例请求 系统提示
You are a helpful assistant who will use the :Schema1 ontology that follows. This schema is called
:Schema1 with IRI <http://inova8.com/schema/1/>
…. ontology in TTL ….
调整示例请求用户提示
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>"}]}
调整示例请求助理响应
{“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/> .\n@prefix schema1: <http://inova8.com/schema/1/> .\nex:JohnSmith rdf:type schema1:CC ;\nschema1:dc \”John\” ;\nschema1:de \”Smith\” ;\nschema1:of schema1:professor ;\nschema1:oa ex:ReputedCollege .\nex:ReputedCollege rdf:type schema1:CA .”}
]
}
… and so on
使用微调 LLM 进行文本到图的翻译请求
微调本体系统提示
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.
微调本体用户提示
Peter Jones and Beth Hampton both studied at Brunel University, then got married, and have three children: George, James, and Harold.
微调本体助理响应
@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
方法 4:微调和预训练的混合方法
使用微调 LLM 和 FOAF 进行文本到图翻译的请求
混合系统提示
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" .