AI知识库

53AI知识库

学习大模型的前沿技术与行业应用场景


构建知识图谱的双重方法:传统NLP技术或大型语言模型
发布日期:2024-10-09 08:54:19 浏览次数: 1783 来源:知识图谱科技


最近在默沙东制药的内部研讨会分享了一下我们医学图书馆如何利用知识图谱和大模型技术构建文档级别知识图谱和打标签能力并应用于智能知识库建设以及推荐和检索、问答等应用场景。



什么是知识图谱?


from gliner import GLiNER
#Model Initialization
model = GLiNER.from_pretrained("numind/NuNerZero")
#Merging and Displaying Entities
# NuZero requires labels to be lower-cased!
labels=[
"people",
"organizations",
"concepts/terms",
"principles",
"documents",
"dates"
]
labels = [l.lower() for l in labels]
text = content_process
entities = model.predict_entities(text, labels)
entities = merge_entities(entities)
for entity in entities:
print(entity["text"], "=>", entity["label"])

import openai
import json
# Function to generate entities and relationships from the given text using OpenAI's API
def generate_entities_and_relationships(text, api_key):
# Set the OpenAI API key
openai.api_key = api_key
# Create the prompt that will be sent to the OpenAI API.
# The prompt asks the model to identify entities and relationships within the provided text
# and format the response in JSON format.
prompt = f"""
Given the following text, identify the main entities and their relationships:
Text: {text}
Please provide the output in the following JSON format:
{{
"
entities": [
{{"
name": "Entity1", "type": "PersonType"}},
{{"
name": "Entity2", "type": "OrganizationType"}},
...],
"
relationships": [
{{"
subject": "Entity1", "predicate": "works_for", "object": "Entity2"}},
{{"
subject": "Entity2", "predicate": "located_in", "object": "Entity3"}},
...]}}"""

# Send the request to the OpenAI API using the 'gpt-3.5-turbo' model.
# The API call is structured as a chat completion with system and user messages.
response = openai.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant that identifies entities and relationships in text."},
{"role": "user", "content": prompt}
]
)# Extract and clean up the response by removing extra characters or code format markers
result = response.choices[0].message.content.strip().strip('```json').strip().strip('```')
return json.loads(result)


  1. iText2KG:使用大型语言模型构建增量知识图谱

  2. 知识图谱增强大模型GraphRAG全面综述解读 - 蚂蚁集团、北大、浙大、人大等

  3. “大模型+知识图谱”双轮驱动的医药数智化转型新范式-OpenKG TOC专家谈

  4. LLMs用于知识图谱系列之一:将文本以超高速转换为高质量知识图谱

  5. LLMs大模型生成知识图谱系列之二:GPT提示工程创建知识图谱实践

  6. GraphRAG + GPT-4o mini 低成本构建 AI 图谱知识库


53AI,企业落地应用大模型首选服务商

产品:大模型应用平台+智能体定制开发+落地咨询服务

承诺:先做场景POC验证,看到效果再签署服务协议。零风险落地应用大模型,已交付160+中大型企业

联系我们

售前咨询
186 6662 7370
预约演示
185 8882 0121

微信扫码

与创始人交个朋友

回到顶部

 
扫码咨询