本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
将 Amazon Comprehend Medical 与大型语言模型相结合
NEJM AI在2024年进行的一项研究
-
使用亚马逊 Comprehend Medical 的初始结果作为法学硕士学位的背景,提高实体选择的准确性
-
实现自定义实体识别、摘要、问答和其他用例
本节介绍如何使用检索增强生成 (RAG) 方法将 Amazon Comprehend Medical 与 LLM 相结合。检索增强生成 (RAG) 是一种生成式人工智能技术,其中法学硕士在生成响应之前引用其训练数据源之外的权威数据源。有关更多信息,请参阅什么是 RAG
为了说明这种方法,本节使用了与 ICD-10-CM 相关的医疗(诊断)编码示例。它包括示例架构和快速工程模板,可帮助您加快创新。它还包括在 RAG 工作流程中使用 Amazon Comprehend Medical 的最佳实践。
基于 RAG 的架构,采用亚马逊 Comprehend Medical
下图说明了一种从患者记录中识别 ICD-10-CM 诊断代码的 RAG 方法。它使用亚马逊 Comprehend Medical 作为知识来源。在 RAG 方法中,检索方法通常从包含适用知识的矢量数据库中检索信息。该架构不是向量数据库,而是使用 Amazon Comprehend Medical 来执行检索任务。协调员将患者病历信息发送到 Amazon Comprehend Medical 并检索 ICD-10-CM 代码信息。协调器通过 Amazon Bedrock 将此上下文发送到下游基础模型 (LLM)。LLM 使用 ICD-10-CM 代码信息生成响应,并将该响应发送回客户端应用程序。

