準備評估資料集

對於 Gen AI 評估服務,評估資料集通常包含您要評估的模型回應、用於產生回應的輸入資料,以及可能的真值回應。

評估資料集架構

如要使用模型式指標,資料集必須提供下列資訊:

輸入類型 輸入欄位內容
提示 生成式 AI 模型或應用程式的使用者輸入內容。在某些情況下,這是選填屬性。
回應 要評估的 LLM 推論回覆。
baseline_model_response (逐對指標的必要項目) 用於比較 LLM 回覆與成對評估結果的基準 LLM 推論回覆

如果您使用 Vertex AI SDK for PythonGen AI Evaluation 模組,Gen AI Evaluation Service 可以自動使用您指定的模型生成 responsebaseline_model_response

如要評估其他使用情況,您可能需要提供更多資訊:

多輪對話或即時通訊

輸入類型 輸入欄位內容
記錄 目前回合前,使用者與模型之間的對話記錄。
提示 目前回合中生成式 AI 模型或應用程式的使用者輸入內容。
回應 要評估的 LLM 推論回覆,這類回覆是根據記錄和目前的輪次提示產生。
baseline_model_response (逐對指標的必要項目) 用於比較 LLM 回覆與成對評估結果的基準 LLM 推論回覆,評估結果會根據記錄和目前的輪次提示。

以運算為基礎的指標

資料集必須提供大型語言模型的回覆,以及可供比較的參考資料。

輸入類型 輸入欄位內容
回應 要評估的 LLM 推論回覆。
參考資料 用來比較 LLM 回覆的基準真相。

翻譯指標

資料集必須提供模型的回覆。視用途而定,您也需要提供比較用的參考資料、來源語言的輸入內容,或兩者兼具。

輸入類型 輸入欄位內容
來源 來源文字,也就是預測內容的原文。
回應 要評估的 LLM 推論回覆。
參考資料 用來比較 LLM 回覆的基準真相。這項資訊會以與回覆相同的語言顯示。

視用途而定,您也可以將輸入的使用者提示分解成細微片段 (例如 instructioncontext),並提供提示範本,將這些片段組合成推論結果。如有需要,您也可以提供參考或實際資料資訊:

輸入類型 輸入欄位內容
指示 輸入的使用者提示部分。這是指傳送至 LLM 的推論指令。例如:「請為下列文字內容製作摘要」就是指令。
context 目前回合中生成式 AI 模型或應用程式的使用者輸入內容。
參考資料 用來比較 LLM 回覆的基準真相。

評估資料集的必要輸入內容應與指標一致。如要進一步瞭解如何自訂指標,請參閱「定義評估指標」和「執行評估」。如要進一步瞭解如何在以模型為準的指標中加入參照資料,請參閱「根據輸入資料調整指標提示範本」。

匯入評估用資料集

您可以匯入下列格式的資料集:

  • 儲存在 Cloud Storage 中的 JSONL 或 CSV 檔案

  • BigQuery 資料表

  • Pandas DataFrame

評估資料集範例

本節會以 Pandas DataFrame 格式顯示資料集範例。請注意,這裡僅顯示幾個資料記錄做為範例,評估資料集通常有 100 個以上的資料點。如需準備資料集的最佳做法,請參閱「最佳做法」一節。

以模型為基準的逐點指標

以下是摘要案例,用來示範基於逐點模型的指標範例資料集:

prompts = [
    # Example 1
    (
        "Summarize the text in one sentence: As part of a comprehensive"
        " initiative to tackle urban congestion and foster sustainable urban"
        " living, a major city has revealed ambitious plans for an extensive"
        " overhaul of its public transportation system. The project aims not"
        " only to improve the efficiency and reliability of public transit but"
        " also to reduce the city's carbon footprint and promote eco-friendly"
        " commuting options. City officials anticipate that this strategic"
        " investment will enhance accessibility for residents and visitors"
        " alike, ushering in a new era of efficient, environmentally conscious"
        " urban transportation."
    ),
    # Example 2
    (
        "Summarize the text such that a five-year-old can understand: A team of"
        " archaeologists has unearthed ancient artifacts shedding light on a"
        " previously unknown civilization. The findings challenge existing"
        " historical narratives and provide valuable insights into human"
        " history."
    ),
]

