本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
結合 Amazon Comprehend Medical 與大型語言模型
由 NEJM AI 進行的 2024 年研究
-
使用 Amazon Comprehend Medical 的初始結果作為 LLM 的內容,以增強實體選擇的準確性
-
實作自訂實體辨識、摘要、問答和其他使用案例
本節說明如何使用擷取增強生成 (RAG) 方法,將 Amazon Comprehend Medical 與 LLM 結合。擷取增強生成 (RAG) 是一種生成式 AI 技術,其中 LLM 會在產生回應之前參考訓練資料來源以外的授權資料來源。如需詳細資訊,請參閱什麼是 RAG
為了說明此方法,本節使用與 ICD-10-CM 相關的醫療 (診斷) 編碼範例。它包含範例架構和提示工程範本,以協助加速您的創新。它還包括在 RAG 工作流程中使用 Amazon Comprehend Medical 的最佳實務。
使用 Amazon Comprehend Medical 的 RAG 架構
下圖說明從患者備註識別 ICD-10-CM 診斷碼的 RAG 方法。它使用 Amazon 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 代碼。它使用 InferICD10CM 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 結果整合為 LLM 的提示時,請務必遵循最佳實務。這可以提高效能和準確性。以下是主要建議:
-
了解 Amazon Comprehend Medical 可信度分數 – Amazon Comprehend Medical 為每個偵測到的實體和本體連結提供可信度分數。請務必了解這些分數的意義,並為您的特定使用案例建立適當的閾值。可信度分數有助於篩選出低可信度實體,減少雜訊並改善 LLM 輸入的品質。
-
在提示詞工程中使用可信度分數 – 製作 LLM 的提示時,請考慮將 Amazon Comprehend Medical 可信度分數納入其他內容。這有助於 LLM 根據實體的可信度等級排定優先順序或權重實體,從而可能改善輸出的品質。
-
使用 Ground Truth 資料評估 Amazon Comprehend Medical 結果 – Ground Truth 資料是已知為 true 的資訊。它可用來驗證 AI/ML 應用程式是否產生準確的結果。將 Amazon Comprehend Medical 結果整合到您的 LLM 工作流程之前,請在代表性的資料範例上評估服務的效能。將結果與 Ground Truth 註釋進行比較,以識別潛在的差異或需要改進的區域。此評估可協助您了解 Amazon Comprehend Medical 對您使用案例的優勢和限制。
-
從策略上選取相關資訊 – Amazon Comprehend Medical 可以提供大量資訊,但並非所有資訊都與您的任務相關。仔細選取與您的使用案例最相關的實體、屬性和中繼資料。向 LLM 提供太多不相關的資訊可能會產生雜訊,並可能降低效能。
-
對齊實體定義 – 確保 Amazon Comprehend Medical 使用的實體和屬性定義與您的解釋保持一致。如果有差異,請考慮提供其他內容或釐清給 LLM,以彌補 Amazon Comprehend Medical 輸出與您的需求之間的差距。如果 Amazon Comprehend Medical 實體不符合您的期望,您可以在提示中包含其他指示 (和可能的範例),以實作自訂實體偵測。
-
提供特定網域的知識 – 雖然 Amazon Comprehend Medical 提供寶貴的醫療資訊,但可能無法擷取特定網域的所有細微差別。考慮使用其他領域特定的知識來源來補充 Amazon Comprehend Medical 結果,例如拓撲、術語或專家策劃的資料集。這可為 LLM 提供更全面的內容。
-
遵守道德和法規準則 – 處理醫療資料時,請務必遵守道德原則和法規準則,例如與資料隱私權、安全和醫療保健中 AI 系統負責任使用相關的準則。確保您的實作符合相關法律和業界最佳實務。
透過遵循這些最佳實務,AI/ML 從業人員可以有效地使用 Amazon Comprehend Medical 和 LLMs的優勢。對於醫療 NLP 任務,這些最佳實務有助於降低潛在風險並提高效能。
Amazon Comprehend Medical 內容的提示工程
提示詞工程
視您執行的 API 操作而定,Amazon Comprehend Medical 會傳回偵測到的實體、本體程式碼和描述,以及可信度分數。當您的解決方案調用目標 LLM 時,這些結果會在提示中變成內容。您必須設計提示,以在提示範本中呈現內容。
注意
本節中的範例提示遵循 Anthropic 指引
一般而言,您會將原始醫療文字和 Amazon 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 任務的提示內容的策略:
篩選 Amazon 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 精確度。若要減少雜訊,您可以使用 Amazon 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>
使用 Amazon Comprehend Medical 擴展醫療 NLP 任務
處理醫療文字時,Amazon Comprehend Medical 的內容可協助 LLM 選取更好的字符。在此範例中,您想要將診斷症狀與藥物配對。您也想要尋找與醫療測試相關的文字,例如與血液面板測試相關的術語。您可以使用 Amazon Comprehend Medical 來偵測實體和藥物名稱。在此情況下,您會使用適用於 Amazon Comprehend Medical 的 DetectEntitiesV2 和 InferRxNorm APIs。
以下是範例病患備註:
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
為了專注於診斷碼,提示中只會DX_NAME
使用MEDICAL_CONDITION
與 類型相關的實體。由於不相關,會排除其他中繼資料。對於藥物實體,會包含藥物名稱以及擷取的屬性。由於不相關,Amazon 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>
使用 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
以下是提示範例,其中包含 Amazon 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>