prettygraph的AI提示工程如何优化系统提示以获得更好的图谱质量【免费下载链接】prettygraphAn experimental UI for text-to-knowledge-graph generation项目地址: https://gitcode.com/gh_mirrors/pr/prettygraphprettygraph是一款实验性的文本转知识图谱生成工具通过AI技术将文本内容自动转换为结构化的知识图谱。本文将分享如何通过优化系统提示来提升prettygraph生成的图谱质量帮助新手用户快速掌握提示工程的核心技巧。为什么系统提示对知识图谱质量至关重要知识图谱的准确性和完整性直接依赖于AI对文本的理解能力。在prettygraph中系统提示system prompt作为AI的操作指南决定了节点抽取、关系识别和图谱构建的整体逻辑。通过精心设计的提示可以引导AI更精准地捕捉文本中的实体和关系避免常见的抽取错误。prettygraph默认系统提示解析在项目核心文件main.py中我们可以看到默认的系统提示定义{ role: system, content: f You are an AI expert specializing in knowledge graph creation with the goal of capturing relationships based on a given input or request. Based on the user input in various forms such as paragraph, email, text files, and more. Your task is to create a knowledge graph based on the input. Nodes must have a label parameter. where the label is a direct word or phrase from the input. Edges must also have a label parameter, wher the label is a direct word or phrase from the input. Respons only with JSON in a format where we can jsonify in python and feed directly into cy.add(data); to display a graph on the front-end. Make sure the target and source of edges match an existing node. Do not include the markdown triple quotes above and below the JSON, jump straight into it with a curly bracket. }这个基础提示已经定义了知识图谱生成的核心规则节点和边的标签必须来自输入文本输出格式为JSON等。优化系统提示的5个实用技巧1. 明确实体类型指导添加实体类型定义可以帮助AI更准确地分类节点。例如Nodes must have a label and type parameter. Types include: person, object, event, concept. Example: {label: Old King Cole, type: person}2. 关系类型规范化为常见关系类型提供示例减少关系标签的歧义Common edge labels include: called for, consists of, had, was. Use only single verbs or verb phrases as edge labels.3. 上下文保留策略指导AI如何处理上下文相关实体When extracting entities, preserve the full context. For example, fiddlers three should be treated as a single node, not separate fiddlers and three.4. 输出格式严格约束增加格式验证规则确保生成的JSON可以直接使用Ensure all nodes have unique IDs. Each edge must have exactly one source and one target node ID that exist in the nodes list.5. 错误处理指令告诉AI如何处理模糊或不确定的关系If relationship is unclear, use related to as edge label and add a confidence property with value between 0.1-0.9.优化前后效果对比上图展示了使用默认系统提示处理童谣文本的结果。左侧为原始文本右侧为生成的知识图谱。可以看到AI成功识别了Old King Cole与pipe、bowl、fiddlers three之间的called for关系以及fiddlers three与fiddler之间的consists of关系。通过应用上述优化技巧我们可以进一步提升图谱质量减少重复节点明确实体类型标准化关系标签提高复杂句子的解析准确率快速开始使用prettygraph要体验优化后的知识图谱生成效果只需克隆仓库git clone https://gitcode.com/gh_mirrors/pr/prettygraph安装依赖poetry install启动应用python main.py在浏览器中访问应用输入文本并查看生成的知识图谱总结优化系统提示是提升prettygraph知识图谱质量的关键。通过明确实体类型、规范关系标签、严格格式约束等技巧即使是新手用户也能显著改善AI的输出结果。随着对提示工程理解的深入你可以根据特定领域需求定制更专业的提示策略充分发挥prettygraph的文本转知识图谱能力。【免费下载链接】prettygraphAn experimental UI for text-to-knowledge-graph generation项目地址: https://gitcode.com/gh_mirrors/pr/prettygraph创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考