MedLM API

MedLM 是經過微調的基礎模型系列,適用於醫療照護產業。Med-PaLM 2 是 Google 研究開發的文字模型之一,也是 MedLM 的基礎。此外,這也是第一個在回答美國醫師執照考試 (USMLE) 類型問題時,達到人類專家程度的 AI 系統。這些模型的開發過程參考了特定客戶需求,例如回答醫療問題和草擬摘要。

MedLM 模型資訊卡

MedLM 模型資訊卡會列出模型詳細資料,例如 MedLM 的預期用途、資料總覽和安全性資訊。點選下列連結即可下載 MedLM 模型資訊卡的 PDF 版本:

下載 MedLM 模型資訊卡

用途

  • 回答問題:根據文字形式的醫療相關問題,提供草擬的答案。
  • 摘要:根據原文的相關資訊,草擬簡短版文件 (例如就診後摘要或病史和體檢記錄)。

如要進一步瞭解如何設計文字提示,請參閱「提示策略總覽」。

HTTP 要求

MedLM-medium (medlm-medium)

POST https://us-central1-aiplatform.googleapis.com/v1/projects/{PROJECT_ID}/locations/us-central1/publishers/google/models/medlm-medium:predict

MedLM-large (medlm-large)

POST https://us-central1-aiplatform.googleapis.com/v1/projects/{PROJECT_ID}/locations/us-central1/publishers/google/models/medlm-large:predict

詳情請參閱 predict 方法。

模型版本

MedLM 提供下列模型:

  • MedLM-medium (medlm-medium)
  • MedLM-large (medlm-large)

下表列出可用的穩定模型版本:

medlm-medium 模型 發布日期
medlm-medium 2023 年 12 月 13 日
medlm-large 模型 發布日期
medlm-large 2023 年 12 月 13 日

MedLM-medium 和 MedLM-large 有各自的端點,可為客戶提供更多使用彈性。MedLM-medium 可為顧客提供更佳的輸送量,並納入較新的資料。MedLM-large 與預先發布階段的模型相同。這兩種模型都會在產品生命週期內持續更新。本頁的「MedLM」是指這兩種模型。

詳情請參閱「模型版本和生命週期」。

MedLM 安全篩選器和屬性

系統會根據安全屬性清單,評估透過 MedLM API 處理的內容,包括「有害類別」和可能較敏感的主題。如果看到備用回覆,例如「我只是語言模型,無法提供這方面的協助」,表示提示或回覆觸發了安全篩選器。

安全門檻

使用 Vertex AI Studio 時,您可以調整安全篩選器門檻,決定看到可能有害回覆的機率。系統會依據模型回應含有騷擾、仇恨言論、危險或煽情露骨內容的機率封鎖回應。安全篩選設定位於 Vertex AI Studio 提示欄位的右側。你可以從三個選項中選擇:block mostblock someblock few

Console-image

測試信賴度和嚴重程度門檻

您可以測試 Google 的安全篩選器,並根據自家業務定義適當的信心門檻。您可以使用這些門檻,全面偵測違反 Google 使用政策或服務條款的內容,並採取適當行動。

可信度分數僅為預測結果,不應做為可靠性或準確度的依據。Google 不負責解讀或使用這些分數來做出業務決策。

為安全且負責任地運用這項技術,除了內建技術防護措施外,請務必考量特定用途、使用者和業務環境的其他風險。

建議採取下列步驟:

  1. 評估應用程式的安全風險。
  2. 考慮調整設定,降低安全風險。
  3. 根據您的用途執行適當的安全測試。
  4. 徵求使用者意見回饋並監控內容。

如要瞭解詳情,請參閱 Google 的負責任的 AI 建議。

要求主體

{
  "instances": [
    {
      "content": string
    }
  ],
  "parameters": {
    "temperature": number,
    "maxOutputTokens": integer,
    "topK": integer,
    "topP": number
  }
}

請使用 medlm-mediummedlm-large 模型的下列參數。 詳情請參閱「設計文字提示」。

參數 說明 可接受的值

content

輸入文字,生成模型回覆。提示可以包含前言、問題、建議、指示或範例。 文字

temperature

系統會在生成回覆時使用溫度進行取樣,也就是套用 topPtopK 時。溫度參數會決定選取詞元時的隨機程度。 如果希望提示生成較不具開放性和創意性的回覆,建議調低溫度參數。另一方面,如果溫度參數較高,則可能產生較多元或有創意的結果。如果溫度參數為 0,模型一律會選取可能性最高的詞元。在這種情況下,特定提示的回覆大多是確定性的,但仍可能出現少量差異。

如果模型的回覆太普通、太短或提供了備用回覆,再試試看調高 Temperature。

0.0–1.0

Default: 0.2

maxOutputTokens

回覆內可以生成的權杖數量上限。一個詞元約為四個字元。100 個符記約等於 60 到 80 個字。

如要取得較短的回覆,請指定較低的值;如要取得可能較長的回覆,請調高此值。

1–8192 medlm-medium

1–1024 for medlm-large

topK

