利用可能な MedLM モデル(MedLM-medium と MedLM-large)は、医療の質問応答と要約の基盤モデルです。Vertex AI MedLM API を使用してモデルにアクセスできます。このページでは、使用可能な MedLM モデル、モデルとのやり取りに使用する API、モデルの動作のカスタマイズ方法について説明します。
始める前に
- お客様の責任、規制情報、責任ある AI のベスト プラクティスなどについては、MedLM モデルの概要をご覧ください。
MedLM の使用目的、データの概要、安全性情報などのモデルの詳細については、MedLM モデルカードをご覧ください。MedLM モデルカードの PDF 版をダウンロードするには、次のリンクをクリックします。
プロンプト設計
MedLM モデルを操作するには、生成する対象をモデルに伝える、プロンプトとも呼ばれる自然言語命令を送信します。しかし、LLM は予期しない動作をすることがあります。プロンプト設計は試行錯誤を繰り返すプロセスであり、習熟までに時間と練習が必要です。一般的なプロンプト設計戦略については、プロンプト設計の概要をご覧ください。タスク固有のテキスト プロンプトの設計ガイダンスについては、テキスト プロンプトを設計するをご覧ください。
ユースケース
- 要約: 元のテキストの関連情報を盛り込んで、ドキュメントの短いバージョンを作成します。たとえば、外来患者の訪問を説明する医療メモを要約することや、特定のデータポイントに関連する情報を抽出することが可能です。
- 質問応答: 質問への回答をテキストで提示します。たとえば、一般的な医学的な質問をして、ナレッジベースから回答を生成できます。
サポートされているモデル
medlm-medium
medlm-large
使ってみる
次のサンプルは、以下のインターフェースを使用して MedLM API の使用を開始する方法を示しています。
- Vertex AI REST API
- Vertex AI SDK for Python
- Vertex AI Studio
REST
リクエストのデータを使用する前に、次のように置き換えます。
PROJECT_ID
: 実際のプロジェクト ID。MEDLM_MODEL
: MedLM モデル(medlm-medium
またはmedlm-large
)。
HTTP メソッドと URL:
POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict
リクエストの本文(JSON):
{ "instances": [ { "content": "Question: What causes you to get ringworm?" } ], "parameters": { "temperature": 0, "maxOutputTokens": 256, "topK": 40, "topP": 0.95 } }
リクエストを送信するには、次のいずれかのオプションを選択します。
curl
リクエスト本文を request.json
という名前のファイルに保存します。ターミナルで次のコマンドを実行して、このファイルを現在のディレクトリに作成または上書きします。
cat > request.json << 'EOF' { "instances": [ { "content": "Question: What causes you to get ringworm?" } ], "parameters": { "temperature": 0, "maxOutputTokens": 256, "topK": 40, "topP": 0.95 } } EOF
その後、次のコマンドを実行して REST リクエストを送信します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict"
PowerShell
リクエスト本文を request.json
という名前のファイルに保存します。ターミナルで次のコマンドを実行して、このファイルを現在のディレクトリに作成または上書きします。
@' { "instances": [ { "content": "Question: What causes you to get ringworm?" } ], "parameters": { "temperature": 0, "maxOutputTokens": 256, "topK": 40, "topP": 0.95 } } '@ | Out-File -FilePath request.json -Encoding utf8
その後、次のコマンドを実行して REST リクエストを送信します。
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict" | Select-Object -Expand Content
Python(Colaboratory)
Colaboratory で次の Python コードを実行します。
!pip install google-cloud-aiplatform # The following restarts the runtime. import IPython app = IPython.Application.instance() # Note that this will result in a pop-up telling you that the session has # crashed for an unknown reason. This can be safely ignored and you can continue # with the following cells after getting this message. app.kernel.do_shutdown(True)
Colaboratory ノートブックで次のコードを実行します。示されている Google Cloud プロジェクト ID を入力します。プロジェクト ID を確認するには、プロジェクト ID を探すをご覧ください。
from google.colab import auth as google_auth import vertexai from vertexai.preview.language_models import TextGenerationModel google_auth.authenticate_user() # TODO: Replace with project ID from Cloud Console # (https://support.google.com/googleapi/answer/7014113) PROJECT_ID = 'my-project' # MedLM models are only available in us-central1. vertexai.init(project=PROJECT_ID, location='us-central1') parameters = { "candidate_count": 1, "max_output_tokens": 256, "temperature": 0.0, "top_k": 40, "top_p": 0.80, } model_instance = TextGenerationModel.from_pretrained("medlm-medium") response = model_instance.predict( "Question: What causes you to get ringworm?", **parameters ) print(f"Response from Model: {response.text}")
Generative AI Studio
Vertex AI Studio を使用して、MedLM API に送信されるプロンプトを設計、テスト、カスタマイズします。Vertex AI Studio for MedLM を使用する前に、前提条件について Vertex AI Studio を試すをご覧ください。
Google Cloud コンソールで Vertex AI Studio を使用して MedLM プロンプトをテストする手順は次のとおりです。
- Google Cloud コンソールの [Vertex AI] セクションで、[Vertex AI Studio] ページに移動します。
- [開始] をクリックします。
- [Create prompt] をクリックします。
- [モデル] メニューで、
MedLM-Medium
またはMedLM-Large
を選択します。 - [Prompt] フィールドにプロンプトを入力します。
- (省略可)[Temperature] と [Token limit] の値を調整して、レスポンスへの影響をテストできます。デフォルト値を使用することをおすすめします。どの値を使用するかわからない場合は、デフォルト値を使用します。
- [送信] をクリックしてレスポンスを生成します。
- (省略可)プロンプトを保存するには、[保存] をクリックします。
- (省略可)プロンプトの Python コードまたは
curl
コマンドを表示するには、[コードを取得] をクリックします。
質問応答のプロンプト
以下のセクションでは、質問応答のプロンプトのサンプルについて説明します。各サンプル プロンプトには、推奨されるモデルとパラメータ値が含まれています。
長形式の質問応答
次のサンプルは、クエリとして作成された長形式の医療関連の質問に MedLM API がどのように回答するかを示しています。
REST
リクエストのデータを使用する前に、次のように置き換えます。
PROJECT_ID
: 実際のプロジェクト ID。MEDLM_MODEL
: MedLM モデル(medlm-medium
またはmedlm-large
)。
HTTP メソッドと URL:
POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict
リクエストの本文(JSON):
{ "instances": [ { "content": "Question: What causes you to get ringworm?" } ], "parameters": { "temperature": 0, "maxOutputTokens": 256, "topK": 40, "topP": 0.95 } }
リクエストを送信するには、次のいずれかのオプションを選択します。
curl
リクエスト本文を request.json
という名前のファイルに保存します。ターミナルで次のコマンドを実行して、このファイルを現在のディレクトリに作成または上書きします。
cat > request.json << 'EOF' { "instances": [ { "content": "Question: What causes you to get ringworm?" } ], "parameters": { "temperature": 0, "maxOutputTokens": 256, "topK": 40, "topP": 0.95 } } EOF
その後、次のコマンドを実行して REST リクエストを送信します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict"
PowerShell
リクエスト本文を request.json
という名前のファイルに保存します。ターミナルで次のコマンドを実行して、このファイルを現在のディレクトリに作成または上書きします。
@' { "instances": [ { "content": "Question: What causes you to get ringworm?" } ], "parameters": { "temperature": 0, "maxOutputTokens": 256, "topK": 40, "topP": 0.95 } } '@ | Out-File -FilePath request.json -Encoding utf8
その後、次のコマンドを実行して REST リクエストを送信します。
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict" | Select-Object -Expand Content
多肢選択式の質問応答
次のサンプルは、MedLM API が多肢選択式の医療関連の質問にどのように回答するかを示しています。プロンプトは次のとおりです。
Instructions: This text contains multiple-choice questions about medical knowledge. Solve each question step-by-step, starting by summarizing the available information. Select a single option from the four choices provided as the final answer.
Question 1: Which medication causes the maximum increase in prolactin level?
(A) Risperidone
(B) Clozapine
(C) Olanzapine
(D) Aripiprazole
Explanation: To solve this question, let's refer to authoritative sources. Clozapine generally does not elevate prolactin levels. Atypicals like olanzapine and aripiprazole cause little to no elevation. Risperidone, on the other hand, is known to result in a sustained elevated prolactin level. Therefore, risperidone is likely to cause the maximum increase in prolactin level.
Answer: (A)
Question 2: What is the recommended age for routine screening mammography?
(A) 20 years
(B) 30 years
(C) 40 years
(D) 50 years
Explanation: The age of routine screening may vary depending on the country. In the United States, according to the American Cancer Society, it is recommended to start routine screening mammography at 40 years of age. In Europe, it is typically closer to 50 years. For a patient based in the US, the best answer is 40 years.
Answer: (C)
Question 3: A 65-year-old male experiences severe back pain and paralysis in his left lower limb. Imaging studies show compression of nerve elements at the intervertebral foramen between vertebrae L5 and S1. Which structure is most likely causing this compression?
(A) Anulus fibrosus
(B) Nucleus pulposus
(C) Posterior longitudinal ligament
(D) Anterior longitudinal ligament
Explanation: This man's symptoms and imaging findings are consistent with a herniated intervertebral disk. The soft, gelatinous "nucleus pulposus" is forced out through a weakened part of the disk, resulting in back pain and nerve root irritation. In this case, the impingement is resulting in paralysis, which should be considered a medical emergency. Overall, the structure that is causing the compression and symptoms is the nucleus pulposus.
Answer: (B)
Question 4: Which cells in the lungs are also known as APUD cells?
(A) Dendritic cells
(B) Type I pneumocytes
(C) Type II pneumocytes
(D) Neuroendocrine cells
Explanation: Neuroendocrine cells, also known as Kultschitsky-type cells, Feyrter cells, and APUD cells, are found in the basal layer of the surface epithelium and in the bronchial glands.
Answer: (D)
Question 5: Which microorganism indicates remote contamination of water?
(A) Streptococci
(B) Staphylococci
(C) Clostridium perfringens
(D) Vibrio
Explanation: The presence of Clostridium perfringens in water indicates remote contamination because it is a spore-forming bacterium that can survive in the environment for extended periods of time.
Answer: (C)
REST
リクエストのデータを使用する前に、次のように置き換えます。
PROJECT_ID
: 実際のプロジェクト ID。MEDLM_MODEL
: MedLM モデル(medlm-medium
またはmedlm-large
)。
HTTP メソッドと URL:
POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict
リクエストの本文(JSON):
{ "instances": [ { "content": "Instructions: The following are multiple choice questions about medical knowledge. Solve them in a step-by-step fashion, starting by summarizing the available information. Output a single option from the four options as the final answer. \n \nQuestion: Maximum increase in prolactin level is caused by: \n(A) Risperidone (B) Clozapine (C) Olanzapine (D) Aripiprazole \nExplanation: Let's solve this step-by-step, referring to authoritative sources as needed. Clozapine generally does not raise prolactin levels. Atypicals such as olanzapine and aripiprazole cause small if no elevation. Risperidone is known to result in a sustained elevated prolactin level. Therefore risperidone is likely to cause the maximum increase in prolactin level. \nAnswer: (A) \n \nQuestion: What is the age of routine screening mammography? \n(A) 20 years (B) 30 years (C) 40 years (D) 50 years \nExplanation: Let's solve this step-by-step, referring to authoritative sources as needed. The age of routine screening depends on the country you are interested in and varies widely. For the US, it is 40 years of age according to the American Cancer Society. In Europe, it is typically closer to 50 years. For a patient based in the US, the best answer is 40 years. \nAnswer: (C) \n \nQuestion: A 65-year-old male complains of severe back pain and inability to move his left lower limb. Radiographic studies demonstrate the compression of nerve elements at the intervertebral foramen between vertebrae L5 and S1. Which structure is most likely responsible for this space-occupying lesion? \n(A) Anulus fibrosus (B) Nucleus pulposus (C) Posterior longitudinal ligament (D) Anterior longitudinal ligament \nExplanation: Let's solve this step-by-step, referring to authoritative sources as needed. This man describes a herniated invertebral disk through a tear in the surrounding annulus fibrosus. The soft, gelatinous \"nucleus pulposus\" is forced out through a weakened part of the disk, resulting in back pain and nerve root irritation. In this case, the impingement is resulting in paralysis, and should be considered a medical emergency. Overall, the structure that is causing the compression and symptoms is the nucleus pulposus. \nAnswer: (B) \n \nQuestion: Neuroendocrine cells in the lungs are: \n(A) Dendritic cells (B) Type I pneumocytes (C) Type II pneumocytes (D) APUD cells \nExplanation: Let's solve this step-by-step, referring to authoritative sources as needed. Neuroendocrine cells, which are also known as Kultschitsky-type cells, Feyrter cells and APUD cells, are found in the basal layer of the surface epithelium and in the bronchial glands. \nAnswer: (D) \n \nQuestion: Presence of it indicates remote contamination of water \n(A) Streptococci (B) Staphalococci (C) Clastridium pertringes (D) Nibrio \n" } ], "parameters": { "temperature": 0.2, "maxOutputTokens": 256 } }
リクエストを送信するには、次のいずれかのオプションを選択します。
curl
リクエスト本文を request.json
という名前のファイルに保存します。ターミナルで次のコマンドを実行して、このファイルを現在のディレクトリに作成または上書きします。
cat > request.json << 'EOF' { "instances": [ { "content": "Instructions: The following are multiple choice questions about medical knowledge. Solve them in a step-by-step fashion, starting by summarizing the available information. Output a single option from the four options as the final answer. \n \nQuestion: Maximum increase in prolactin level is caused by: \n(A) Risperidone (B) Clozapine (C) Olanzapine (D) Aripiprazole \nExplanation: Let's solve this step-by-step, referring to authoritative sources as needed. Clozapine generally does not raise prolactin levels. Atypicals such as olanzapine and aripiprazole cause small if no elevation. Risperidone is known to result in a sustained elevated prolactin level. Therefore risperidone is likely to cause the maximum increase in prolactin level. \nAnswer: (A) \n \nQuestion: What is the age of routine screening mammography? \n(A) 20 years (B) 30 years (C) 40 years (D) 50 years \nExplanation: Let's solve this step-by-step, referring to authoritative sources as needed. The age of routine screening depends on the country you are interested in and varies widely. For the US, it is 40 years of age according to the American Cancer Society. In Europe, it is typically closer to 50 years. For a patient based in the US, the best answer is 40 years. \nAnswer: (C) \n \nQuestion: A 65-year-old male complains of severe back pain and inability to move his left lower limb. Radiographic studies demonstrate the compression of nerve elements at the intervertebral foramen between vertebrae L5 and S1. Which structure is most likely responsible for this space-occupying lesion? \n(A) Anulus fibrosus (B) Nucleus pulposus (C) Posterior longitudinal ligament (D) Anterior longitudinal ligament \nExplanation: Let's solve this step-by-step, referring to authoritative sources as needed. This man describes a herniated invertebral disk through a tear in the surrounding annulus fibrosus. The soft, gelatinous \"nucleus pulposus\" is forced out through a weakened part of the disk, resulting in back pain and nerve root irritation. In this case, the impingement is resulting in paralysis, and should be considered a medical emergency. Overall, the structure that is causing the compression and symptoms is the nucleus pulposus. \nAnswer: (B) \n \nQuestion: Neuroendocrine cells in the lungs are: \n(A) Dendritic cells (B) Type I pneumocytes (C) Type II pneumocytes (D) APUD cells \nExplanation: Let's solve this step-by-step, referring to authoritative sources as needed. Neuroendocrine cells, which are also known as Kultschitsky-type cells, Feyrter cells and APUD cells, are found in the basal layer of the surface epithelium and in the bronchial glands. \nAnswer: (D) \n \nQuestion: Presence of it indicates remote contamination of water \n(A) Streptococci (B) Staphalococci (C) Clastridium pertringes (D) Nibrio \n" } ], "parameters": { "temperature": 0.2, "maxOutputTokens": 256 } } EOF
その後、次のコマンドを実行して REST リクエストを送信します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict"
PowerShell
リクエスト本文を request.json
という名前のファイルに保存します。ターミナルで次のコマンドを実行して、このファイルを現在のディレクトリに作成または上書きします。
@' { "instances": [ { "content": "Instructions: The following are multiple choice questions about medical knowledge. Solve them in a step-by-step fashion, starting by summarizing the available information. Output a single option from the four options as the final answer. \n \nQuestion: Maximum increase in prolactin level is caused by: \n(A) Risperidone (B) Clozapine (C) Olanzapine (D) Aripiprazole \nExplanation: Let's solve this step-by-step, referring to authoritative sources as needed. Clozapine generally does not raise prolactin levels. Atypicals such as olanzapine and aripiprazole cause small if no elevation. Risperidone is known to result in a sustained elevated prolactin level. Therefore risperidone is likely to cause the maximum increase in prolactin level. \nAnswer: (A) \n \nQuestion: What is the age of routine screening mammography? \n(A) 20 years (B) 30 years (C) 40 years (D) 50 years \nExplanation: Let's solve this step-by-step, referring to authoritative sources as needed. The age of routine screening depends on the country you are interested in and varies widely. For the US, it is 40 years of age according to the American Cancer Society. In Europe, it is typically closer to 50 years. For a patient based in the US, the best answer is 40 years. \nAnswer: (C) \n \nQuestion: A 65-year-old male complains of severe back pain and inability to move his left lower limb. Radiographic studies demonstrate the compression of nerve elements at the intervertebral foramen between vertebrae L5 and S1. Which structure is most likely responsible for this space-occupying lesion? \n(A) Anulus fibrosus (B) Nucleus pulposus (C) Posterior longitudinal ligament (D) Anterior longitudinal ligament \nExplanation: Let's solve this step-by-step, referring to authoritative sources as needed. This man describes a herniated invertebral disk through a tear in the surrounding annulus fibrosus. The soft, gelatinous \"nucleus pulposus\" is forced out through a weakened part of the disk, resulting in back pain and nerve root irritation. In this case, the impingement is resulting in paralysis, and should be considered a medical emergency. Overall, the structure that is causing the compression and symptoms is the nucleus pulposus. \nAnswer: (B) \n \nQuestion: Neuroendocrine cells in the lungs are: \n(A) Dendritic cells (B) Type I pneumocytes (C) Type II pneumocytes (D) APUD cells \nExplanation: Let's solve this step-by-step, referring to authoritative sources as needed. Neuroendocrine cells, which are also known as Kultschitsky-type cells, Feyrter cells and APUD cells, are found in the basal layer of the surface epithelium and in the bronchial glands. \nAnswer: (D) \n \nQuestion: Presence of it indicates remote contamination of water \n(A) Streptococci (B) Staphalococci (C) Clastridium pertringes (D) Nibrio \n" } ], "parameters": { "temperature": 0.2, "maxOutputTokens": 256 } } '@ | Out-File -FilePath request.json -Encoding utf8
その後、次のコマンドを実行して REST リクエストを送信します。
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict" | Select-Object -Expand Content
要約プロンプト
以下のセクションでは、要約のプロンプトのサンプルについて説明します。各サンプル プロンプトには、推奨されるモデルとパラメータ値が含まれています。
訪問後の概要を作成する
次のサンプルは、外来患者の訪問メモに基づいて患者の訪問後の概要を生成する方法を示しています。プロンプトには次のものが含まれます。
- モデル命令を含むプリアンブル。
- サマリーで抽出する各フィールドの説明。
訪問後のサマリーの形式は、Sieferd 他(2019 年)と英国国立医大アカデミーのおすすめの方法に基づきます。必要に応じて、メモとサマリーの前にフューショットの例を追加できます。
プロンプトは次のとおりです。
Please read through the provided medical note describing an outpatient visit and extract the relevant information for each of the following 12 fields: - Patient name/age/gender: This should summarize the patient's name, age and gender. It should use the format: "[Patient name], [age] year old [gender]". If the name is not mentioned in the note, please answer "Not available". - Today I was seen by: This field should provide the name of the provider. If the provider seen for the note being summarized is not mentioned, please answer "Not available". - I came in today for: This field should indicate the chief complaint or complaints that caused the visit. - New health issues identified today are: This field should indicate any new diagnoses or other issues identified as a result of the visit being summarized. If the issue is a pre-existing condition identified in the past, please answer "No new diagnosis". - Other health issues I have are: This field should indicate any pre-existing health issues identified in notes. - Today we accomplished: This field should summarize the main topics of discussion and results of any procedures performed during the current visit. The summary could be a short list of procedures, or could be a text description of the patient's experience. Please be as brief as possible when providing details, such as test results or medication names. Describing the experience from the patient's point of view, using phrases like "my visit", "my condition". - My important numbers: This field should provide the results of any measurements relevant to the visit, including vitals. Provide the results of any numeric measurements relevant to the visit, including vitals, laboratory studies, or pain scores. Please include the numbers that should be monitored. Do not fabricate numbers that are not presented in the note. - Changes to my medications are: This field should specify any medications that were added, for which the doses were updated, or which are no longer needed after the visit. Please specify both newly added and stopped medications when possible. If no changes are apparent from the note, please answer "no changes". - Other medications I have are: If the note indicates any existing medications for the patient that the patient should continue taking without changes, list them here. If no medications are indicated in the note, please "Not specified". - My next steps are: This field should document the patient's next steps, including any actions they should take, test results they should expect, and follow-up visits they should schedule, along with the appropriate time frames for each. - I should seek immediate medical attention if: If the note specifies any conditions for which the patient should immediately seek care, specify it here. Be sure to only include conditions that are mentioned in the note. If no conditions are mentioned, write "Not specified". - Other comments from my provider: This is an optional extra field that captures any additional relevant information the provider indicated in the notes that it would be useful for the patient to know. Do not include information that is already listed in the previous field. For each field, write at a sixth-grade reading level and avoid using abbreviations or jargon. Output the summary in the following format: - Patient name/age/gender: - Today I was seen by: - I came in today for: - New health issues identified today are: - Other health issues I have are: - Today we accomplished: - My important numbers: - Changes to my medications are: - Other medications I have are: - My next steps are: - I should seek immediate medical attention if: - Other comments from my provider: Note: INPUT_NOTE After Visit Summary:
REST
データをリクエストする前に、次のように置き換えます。
PROJECT_ID
: 実際のプロジェクト ID。MEDLM_MODEL
: MedLM モデル(medlm-medium
またはmedlm-large
)。INPUT_NOTE
: 要約する入力メモ。
HTTP メソッドと URL:
POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict
リクエストの本文(JSON):
{ "instances": [ { "content": "Please read through the provided medical note describing an outpatient visit and extract the relevant information for each of the following 12 fields:\n\n- Patient name/age/gender: This should summarize the patient\u2019s name, age and gender. It should use the format: '[Patient name], [age] year old [gender]'. If the name is not mentioned in the note, please answer \"Not available\".\n- Today I was seen by: This field should provide the name of the provider. If the provider seen for the note being summarized is not mentioned, please answer 'Not available'.\n- I came in today for: This field should indicate the chief complaint or complaints that caused the visit.\n- New health issues identified today are: This field should indicate any new diagnoses or other issues identified as a result of the visit being summarized. If the issue is a pre-existing condition identified in the past, please answer 'No new diagnosis'.\n- Other health issues I have are: This field should indicate any pre-existing health issues identified in notes.\n- Today we accomplished: This field should summarize the main topics of discussion and results of any procedures performed during the current visit. The summary could be a short list of procedures, or could be a text description of the patient\u2019s experience. Please be as brief as possible when providing details, such as test results or medication names. Describing the experience from the patient\u2019s point of view, using phrases like 'my visit', 'my condition'.\n- My important numbers: This field should provide the results of any measurements relevant to the visit, including vitals. Provide the results of any numeric measurements relevant to the visit, including vitals, laboratory studies, or pain scores. Please include the numbers that should be monitored. Do not fabricate numbers that are not presented in the note.\n\n\n\n\n\n\n\n\n- Changes to my medications are: This field should specify any medications that were added, for which the doses were updated, or which are no longer needed after the visit. Please specify both newly added and stopped medications when possible. If no changes are apparent from the note, please answer 'no changes'.\n- Other medications I have are: If the note indicates any existing medications for the patient that the patient should continue taking without changes, list them here. If no medications are indicated in the note, please 'Not specified'.\n- My next steps are: This field should document the patient\u2019s next steps, including any actions they should take, test results they should expect, and follow-up visits they should schedule, along with the appropriate time frames for each.\n- I should seek immediate medical attention if: If the note specifies any conditions for which the patient should immediately seek care, specify it here. Be sure to only include conditions that are mentioned in the note. If no conditions are mentioned, write 'Not specified'.\n- Other comments from my provider: This is an optional extra field that captures any additional relevant information the provider indicated in the notes that it would be useful for the patient to know. Do not include information that is already listed in the previous field.\nFor each field, write at a sixth-grade reading level and avoid using abbreviations or jargon.\n\nOutput the summary in the following format:\n- Patient name/age/gender:\n- Today I was seen by:\n- I came in today for:\n- New health issues identified today are:\n- Other health issues I have are:\n- Today we accomplished:\n- My important numbers:\n- Changes to my medications are:\n- Other medications I have are:\n- My next steps are:\n- I should seek immediate medical attention if:\n- Other comments from my provider:\n\n Note:\n\n INPUT_NOTE \n\nAfter Visit Summary:" } ], "parameters": { "candidate_count": 1, "temperature": 0, "maxOutputTokens": 1024, "topK": 40, "topP": 0.80 } }
リクエストを送信するには、次のいずれかのオプションを選択します。
curl
リクエスト本文を request.json
という名前のファイルに保存します。ターミナルで次のコマンドを実行して、このファイルを現在のディレクトリに作成または上書きします。
cat > request.json << 'EOF' { "instances": [ { "content": "Please read through the provided medical note describing an outpatient visit and extract the relevant information for each of the following 12 fields:\n\n- Patient name/age/gender: This should summarize the patient\u2019s name, age and gender. It should use the format: '[Patient name], [age] year old [gender]'. If the name is not mentioned in the note, please answer \"Not available\".\n- Today I was seen by: This field should provide the name of the provider. If the provider seen for the note being summarized is not mentioned, please answer 'Not available'.\n- I came in today for: This field should indicate the chief complaint or complaints that caused the visit.\n- New health issues identified today are: This field should indicate any new diagnoses or other issues identified as a result of the visit being summarized. If the issue is a pre-existing condition identified in the past, please answer 'No new diagnosis'.\n- Other health issues I have are: This field should indicate any pre-existing health issues identified in notes.\n- Today we accomplished: This field should summarize the main topics of discussion and results of any procedures performed during the current visit. The summary could be a short list of procedures, or could be a text description of the patient\u2019s experience. Please be as brief as possible when providing details, such as test results or medication names. Describing the experience from the patient\u2019s point of view, using phrases like 'my visit', 'my condition'.\n- My important numbers: This field should provide the results of any measurements relevant to the visit, including vitals. Provide the results of any numeric measurements relevant to the visit, including vitals, laboratory studies, or pain scores. Please include the numbers that should be monitored. Do not fabricate numbers that are not presented in the note.\n\n\n\n\n\n\n\n\n- Changes to my medications are: This field should specify any medications that were added, for which the doses were updated, or which are no longer needed after the visit. Please specify both newly added and stopped medications when possible. If no changes are apparent from the note, please answer 'no changes'.\n- Other medications I have are: If the note indicates any existing medications for the patient that the patient should continue taking without changes, list them here. If no medications are indicated in the note, please 'Not specified'.\n- My next steps are: This field should document the patient\u2019s next steps, including any actions they should take, test results they should expect, and follow-up visits they should schedule, along with the appropriate time frames for each.\n- I should seek immediate medical attention if: If the note specifies any conditions for which the patient should immediately seek care, specify it here. Be sure to only include conditions that are mentioned in the note. If no conditions are mentioned, write 'Not specified'.\n- Other comments from my provider: This is an optional extra field that captures any additional relevant information the provider indicated in the notes that it would be useful for the patient to know. Do not include information that is already listed in the previous field.\nFor each field, write at a sixth-grade reading level and avoid using abbreviations or jargon.\n\nOutput the summary in the following format:\n- Patient name/age/gender:\n- Today I was seen by:\n- I came in today for:\n- New health issues identified today are:\n- Other health issues I have are:\n- Today we accomplished:\n- My important numbers:\n- Changes to my medications are:\n- Other medications I have are:\n- My next steps are:\n- I should seek immediate medical attention if:\n- Other comments from my provider:\n\n Note:\n\n INPUT_NOTE \n\nAfter Visit Summary:" } ], "parameters": { "candidate_count": 1, "temperature": 0, "maxOutputTokens": 1024, "topK": 40, "topP": 0.80 } } EOF
その後、次のコマンドを実行して REST リクエストを送信します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict"
PowerShell
リクエスト本文を request.json
という名前のファイルに保存します。ターミナルで次のコマンドを実行して、このファイルを現在のディレクトリに作成または上書きします。
@' { "instances": [ { "content": "Please read through the provided medical note describing an outpatient visit and extract the relevant information for each of the following 12 fields:\n\n- Patient name/age/gender: This should summarize the patient\u2019s name, age and gender. It should use the format: '[Patient name], [age] year old [gender]'. If the name is not mentioned in the note, please answer \"Not available\".\n- Today I was seen by: This field should provide the name of the provider. If the provider seen for the note being summarized is not mentioned, please answer 'Not available'.\n- I came in today for: This field should indicate the chief complaint or complaints that caused the visit.\n- New health issues identified today are: This field should indicate any new diagnoses or other issues identified as a result of the visit being summarized. If the issue is a pre-existing condition identified in the past, please answer 'No new diagnosis'.\n- Other health issues I have are: This field should indicate any pre-existing health issues identified in notes.\n- Today we accomplished: This field should summarize the main topics of discussion and results of any procedures performed during the current visit. The summary could be a short list of procedures, or could be a text description of the patient\u2019s experience. Please be as brief as possible when providing details, such as test results or medication names. Describing the experience from the patient\u2019s point of view, using phrases like 'my visit', 'my condition'.\n- My important numbers: This field should provide the results of any measurements relevant to the visit, including vitals. Provide the results of any numeric measurements relevant to the visit, including vitals, laboratory studies, or pain scores. Please include the numbers that should be monitored. Do not fabricate numbers that are not presented in the note.\n\n\n\n\n\n\n\n\n- Changes to my medications are: This field should specify any medications that were added, for which the doses were updated, or which are no longer needed after the visit. Please specify both newly added and stopped medications when possible. If no changes are apparent from the note, please answer 'no changes'.\n- Other medications I have are: If the note indicates any existing medications for the patient that the patient should continue taking without changes, list them here. If no medications are indicated in the note, please 'Not specified'.\n- My next steps are: This field should document the patient\u2019s next steps, including any actions they should take, test results they should expect, and follow-up visits they should schedule, along with the appropriate time frames for each.\n- I should seek immediate medical attention if: If the note specifies any conditions for which the patient should immediately seek care, specify it here. Be sure to only include conditions that are mentioned in the note. If no conditions are mentioned, write 'Not specified'.\n- Other comments from my provider: This is an optional extra field that captures any additional relevant information the provider indicated in the notes that it would be useful for the patient to know. Do not include information that is already listed in the previous field.\nFor each field, write at a sixth-grade reading level and avoid using abbreviations or jargon.\n\nOutput the summary in the following format:\n- Patient name/age/gender:\n- Today I was seen by:\n- I came in today for:\n- New health issues identified today are:\n- Other health issues I have are:\n- Today we accomplished:\n- My important numbers:\n- Changes to my medications are:\n- Other medications I have are:\n- My next steps are:\n- I should seek immediate medical attention if:\n- Other comments from my provider:\n\n Note:\n\n INPUT_NOTE \n\nAfter Visit Summary:" } ], "parameters": { "candidate_count": 1, "temperature": 0, "maxOutputTokens": 1024, "topK": 40, "topP": 0.80 } } '@ | Out-File -FilePath request.json -Encoding utf8
その後、次のコマンドを実行して REST リクエストを送信します。
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict" | Select-Object -Expand Content
文字起こしから履歴と身体検査(H&P)のメモを作成する
次のサンプルは、MedLM API にリクエストを送信して、医療提供者と患者の間の医療会話の文字起こしから履歴と身体検査(H&P)のメモの下書きを作成することで、臨床文書の作成を加速する方法を示しています。
H&P メモは、医療提供者によって行われた、患者の医療上の履歴と身体検査を文書化した包括的な臨床メモです。MedLM は、医療訪問中の医療提供者と患者の間の会話からこのようなメモの下書きを作成するために必要な臨床情報の多くを収集できます。
次の形式の医療会話の文字起こしがあるとします。会話の話者は既知です。
PROVIDER: Welcome! How can we help you this morning?
PATIENT: I think I hurt my ankle while playing football last night. Now even walking hurts.
PROVIDER: I am sorry to hear that. Can you tell me how it happened?
PATIENT: I was playing soccer last night and I think I trip and twisted my ankle.
PROVIDER: Did it start hurting right away? Did you try anything to alleviate the pain?
PATIENT: It got worse last night. I took some ibuprofen, but it really didn't help.
REST
リクエストのデータを使用する前に、次のように置き換えます。
PROJECT_ID
: 実際のプロジェクト ID。MEDLM_MODEL
: MedLM モデル(medlm-medium
またはmedlm-large
)。
HTTP メソッドと URL:
POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict
リクエストの本文(JSON):
{ "instances": [ { "content": "You are charting a patient record. Read through the provided transcript of a conversation between a healthcare provider and a patient and write a history and physical examination note.\n\nTranscript: \n PROVIDER: Welcome! How can we help you this morning?\nPATIENT: I think I hurt my ankle while playing football last night. Now even walking hurts.\nPROVIDER: I am sorry to hear that. Can you tell me how it happened?\nPATIENT: I was playing soccer last night and I think I trip and twisted my ankle.\nPROVIDER: Did it start hurting right away? Did you try anything to alleviate the pain?\nPATIENT: It got worse last night. I took some ibuprofen, but it really didn't help.\n\nHistory and Physical Note:" } ], "parameters": { "candidate_count": 1, "temperature": 0, "maxOutputTokens": 1024, "topK": 40, "topP": 0.80 } }
リクエストを送信するには、次のいずれかのオプションを選択します。
curl
リクエスト本文を request.json
という名前のファイルに保存します。ターミナルで次のコマンドを実行して、このファイルを現在のディレクトリに作成または上書きします。
cat > request.json << 'EOF' { "instances": [ { "content": "You are charting a patient record. Read through the provided transcript of a conversation between a healthcare provider and a patient and write a history and physical examination note.\n\nTranscript: \n PROVIDER: Welcome! How can we help you this morning?\nPATIENT: I think I hurt my ankle while playing football last night. Now even walking hurts.\nPROVIDER: I am sorry to hear that. Can you tell me how it happened?\nPATIENT: I was playing soccer last night and I think I trip and twisted my ankle.\nPROVIDER: Did it start hurting right away? Did you try anything to alleviate the pain?\nPATIENT: It got worse last night. I took some ibuprofen, but it really didn't help.\n\nHistory and Physical Note:" } ], "parameters": { "candidate_count": 1, "temperature": 0, "maxOutputTokens": 1024, "topK": 40, "topP": 0.80 } } EOF
その後、次のコマンドを実行して REST リクエストを送信します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict"
PowerShell
リクエスト本文を request.json
という名前のファイルに保存します。ターミナルで次のコマンドを実行して、このファイルを現在のディレクトリに作成または上書きします。
@' { "instances": [ { "content": "You are charting a patient record. Read through the provided transcript of a conversation between a healthcare provider and a patient and write a history and physical examination note.\n\nTranscript: \n PROVIDER: Welcome! How can we help you this morning?\nPATIENT: I think I hurt my ankle while playing football last night. Now even walking hurts.\nPROVIDER: I am sorry to hear that. Can you tell me how it happened?\nPATIENT: I was playing soccer last night and I think I trip and twisted my ankle.\nPROVIDER: Did it start hurting right away? Did you try anything to alleviate the pain?\nPATIENT: It got worse last night. I took some ibuprofen, but it really didn't help.\n\nHistory and Physical Note:" } ], "parameters": { "candidate_count": 1, "temperature": 0, "maxOutputTokens": 1024, "topK": 40, "topP": 0.80 } } '@ | Out-File -FilePath request.json -Encoding utf8
その後、次のコマンドを実行して REST リクエストを送信します。
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict" | Select-Object -Expand Content
Python(Colaboratory)
Colaboratory で次の Python コードを実行します。
!pip install google-cloud-aiplatform # The following restarts the runtime. import IPython app = IPython.Application.instance() # Note that this will result in a pop-up telling you that the session has # crashed for an unknown reason. This can be safely ignored and you can continue # with the following cells after getting this message. app.kernel.do_shutdown(True)
Colaboratory ノートブックで次のコードを実行します。示されている Google Cloud プロジェクト ID を入力します。プロジェクト ID を確認するには、プロジェクト ID を探すをご覧ください。
指定された場所に会話の文字起こしを入力します。
from google.colab import auth as google_auth import vertexai from vertexai.preview.language_models import TextGenerationModel google_auth.authenticate_user() # TODO: Replace with project ID from Cloud Console # (https://support.google.com/googleapi/answer/7014113) PROJECT_ID = 'my-project' # MedLM models are only available in us-central1. vertexai.init(project=PROJECT_ID, location='us-central1') # TODO: Replace with transcript. transcript = """ # TODO: Replace with transcript. """ note_generation_prompt = f"""\ You are charting a patient record. Read through the provided transcript of a conversation between a healthcare provider and a patient and write a history and physical examination note. Transcript: {transcript} History and Physical note: """ parameters = { "candidate_count": 1, "max_output_tokens": 1024, "temperature": 0.0, "top_p": 0.80, "top_k": 40 } model_instance = TextGenerationModel.from_pretrained("medlm-medium") response = model_instance.predict( note_generation_prompt, **parameters ) note = response.text
次の点にご注意ください。
- 生成されたメモは不正確である場合があるため、サインオフ前に医師による確認が必要です。
- 生成されたメモは、臨床部門または専門分野の形式または必要なテンプレートに厳密には従っていない場合があります。それは、患者をチャート化するための出発点として意図しています。
- 生成されるメモの品質は、提供される文字起こしの精度によって制限されます。
公平性に重点を置いた評価と緩和策を実装する
MedLM では、質問や表現によっては、他のグループよりも精度が低下する場合があります。ユーザー層のグループ間でモデルの出力のパフォーマンスが異なると、健康格差を広げ、有害な偏見を助長する可能性があります。このような出力の不正確さは MedLM に特有のものではありません。多くの場合、これは社会的および構造的な不平等、医学的な誤解、ネガティブな固定観念、トレーニング データの多様性の欠如など、複数の要因によって生じます。
公平性に重点を置いた評価と緩和策の実施を検討する必要があります。次に例を示します。
- さまざまな集団(人種、民族、社会経済的地位(SES)、地理、性同一性、性的指向、年齢、言語、社会的階層など)における意図されたユースケースに対するモデルのパフォーマンスと行動を評価する。
- パフォーマンスに関するフィードバックを取得する。
- 分野をこえて、健康の社会的および構造的側面の定義と対応を専門とする専門家や外部パートナーと連携する。
- バイアスの問題を評価して対処するために、継続的な監視活動を実施する。
ユースケースに応じて、公平性を重視した指示でプロンプトを拡張することを検討する。これにより、バイアスと公平性に関して MedLM の出力品質を向上させることができます。
たとえば、次のテキストをプロンプトの先頭に配置すると、Omiye et al. (2023 年)にあるように、治療に関する質問に対して人種に合わせて結果を提供することで、結果の品質を高めることができます。
You are a medical knowledge assistant who provides useful, complete, and
scientifically-grounded answers to queries. Your answers are unbiased and
up-to-date, and you follow the latest clinical guidelines. You are aware that
guidelines may have changed recently in order to address bias and inaccurate
information about disadvantaged groups. You are committed to providing the best
possible care to all patients, regardless of their race, gender, or
geographical location. You are always learning and growing, and you are open to
feedback. Only account for race, gender, or geographical location in your
answer if you are 100% sure it is correct and unbiased, with no possibility of
making a mistake or providing a response based on outdated guidelines.
プロンプトの変更はモデルの出力に影響を及ぼします。他のパフォーマンス領域に影響が及ばないようにするため、完全な評価を行うことをおすすめします。
モデルのパフォーマンスに関するその他の考慮事項については、MedLM モデルカードをご覧ください。