responses = [
    # Example 1
    (
        "A major city is revamping its public transportation system to fight"
        " congestion, reduce emissions, and make getting around greener and"
        " easier."
    ),
    # Example 2
    (
        "Some people who dig for old things found some very special tools and"
        " objects that tell us about people who lived a long, long time ago!"
        " What they found is like a new puzzle piece that helps us understand"
        " how people used to live."
    ),
]

eval_dataset = pd.DataFrame({
    "prompt": prompts,
    "response": responses,
})

以模型為基準的逐對指標

以下範例顯示開放式問答案例,用來示範成對模型式指標的範例資料集。

prompts = [
    # Example 1
    (
        "Based on the context provided, what is the hardest material? Context:"
        " Some might think that steel is the hardest material, or even"
        " titanium. However, diamond is actually the hardest material."
    ),
    # Example 2
    (
        "Based on the context provided, who directed The Godfather? Context:"
        " Mario Puzo and Francis Ford Coppola co-wrote the screenplay for The"
        " Godfather, and the latter directed it as well."
    ),
]

responses = [
    # Example 1
    "Diamond is the hardest material. It is harder than steel or titanium.",
    # Example 2
    "Francis Ford Coppola directed The Godfather.",
]

baseline_model_responses = [
    # Example 1
    "Steel is the hardest material.",
    # Example 2
    "John Smith.",
]

eval_dataset = pd.DataFrame(
  {
    "prompt":  prompts,
    "response":  responses,
    "baseline_model_response": baseline_model_responses,
  }
)

以運算為基礎的指標

以運算為基礎的指標通常需要 reference

eval_dataset = pd.DataFrame({
  "response": ["The Roman Senate was filled with exuberance due to Pompey's defeat in Asia."],
  "reference": ["The Roman Senate was filled with exuberance due to successes against Catiline."],
})

工具使用 (函式呼叫) 指標

以下範例顯示以運算為準的工具使用指標輸入資料:

json_responses = ["""{
    "content": "",
    "tool_calls":[{
      "name":"get_movie_info",
      "arguments": {"movie":"Mission Impossible", "time": "today 7:30PM"}
    }]
  }"""]

json_references = ["""{
    "content": "",
    "tool_calls":[{
      "name":"book_tickets",
      "arguments":{"movie":"Mission Impossible", "time": "today 7:30PM"}
      }]
  }"""]

eval_dataset = pd.DataFrame({
    "response": json_responses,
    "reference": json_references,
})

翻譯用途

以下範例顯示翻譯指標的輸入資料:

  source = [
      "Dem Feuer konnte Einhalt geboten werden",
      "Schulen und Kindergärten wurden eröffnet.",
  ]

  response = [
      "The fire could be stopped",
      "Schools and kindergartens were open",
  ]

  reference = [
      "They were able to control the fire.",
      "Schools and kindergartens opened",
  ]

  eval_dataset = pd.DataFrame({
      "source": source,
      "response": response,
      "reference": reference,
  })

最佳做法

定義評估資料集時,請遵循下列最佳做法:

  • 提供代表輸入類型的範例,模型會在實際運作時處理這些輸入內容。
  • 資料集至少須包含一個評估範例。建議提供約 100 個範例,確保匯總指標品質優良,並取得具統計顯著性的結果。這個大小有助於提高匯總評估結果的信賴度、減少離群值的影響,並確保效能指標反映模型在各種情境下的真實能力。如果提供的範例超過 400 個,匯總指標品質的改善幅度通常會降低。

後續步驟