Criar comandos do MedLM

Os modelos MedLM disponíveis, MedLM médio e grande, são modelos de fundação para respostas e resumos de perguntas médicas. É possível acessar os modelos usando a API MedLM da Vertex AI. Nesta página, você encontra uma visão geral dos modelos de MedLM disponíveis, as APIs usadas para interagir com os modelos e maneiras de personalizar os comportamentos.

Antes de começar

  • Consulte Visão geral dos modelos MedLM para ver informações, incluindo responsabilidades do cliente, informações regulamentares e práticas recomendadas de IA responsável.
  • Consulte o card de um modelo do MedLM para conferir os detalhes dele, como o uso pretendido, as informações gerais dos dados e as informações de segurança. Clique no seguinte link para fazer o download de uma versão em PDF do card do modelo do MedLM:

    Faça o download do card do modelo do MedLM

Design de comandos

Para interagir com os modelos do MedLM, você envia instruções em linguagem natural, também chamadas de comandos, que informam ao modelo o que você quer que ele gere. No entanto, os LLMs podem se comportar de forma imprevisível. O design rápido é um processo iterativo de tentativa e erro que exige tempo e prática para ser proficiente. Para saber mais sobre as estratégias gerais de design de prompts, consulte Introdução ao design de prompts. Para orientações específicas sobre a criação de comandos de texto em uma tarefa, consulte Criar comandos em texto.

Casos de uso

  • Resumo: crie uma versão mais curta de um documento que incorpore informações pertinentes do texto original. Por exemplo, resuma uma nota médica descrevendo uma consulta ambulatorial e extraia informações relevantes para pontos de dados específicos.
  • Resposta a perguntas: responda a perguntas no texto. Por exemplo, talvez você queira gerar um plano de nutrição abrangente e com fundamento médico, com base nas condições de saúde e nas preferências alimentares do paciente.

Modelos compatíveis

  • medlm-medium
  • medlm-large

Começar

Os exemplos a seguir mostram como começar a usar a API MedLM usando as seguintes interfaces:

  • A API REST da Vertex AI
  • SDK da Vertex AI para Python
  • Vertex AI Studio

REST

Antes de usar os dados da solicitação abaixo, faça as substituições a seguir:

  • PROJECT_ID: o ID do projeto.
  • MEDLM_MODEL: o modelo MedLM, medlm-medium ou medlm-large.

Método HTTP e URL:

POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict

Corpo JSON da solicitação:

{
  "instances": [
    {
      "content": "Question: What causes you to get ringworm?"
    }
  ],
  "parameters": {
    "temperature": 0,
    "maxOutputTokens": 256,
    "topK": 40,
    "topP": 0.95
  }
}

Para enviar a solicitação, escolha uma destas opções:

curl

Salve o corpo da solicitação em um arquivo chamado request.json. Execute o comando a seguir no terminal para criar ou substituir esse arquivo no diretório atual:

cat > request.json << 'EOF'
{
  "instances": [
    {
      "content": "Question: What causes you to get ringworm?"
    }
  ],
  "parameters": {
    "temperature": 0,
    "maxOutputTokens": 256,
    "topK": 40,
    "topP": 0.95
  }
}
EOF

Depois execute o comando a seguir para enviar a solicitação 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

Salve o corpo da solicitação em um arquivo chamado request.json. Execute o comando a seguir no terminal para criar ou substituir esse arquivo no diretório atual:

@'
{
  "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

Depois execute o comando a seguir para enviar a solicitação 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)

Execute o código Python a seguir no Colaboratory.

!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)

Execute o código a seguir no seu notebook do Colaboratory. Insira o ID do projeto do Google Cloud onde indicado. Para encontrar o ID do projeto, consulte Localizar o ID do projeto.

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

Use o Vertex AI Studio para projetar, testar e personalizar os comandos enviados à API MedLM. Antes de usar o Vertex AI Studio para MedLM, consulte Testar o Vertex AI Studio para conferir os pré-requisitos.