该图显示了以下 RAG 工作流程:
-
客户端应用程序将患者笔记作为查询发送给协调员。这些患者笔记的一个例子可能是:“患者是X医生的71岁女性患者。该患者昨晚被送往急诊室,有大约7天至8天的腹痛史,这种病史一直持续存在。她没有明显的发烧或发冷,也没有黄疸病史。患者否认最近有任何明显的体重减轻。”
-
协调器使用 Amazon Comprehend Medical 检索与查询中的医疗信息相关的 ICD-10-CM 代码。它使用 Infer ICD1 0CM API 从患者笔记中提取和推断 ICD-10-CM 代码。
-
协调器构造一个提示,其中包括提示模板、原始查询和从 Amazon Comprehend Medical 检索到的 ICD-10-CM 代码。它将此增强的背景信息发送给 Amazon Bedrock。
-
Amazon Bedrock 处理输入并使用基础模型生成响应,其中包含 ICD-10-CM 代码及其相应查询证据。生成的响应包括已识别的 ICD-10-CM 代码和患者记录中支持每种代码的证据。以下为示例响应:
<response> <icd10> <code>R10.9</code> <evidence>history of abdominal pain</evidence> </icd10> <icd10> <code>R10.30</code> <evidence>history of abdominal pain</evidence> </icd10> </response>
-
Amazon Bedrock 将生成的响应发送给协调器。
-
协调器将响应发送回客户端应用程序,用户可以在其中查看响应。
在 RAG 工作流程中使用 Amazon Comprehend Medical 的用例
Amazon Comprehend Medical 可以执行特定的 NLP 任务。有关更多信息,请参阅 Amazon Comprehend Medical 的用例。
您可能需要将 Amazon Comprehend Medical 集成到 RAG 工作流程中,以用于高级用例,例如:
-
通过将提取的医疗实体与患者记录中的情境信息相结合,生成详细的临床摘要
-
使用带有本体关联信息的提取实体进行代码分配,从而自动对复杂案例进行医学编码
-
使用提取的医疗实体,自动从非结构化文本创建结构化临床笔记
-
根据提取的药物名称和属性分析药物副作用
-
开发智能临床支持系统,将提取的医疗信息与 up-to-date研究和指南相结合
在 RAG 工作流程中使用 Amazon Comprehend Medical 的最佳实践
在将 Amazon Comprehend Medical 成绩整合为法学硕士学位的提示时,必须遵循最佳实践。这可以提高性能和准确性。以下是主要建议:
-
了解 Amazon Comprehend Medical 置信度分数 — Amazon Comprehend Medical 为每个检测到的实体和本体关联提供置信度分数。理解这些分数的含义并为您的特定用例设定适当的阈值至关重要。置信度分数有助于过滤掉低可信度的实体,从而减少噪音并提高法学硕士输入的质量。
-
在@@ 即时工程中使用信心分数 — 在起草法学硕士学位的提示时,可以考虑将 Amazon Comprehend Medical 置信度分数作为其他背景。这有助于法学硕士根据实体的置信度对实体进行优先级排序或权衡,从而有可能提高产出的质量。
-
使用实况数据评估 Amazon Comprehend Medical 的结果 — 实况数据是已知真实的信息。它可用于验证 AI/ML 应用程序是否产生了准确的结果。在将 Amazon Comprehend Medical 结果整合到您的法学硕士工作流程之前,请根据具有代表性的数据样本评估该服务的性能。将结果与事实注释进行比较,以确定潜在的差异或需要改进的领域。此评估可帮助您了解亚马逊 Comprehend Medical 在您的用例中的优势和局限性。
-
策略性地选择相关信息 — Amazon Comprehend Medical 可以提供大量信息,但并非所有信息都可能与您的任务相关。仔细选择与您的用例最相关的实体、属性和元数据。向 LLM 提供过多的无关信息可能会带来噪音,并可能降低性能。
-
调整实体定义 — 确保 Amazon Comprehend Medical 使用的实体和属性的定义与您的解释一致。如果存在差异,可以考虑向法学硕士提供额外的背景信息或澄清,以弥合亚马逊 Comprehend Medical 的产出与您的要求之间的差距。如果 Amazon Comprehend Medical 实体未达到您的期望,您可以通过在提示中添加其他说明(和可能的示例)来实现自定义实体检测。
-
提供特定领域的知识 — 虽然 Amazon Comprehend Medical 提供了宝贵的医疗信息,但它可能无法捕捉到您特定领域的所有细微差别。考虑在 Amazon Comprehend Medical 结果中补充其他特定领域的知识来源,例如本体论、术语或专家精心策划的数据集。这为法学硕士提供了更全面的背景信息。
-
遵守道德和监管准则 — 在处理医疗数据时,必须遵守道德原则和监管准则,例如与数据隐私、安全和在医疗保健中负责任地使用人工智能系统相关的道德原则和监管准则。确保您的实施符合相关法律和行业最佳实践。
通过遵循这些最佳实践,人工智能/机器学习从业者可以有效地利用亚马逊Comprehend Medical和的优势。 LLMs对于医疗 NLP 任务,这些最佳实践有助于降低潜在风险并提高绩效。
为亚马逊 Comprehend Medical 环境进行及时的工程设计
P@@ rompt Engineering 是设计
根据您执行的 API 操作,Amazon Comprehend Medical 会返回检测到的实体、本体代码和描述以及置信度分数。当您的解决方案调用目标 LLM 时,这些结果将成为提示中的上下文。您必须设计提示以在提示模板中呈现上下文。
注意
本节中的示例提示遵循了 Anthropic 的指导
通常,您需要在提示中同时插入原始医学文本和亚马逊 Comprehend Medical 结果。以下是常见的提示结构:
<medical_text> medical text </medical_text> <comprehend_medical_text_results> comprehend medical text results </comprehend_medical_text_results> <prompt_instructions> prompt instructions </prompt_instructions>
本节提供了将 Amazon Comprehend Medical 结果作为以下常见医疗 NLP 任务的即时上下文的策略:
筛选亚马逊 Comprehend Medical 结果
Amazon Comprehend Medical 通常会提供大量信息。您可能需要减少医疗专业人员必须审查的结果数量。在这种情况下,您可以使用 LLM 来筛选这些结果。Amazon Comprehend Medical 实体包括置信度分数,您可以在设计提示时将其用作筛选机制。
以下是患者笔记示例:
Carlie had a seizure 2 weeks ago. She is complaining of frequent headaches Nausea is also present. She also complains of eye trouble with blurry vision Meds : Topamax 50 mgs at breakfast daily, Send referral order to neurologist Follow-up as scheduled
在这份患者记录中,Amazon Comprehend Medical 检测到以下实体。