「Top-K」會影響模型選取輸出符記的方式。如果 Top-K 設為 1,代表下一個所選詞元是模型詞彙表的所有詞元中可能性最高者 (也稱為「貪婪解碼」)。如果 Top-K 設為 3,則代表模型會依據 temperature,從可能性最高的 3 個詞元中選取下一個詞元。

在每個符記選取步驟中,模型會對機率最高的「Top-K」符記取樣,接著進一步根據「Top-P」篩選詞元,最後依 temperature 選出最終詞元。

如要取得較不隨機的回覆,請指定較低的值;如要取得較隨機的回覆,請調高此值。

1–40

Default: 40

topP

「Top-P」會影響模型選取輸出符記的方式。模型會按照可能性最高到最低的順序選取符記,直到所選符記的可能性總和等於 Top-P 值。舉例來說,假設詞元 A、B 和 C 的可能性分別為 0.3、0.2 和 0.1,而「Top-P」值為 0.5,模型會依據 temperature 選擇 A 或 B 做為下一個詞元,並排除 C。

如要取得較不隨機的回覆,請指定較低的值;如要取得較隨機的回覆,請調高此值。

0.0–1.0

Default: 0.8

要求範例

使用 MedLM API 時,請務必納入提示工程。舉例來說,我們強烈建議您在每個提示的開頭提供適當的特定工作指示。詳情請參閱「提示簡介」。

REST

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_ID:您的專案 ID
  • MEDLM_MODEL:MedLM 模型,可以是 medlm-mediummedlm-large

HTTP 方法和網址:

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
 

回應主體

{
  "predictions": [
    {
      "content": string,
      "citationMetadata": {
        "citations": [
          {
            "startIndex": integer,
            "endIndex": integer,
            "url": string,
            "title": string,
            "license": string,
            "publicationDate": string
          }
        ]
      },
      "logprobs": {
        "tokenLogProbs": [ float ],
        "tokens": [ string ],
        "topLogProbs": [ { map<string, float> } ]
      },
      "safetyAttributes": {
        "categories": [ string ],
        "blocked": boolean,
        "scores": [ float ],
        "errors": [ int ]
      }
    }
  ],
  "metadata": {
    "tokenMetadata": {
      "input_token_count": {
        "total_tokens": integer,
        "total_billable_characters": integer
      },
      "output_token_count": {
        "total_tokens": integer,
        "total_billable_characters": integer
      }
    }
  }
}
回應元素 說明
content 根據輸入文字生成的結果。
categories 與生成內容相關聯的安全屬性類別顯示名稱。順序與分數相符。
scores 每個類別的可信度分數,分數越高表示可信度越高。
blocked 指出模型輸入或輸出內容是否遭到封鎖的旗標。
errors 錯誤代碼,用於識別輸入或輸出內容遭到封鎖的原因。如需錯誤代碼清單,請參閱「安全篩選器和屬性」。
startIndex 引文在預測輸出內容中的起始索引 (含)。必須大於或等於 0,且小於 end_index
endIndex 預測輸出中引文結尾的索引 (不含)。必須大於 start_index 且小於 len(output)
url 與這項引用內容相關聯的網址。如有,這個網址會連結至這項引文的來源網頁。網址可能包括新聞網站、GitHub 存放區等。
title 與這項引用內容相關聯的標題。如有,則是指這項引文的來源標題。可能包括新聞標題、書名等。
license 與朗讀內容相關聯的授權。如有,則是指此引文來源的授權。可能的授權包括程式碼授權,例如 MIT 授權。
publicationDate 與這項引用內容相關聯的出版日期。如果有的話,是指這項引文的來源發布日期。可能格式為 YYYY、YYYY-MM、YYYY-MM-DD。
input_token_count 輸入權杖數量。這是指所有提示、前置字元和後置字元的權杖總數。
output_token_count 輸出權杖數量。這是指所有預測結果中 content 的權杖總數。
tokens 取樣的權杖。
tokenLogProbs 取樣符記的記錄機率。
topLogProb 每個步驟中最有可能的候選符記及其對數機率。
logprobs `logprobs` 參數的結果。1-1 mapping to `candidates`。

回應範例

{
  "predictions": [
    {
      "citationMetadata": {
        "citations": []
      },
      "content": "\n\nAnswer and Explanation:\nRingworm is a fungal infection of the skin that is caused by a type of fungus called dermatophyte. Dermatophytes can live on the skin, hair, and nails, and they can be spread from person to person through direct contact or through contact with contaminated objects.\n\nRingworm can cause a variety of symptoms, including:\n\n* A red, itchy rash\n* A raised, circular border\n* Blisters or scales\n* Hair loss\n\nRingworm is most commonly treated with antifungal medications, which can be applied to the skin or taken by mouth. In some cases, surgery may be necessary to remove infected hair or nails.",
      "safetyAttributes": {
        "scores": [
          1
        ],
        "blocked": false,
        "categories": [
          "Health"
        ]
      }
    }
  ],
  "metadata": {
    "tokenMetadata": {
      "outputTokenCount": {
        "totalTokens": 140,
        "totalBillableCharacters": 508
      },
      "inputTokenCount": {
        "totalTokens": 10,
        "totalBillableCharacters": 36
      }
    }
  }
}