Para testar um comando do MedLM usando o Vertex AI Studio no console do Google Cloud, faça o seguinte:

  1. Na seção "Vertex AI" do console do Google Cloud, acesse a página do Vertex AI Studio.

    Acessar o Vertex AI Studio

  2. Clique em Começar.
  3. Clique em Criar prompt.
  4. No menu Modelo, selecione MedLM-Medium ou MedLM-Large.
  5. Digite seu comando no campo Comando.
  6. (Opcional) É possível ajustar os valores de Temperatura e Limite de tokens para testar como eles afetam a resposta. Recomendamos usar os valores padrão. Se você não tiver certeza sobre quais valores usar, use os valores padrão.
  7. Clique em Enviar para gerar uma resposta.
  8. (Opcional) Para salvar um comando, clique em Salvar.
  9. (Opcional) Para ver o código Python ou um comando curl do prompt, clique em Receber código.

Respostas a perguntas

As seções a seguir contêm exemplos de comandos para responder a perguntas. Cada exemplo de comando inclui o modelo recomendado e os valores de parâmetro.

Respostas a perguntas mais longas

Os exemplos a seguir mostram como a API MedLM responde a uma pergunta longa de medicina formulada como uma consulta.

REST

Antes de usar os dados da solicitação abaixo, faça as substituições a seguir:

  • PROJECT_ID: o ID do projeto.
  • MEDLM_MODEL: o modelo MedLM, medlm-medium ou medlm-large.

Método HTTP e URL:

POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict

Corpo JSON da solicitação:

{
  "instances": [
    {
      "content": "Question: What causes you to get ringworm?"
    }
  ],
  "parameters": {
    "temperature": 0,
    "maxOutputTokens": 256,
    "topK": 40,
    "topP": 0.95
  }
}

Para enviar a solicitação, escolha uma destas opções:

curl

Salve o corpo da solicitação em um arquivo chamado request.json. Execute o comando a seguir no terminal para criar ou substituir esse arquivo no diretório atual:

cat > request.json << 'EOF'
{
  "instances": [
    {
      "content": "Question: What causes you to get ringworm?"
    }
  ],
  "parameters": {
    "temperature": 0,
    "maxOutputTokens": 256,
    "topK": 40,
    "topP": 0.95
  }
}
EOF

Depois execute o comando a seguir para enviar a solicitação 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

Salve o corpo da solicitação em um arquivo chamado request.json. Execute o comando a seguir no terminal para criar ou substituir esse arquivo no diretório atual:

@'
{
  "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

Depois execute o comando a seguir para enviar a solicitação 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
 

Respostas a perguntas de múltipla escolha

Os exemplos a seguir mostram como a API MedLM responde a uma pergunta médica de múltipla escolha. O comando é o seguinte:

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

Antes de usar os dados da solicitação abaixo, faça as substituições a seguir:

  • PROJECT_ID: o ID do projeto.
  • MEDLM_MODEL: o modelo MedLM, medlm-medium ou medlm-large.

Método HTTP e URL:

POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict

Corpo JSON da solicitação:

{
  "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
  }
}

Para enviar a solicitação, escolha uma destas opções:

curl

Salve o corpo da solicitação em um arquivo chamado request.json. Execute o comando a seguir no terminal para criar ou substituir esse arquivo no diretório atual:

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

Depois execute o comando a seguir para enviar a solicitação 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

Salve o corpo da solicitação em um arquivo chamado request.json. Execute o comando a seguir no terminal para criar ou substituir esse arquivo no diretório atual:

@'
{
  "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

Depois execute o comando a seguir para enviar a solicitação 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
 

Prompts de resumo

As seções a seguir contêm exemplos de comandos de resumo. Cada exemplo de comando inclui o modelo recomendado e os valores de parâmetro.

Escreva um resumo após a visita

Os exemplos a seguir mostram como gerar um resumo após a visita para um paciente com base em uma anotação de visita ambulatorial. O comando contém o seguinte:

  • Um preâmbulo contendo a instrução do modelo.
  • Uma descrição de cada campo a extrair para o resumo.

O formato do resumo após a visita é baseado em Sieferd et al. (2019) e recomendações da UK Academy of Medical Royal Colleges (link em inglês). Também é possível adicionar exemplos few-shot antes das notas e dos resumos.

O comando é o seguinte:

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

Antes de usar os dados da solicitação abaixo, faça as substituições a seguir:

  • PROJECT_ID: o ID do projeto.
  • MEDLM_MODEL: o modelo MedLM, medlm-medium ou medlm-large.
  • INPUT_NOTE: a nota de entrada a ser resumida.

Método HTTP e URL:

POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict

Corpo JSON da solicitação:

{
  "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
  }
}

Para enviar a solicitação, escolha uma destas opções:

curl