这些实体链接到以下 ICD-10-CM 用于癫痫发作和头痛的代码。
类别 | ICD-10-CM 代码 | ICD-10-CM 描述 | 置信度分数 |
---|---|---|---|
发作 | R56.9 | 未指明的抽搐 | 0.8348 |
发作 | G40.909 | 癫痫,未指明,不可治愈,无癫痫持续状态 | 0.5424 |
发作 | R56.00 | 单纯性发热性惊厥 | 0.4937 |
发作 | G40.09 | 其他癫痫发作 | 0.4397 |
发作 | G40.409 | 其他全身性癫痫和癫痫综合征,非难治性,无癫痫持续状态 | 0.4138 |
头痛 | R51 | 头痛 | 0.4067 |
头痛 | R51.9 | 头痛,未指明 | 0.3844 |
头痛 | G44.52 | 新的每日持续性头痛 (NDPH) | 0.3005 |
头痛 | G44 | 其他头痛综合症 | 0.2670 |
头痛 | G44.8 | 其他指定的头痛综合征 | 0.2542 |
您可以将 ICD-10-CM 代码传递到提示符中以提高 LLM 精度。为了减少噪音,您可以使用亚马逊 Comprehend Medical 结果中包含的置信度分数筛选 ICD-10-CM 代码。以下是仅包含置信度分数高于 0.4 的 ICD-10-CM 代码的提示示例:
<patient_note> Carlie had a seizure 2 weeks ago. She is complaining of frequent headaches Nausea is also present. She also complains of eye trouble with blurry vision Meds : Topamax 50 mgs at breakfast daily, Send referral order to neurologist Follow-up as scheduled </patient_note> <comprehend_medical_results> <icd-10> <entity> <text>seizure</text> <code> <description>Unspecified convulsions</description> <code_value>R56.9</code_value> <score>0.8347607851028442</score> </code> <code> <description>Epilepsy, unspecified, not intractable, without status epilepticus</description> <code_value>G40.909</code_value> <score>0.542376697063446</score> </code> <code> <description>Other seizures</description> <code_value>G40.89</code_value> <score>0.43966275453567505</score> </code> <code> <description>Other generalized epilepsy and epileptic syndromes, not intractable, without status epilepticus</description> <code_value>G40.409</code_value> <score>0.41382506489753723</score> </code> </entity> <entity> <text>headaches</text> <code> <description>Headache</description> <code_value>R51</code_value> <score>0.4066613018512726</score> </code> </entity> <entity> <text>Nausea</text> <code> <description>Nausea</description> <code_value>R11.0</code_value> <score>0.6460834741592407</score> </code> </entity> <entity> <text>eye trouble</text> <code> <description>Unspecified disorder of eye and adnexa</description> <code_value>H57.9</code_value> <score>0.6780954599380493</score> </code> <code> <description>Unspecified visual disturbance</description> <code_value>H53.9</code_value> <score>0.5871203541755676</score> </code> <code> <description>Unspecified disorder of binocular vision</description> <code_value>H53.30</code_value> <score>0.5539672374725342</score> </code> </entity> <entity> <text>blurry vision</text> <code> <description>Other visual disturbances</description> <code_value>H53.8</code_value> <score>0.9001834392547607</score> </code> </entity> </icd-10> </comprehend_medical_results> <prompt> Given the patient note and Amazon Comprehend Medical ICD-10-CM code results above, please select the most relevant ICD-10-CM diagnosis codes for the patient. For each selected code, provide a brief explanation of why it is relevant based on the information in the patient note. </prompt>
使用亚马逊 Comprehend Medical 扩展医疗 NLP 任务 Amazon Medical
在处理医学文本时,Amazon Comprehend Medical 的背景信息可以帮助法学硕士选择更好的代币。在此示例中,您希望将诊断症状与药物相匹配。您还想查找与医学检查相关的文本,例如与血液检查相关的术语。你可以使用 Amazon Comprehend Medical 来检测实体和药物名称。在这种情况下,你可以使用 DetectEntitiesV2 和 Amazon Comprehen InferRxNorm APIs d Medical。
以下是患者笔记示例:
Carlie had a seizure 2 weeks ago. She is complaining of increased frequent headaches Given lyme disease symptoms such as muscle ache and stiff neck will order prescription. Meds : Topamax 50 mgs at breakfast daily. Amoxicillan 25 mg by mouth twice a day Place MRI radiology order at RadNet
为了重点介绍诊断代码,提示中仅使用与 wit MEDICAL_CONDITION
h typ DX_NAME
e 相关的实体。由于不相关,其他元数据被排除在外。对于药物实体,包括药物名称和提取的属性。由于无关紧要,不包括来自亚马逊 Comprehend Medical 的其他药物实体元数据。以下是使用筛选后的 Amazon Comprehend Medical 结果的提示示例。提示侧重于具有该DX_NAME
类型的MEDICAL_CONDITION
实体。此提示旨在更精确地将诊断代码与药物联系起来,并更精确地提取医疗命令测试:
<patient_note> Carlie had a seizure 2 weeks ago. She is complaining of increased freqeunt headaches Given lyme disease symptoms such as muscle ache and stiff neck will order prescription. Meds : Topamax 50 mgs at breakfast daily. Amoxicillan 25 mg by mouth twice a day Place MRI radiology order at RadNet </patient_note> <detect_entity_results> <entity> <text>seizure</text> <category>MEDICAL_CONDITION</category> <type>DX_NAME</type> </entity> <entity> <text>headaches</text> <category>MEDICAL_CONDITION</category> <type>DX_NAME</type> </entity> <entity> <text>lyme disease</text> <category>MEDICAL_CONDITION</category> <type>DX_NAME</type> </entity> <entity> <text>muscle ache</text> <category>MEDICAL_CONDITION</category> <type>DX_NAME</type> </entity> <entity> <text>stiff neck</text> <category>MEDICAL_CONDITION</category> <type>DX_NAME</type> </entity> </detect_entity_results> <rx_results> <entity> <text>Topamax</text> <category>MEDICATION</category> <type>BRAND_NAME</type> <attributes> <attribute> <type>FREQUENCY</type> <text>at breakfast daily</text> </attribute> <attribute> <type>DOSAGE</type> <text>50 mgs</text> </attribute> <attribute> <type>ROUTE_OR_MODE</type> <text>by mouth</text> </attribute> </attributes> </entity> <entity> <text>Amoxicillan</text> <category>MEDICATION</category> <type>GENERIC_NAME</type> <attributes> <attribute> <type>ROUTE_OR_MODE</type> <text>by mouth</text> </attribute> <attribute> <type>DOSAGE</type> <text>25 mg</text> </attribute> <attribute> <type>FREQUENCY</type> <text>twice a day</text> </attribute> </attributes> </entity> </rx_results> <prompt> Based on the patient note and the detected entities, can you please: 1. Link the diagnosis symptoms with the medications prescribed. Provide your reasoning for the linkages. 2. Extract any entities related to medical order tests mentioned in the note. </prompt>
使用亚马逊 Comprehend Medical 安装护栏 Amazon Comprehend Medical
在使用生成的响应之前,你可以使用 LLM 和 Amazon Comprehend Medical 来创建护栏。您可以对未经修改或经过后处理的医学文本运行此工作流程。用例包括处理受保护的健康信息 (PHI)、检测幻觉或实施用于发布结果的自定义策略。例如,您可以使用 Amazon Comprehend Medical 中的上下文来识别 PHI 数据,然后使用 LLM 删除该 PHI 数据。
以下是患者记录中包含 PHI 的信息示例:
Patient name: John Doe Patient SSN: 123-34-5678 Patient DOB: 01/01/2024 Patient address: 123 Main St, Anytown USA Exam details: good health. Pulse is 60 bpm. needs to work on diet with BMI of 190
以下是包含亚马逊 Comprehend Medical 结果作为背景的示例提示:
<original_text> Patient name: John Doe Patient SSN: 123-34-5678 Patient DOB: 01/01/2024 Patient address: 123 Main St, Anytown USA Exam details: good health. Pulse is 60 bpm. needs to work on diet with BMI of 190 </original_text> <comprehend_medical_phi_entities> <entity> <text>John Doe</text> <category>PROTECTED_HEALTH_INFORMATION</category> <score>0.9967944025993347</score> <type>NAME</type> </entity> <entity> <text>123-34-5678</text> <category>PROTECTED_HEALTH_INFORMATION</category> <score>0.9998034834861755</score> <type>ID</type> </entity> <entity> <text>01/01/2000</text> <category>PROTECTED_HEALTH_INFORMATION</category> <score>0.9964448809623718</score> <type>DATE</type> </entity> </comprehend_medical_phi_entities> <instructions> Using the provided original text and the Amazon Comprehend Medical PHI entities detected, please analyze the text to determine if it contains any additional protected health information (PHI) beyond the entities already identified. If additional PHI is found, please list and categorize it. If no additional PHI is found, please state that explicitly. In addition if PHI is found, generate updated text with the PHI removed. </instructions>