如何用大模型RAG做医疗问答系统

代码参考

TLDR

if '疾病症状' in entities and  '疾病' not in entities:
        sql_q = "match (a:疾病)-[r:疾病的症状]->(b:疾病症状 {名称:'%s'}) return a.名称" % (entities['疾病症状'])
        res = list(client.run(sql_q).data()[0].values())
        # print('res=',res)
        if len(res)>0:
            entities['疾病'] = random.choice(res)
            all_en = "、".join(res)
            prompt+=f"<提示>用户有{entities['疾病症状']}的情况,知识库推测其可能是得了{all_en}。请注意这只是一个推测,你需要明确告知用户这一点。</提示>"

根据实体确定图数据库查询语句,从中查询得到结果。疾病症状和知识库查询结果一起组成prompt,输入大模型中

系统设计

在这里插入图片描述

实体识别

  • token classification

意图识别

  • sequence classification

知识图谱

  • graph

对话

搭建知识图谱

实体识别

LLM做的特点

优势
  • they can handle a broad spectrum of entity types;
  • they are highly adaptable to various domains and languages;
  • their performance often surpasses that of traditional rule-based (e.g. regular expressions) or feature-based NER system;
  • they can capture contextual information and context dependencies more effectively (e.g. sentiment analysis or intent detection);
  • LLMs are capable of transfer learning, meaning they can be pre-trained on a general language corpus and fine-tuned for specific NER tasks, thus requiring fewer annotated data points for training.
con
  • LLMs may raise concerns about model bias, model interpretability and ethical considerations, which require careful attention;
  • LLM responses may contain “hallucinations” that can lead to the spread of misinformation;
  • Fine-tuning requires designing appropriate training data, carefully selecting hyper-parameters, and often involves substantial computational resources.
prompt

intent
intent_name_field = ResponseSchema(name=“intent”, description=f"Based on the latest user message, extract the user message intent. Here are some possible labels: ‘greetings’, ‘booking’, ‘complaint’ or ‘other’")

user need
user_need_field = ResponseSchema(name=“user_need”, description=“Rephrase the latest user request and make it a meaningful question without missing any details. Use ‘’ if it is not available”)

user sentiment
sentiment_field = ResponseSchema(name=“sentiment”, description=“Based on the latest user message, extract the user sentiment. Here are some possible labels: ‘positive’, ‘neutral’, ‘negative’, ‘mixed’ or ‘other’”)

number of pizzas to be ordered
n_pizzas_field = ResponseSchema(name=“n_pizzas”, description=“Based on the user need, extract the number of pizzas to be made. Use ‘’ if it is not available”)

### 构建基于RAG的医学问答系统 #### 模型选择 为了构建高效可靠的医学问答系统,可以选择已经经过大规模预训练的语言模型作为基础框架。这些模型具备强大的自然语言理解能力,在此基础上引入检索增强机制(Retrieval-Augmented Generation),使得系统能够更精准地获取并利用外部知识库中的信息[^1]。 对于医学领域而言,建议采用专门针对医疗场景优化过的BERT变体或其他相似结构的大规模预训练模型作为编码器部分;而对于解码端,则可以根据实际需求选用适合对话生成任务的Transformer架构。此外,考虑到医学专业知识的独特性和复杂度,也可以探索使用多模态融合的方式,比如结合iRAG技术,以便更好地处理包含图表、影像资料等内容的问题情境[^2]。 #### 数据集准备 高质量的数据源是确保系统性能的关键所在。为此,需收集整理来自权威渠道发布的临床指南、教科书摘要以及公开可用的真实病例记录等文本材料,并将其转化为适配于所选模型输入格式的知识片段。同时,还应建立配套的问题-答案对集合用于监督学习过程中的微调操作[^3]。 具体来说,可以按照如下原则来进行数据加工: - **清洗过滤**:去除无关噪声项,保留核心诊疗信息; - **标注分类**:依据疾病种类或症状表现给定标签,便于后续索引定位; - **切分重组**:遵循一定逻辑关系将长篇文档拆分成若干短句段落形式,既满足嵌入向量长度约束又兼顾语义连贯性[^5]。 #### 训练流程 整个训练分为两个主要阶段——预训练与精调: - 预训练期间,先让模型接触大量未标记的一般性健康咨询类交流样本,以此积累广泛背景常识; - 进入到细粒度调整环节后,则重点聚焦于特定主题范围内的互动模式识别,即借助前述精心编排好的Q&A实例指导参数更新迭代方向,直至收敛至理想状态为止。在此基础上实施beam search策略以提高最终响应质量[^4]。 值得注意的是,鉴于医学信息安全的重要性,在线部署前还需严格执行隐私保护措施,防止敏感个人信息泄露风险。 #### 应用场景 此类系统适用于多种场合下的辅助决策支持工作,例如在线问诊平台上的即时答疑服务、医院内部信息系统集成模块或是科研人员开展循证研究时的信息检索工具等等。通过提供快速准确的回答反馈,不仅有助于缓解一线医护人员的工作压力,同时也促进了优质医疗服务资源的有效分配。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YueTann

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值