Salve o corpo da solicitação em um arquivo chamado request.json. Execute o comando a seguir no terminal para criar ou substituir esse arquivo no diretório atual:

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

Depois execute o comando a seguir para enviar a solicitação 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

Salve o corpo da solicitação em um arquivo chamado request.json. Execute o comando a seguir no terminal para criar ou substituir esse arquivo no diretório atual:

@'
{
  "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

Depois execute o comando a seguir para enviar a solicitação 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
 

Escrever uma nota de histórico e exame físico (H&P, na sigla em inglês) de uma transcrição

Os exemplos a seguir mostram como acelerar a documentação clínica ao enviar uma solicitação à API MedLM para escrever um rascunho do histórico e da nota do exame físico (H&P) da transcrição de uma conversa médica entre um profissional e um paciente.

A nota do H&P é uma observação clínica abrangente que documenta o histórico médico do paciente e o exame físico feito pelo profissional. O MedLM pode coletar muitas das informações clínicas necessárias para redigir essa observação da conversa entre o profissional e o paciente durante a consulta médica.

Suponha que você tenha uma transcrição de uma conversa médica no formato a seguir. Os participantes da conversa são conhecidos:

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

Antes de usar os dados da solicitação abaixo, faça as substituições a seguir:

  • PROJECT_ID: o ID do projeto.
  • MEDLM_MODEL: o modelo MedLM, medlm-medium ou medlm-large.

Método HTTP e URL:

POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/MEDLM_MODEL:predict

Corpo JSON da solicitação:

{
  "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
  }
}

Para enviar a solicitação, escolha uma destas opções:

curl

Salve o corpo da solicitação em um arquivo chamado request.json. Execute o comando a seguir no terminal para criar ou substituir esse arquivo no diretório atual:

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

Depois execute o comando a seguir para enviar a solicitação 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

Salve o corpo da solicitação em um arquivo chamado request.json. Execute o comando a seguir no terminal para criar ou substituir esse arquivo no diretório atual:

@'
{
  "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

Depois execute o comando a seguir para enviar a solicitação 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)

Execute o código Python a seguir no Colaboratory.

!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)

Execute o código a seguir no seu notebook do Colaboratory. Insira o ID do projeto do Google Cloud onde indicado. Para encontrar o ID do projeto, consulte Localizar o ID do projeto.

Insira o histórico médico quando indicado.

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

Observações:

  • A nota gerada pode ter imprecisões e precisar ser revisada por um médico antes da aprovação.
  • A nota gerada pode não aderir estritamente ao formato ou ao modelo necessário do departamento clínico ou da especialidade. Ela é um ponto de partida para criar um gráfico do paciente.
  • A qualidade da nota gerada é limitada pela precisão da transcrição fornecida.

Implementar avaliações e mitigações focadas em equidade

O MedLM pode produzir resultados menos precisos para alguns grupos em comparação com outros, dependendo da pergunta e da formulação. Diferentes desempenhos dos resultados do modelo em todos os grupos demográficos têm o potencial de agravar as desigualdades de saúde e perpetuar vieses prejudiciais. Essas imprecisões não são exclusivas do MedLM e geralmente resultam de vários fatores, como desigualdades sociais e estruturais existentes, equívocos médicos, estereótipos negativos e falta de diversidade nos dados de treinamento.

Considere implementar avaliações e mitigações focadas em equidade. Isso inclui o seguinte:

  • Avaliação do desempenho e do comportamento do modelo para casos de uso pretendidos em várias populações, como raça e etnia, status socioeconômico (SES), região geográfica, identidade de gênero, orientação sexual, idade, preferência de idioma, classe social etc.
  • Coletar feedback sobre o desempenho.
  • Envolver especialistas interdisciplinares e parceiros externos especializados em definir e abordar aspectos sociais e estruturais da saúde.
  • Realizar esforços contínuos de monitoramento para avaliar e resolver questões de viés.

Dependendo do caso de uso, considere aumentar o comando com instruções focadas em equidade, o que pode melhorar a qualidade das saídas do MedLM em relação a viés e equidade.

Por exemplo, o texto a seguir, quando colocado no início de um comando, melhora a qualidade dos resultados em questões de medicina baseada em raça, conforme mostrado em 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.

Alterar os prompts influencia as saídas do modelo. Portanto, é recomendado fazer avaliações completas para garantir que outras áreas de desempenho não sejam afetadas.

Consulte o card do modelo MedLM para mais considerações sobre o desempenho do modelo.