以模型為基礎的指標可讓您根據條件和用途,自訂評估指標的生成方式。本指南說明如何設定評估模型,並涵蓋下列主題: 如需基本評估工作流程,請參閱 Gen AI Evaluation Service 快速入門。進階評估模型自訂系列包含下列頁面: 您可以透過多種方式設定評估模型,提升品質。下表提供各方法的概要比較。 Gemini 模型可以接收系統指令,這組指令會影響模型處理提示的方式。從模型初始化或生成內容時,您可以使用系統指令指定產品層級的行為,例如角色、人物、情境資訊,以及說明風格和語氣。評估模型通常會比輸入提示更重視系統指令。 如需支援系統指令的型號清單,請參閱「支援的型號」。 下列範例使用 Vertex AI SDK,在 您可以使用 對於 如要減少評估結果的偏誤,可以啟用回應翻轉功能。這項技術會將一半的通話傳送至評估模型,並交換基準模型和候選模型的回覆。以下範例說明如何使用 Vertex AI SDK 啟用回應翻轉功能: 評估期間,評估模型的回覆可能會出現隨機性。如要減輕這種隨機性造成的影響,並產生更一致的結果,可以使用額外的取樣。這項技術也稱為「多重取樣」。 不過,提高取樣率也會增加完成要求的延遲時間。您可以使用 使用 Vertex AI SDK 時,您可以為每個要求指定要執行的樣本數: 如果您有適合評估用途的調整資料,可以使用 Vertex AI SDK 調整 Gemini 模型做為評估模型,並使用調整後的模型進行評估。您可以透過
選擇設定選項
選項
說明
用途
系統操作說明
為評估模型提供高階的持續性指令,影響模型對後續所有評估提示的行為。
需要為整個評估工作中的評估模型定義一致的角色、角色或輸出格式。
回應翻轉
在半數的評估通話中,交換基準模型和候選模型回覆的位置。
在逐對評估中,評估模型可能會偏好第一個或第二個位置的回覆,因此為了減少潛在的位置偏誤,
多重取樣
針對相同輸入內容多次呼叫評估模型,並匯總結果。
為減少評估模型回覆的隨機性,進而提升評估分數的一致性和可靠性。
調整後的評估模型
使用微調的 LLM 做為評估的評估模型。
對於需要細微理解或特定領域知識的專業評估工作,通用模型無法勝任。
系統指示
PointwiseMetric
的指標層級新增 system_instruction
:system_instruction = "You are an expert evaluator."
linguistic_acceptability = PointwiseMetric(
metric="linguistic_acceptability",
metric_prompt_template=linguistic_acceptability_metric_prompt_template,
system_instruction=system_instruction,
)
eval_result = EvalTask(
dataset=EVAL_DATASET,
metrics=[linguistic_acceptability]
).evaluate()
PairwiseMetric
採取相同做法。回應翻轉
PairwiseMetrics
,Gen AI Evaluation Service 會使用基準模型和候選模型的相關回覆。評估模型會根據 metric_prompt_template
中的條件,評估哪個回覆較符合條件。不過,在特定設定中,評估模型可能會偏向基準或候選模型。from vertexai.preview.evaluation import AutoraterConfig
pairwise_relevance_prompt_template = """
# Instruction
…
### Response A
{baseline_model_response}
### Response B
{candidate_model_response}
"""
my_pairwise_metric = PairwiseMetric(
metric="my_pairwise_metric",
metric_prompt_template=pairwise_relevance_prompt_template,
candidate_response_field_name = "candidate_model_response",
baseline_response_field_name = "baseline_model_response"
)
# Define an AutoraterConfig with flip_enabled
my_autorater_config = AutoraterConfig(flip_enabled=True)
# Define an EvalTask with autorater_config
flip_enabled_eval_result = EvalTask(
dataset=EVAL_DATASET,
metrics=[my_pairwise_metric],
autorater_config=my_autorater_config,
).evaluate()
多重取樣
AutoraterConfig
,將取樣計數值更新為介於 1 到 32 之間的整數。建議使用預設值 sampling_count
4,以平衡隨機性和延遲。from vertexai.preview.evaluation import AutoraterConfig
# Define customized sampling count in AutoraterConfig
autorater_config = AutoraterConfig(sampling_count=6)
# Run evaluation with the sampling count.
eval_result = EvalTask(
dataset=EVAL_DATASET,
metrics=[METRICS],
autorater_config=autorater_config
).evaluate()
調整後的評估模型
AutoraterConfig
,將微調模型指定為評估模型:from vertexai.preview.evaluation import {
AutoraterConfig,
PairwiseMetric,
tune_autorater,
evaluate_autorater,
}
# Tune a model to be the judge model. The tune_autorater helper function returns an AutoraterConfig with the judge model set as the tuned model.
autorater_config: AutoRaterConfig = tune_autorater(
base_model="gemini-2.0-flash",
train_dataset=f"{BUCKET_URI}/train/sft_train_samples.jsonl",
validation_dataset=f"{BUCKET_URI}/val/sft_val_samples.jsonl",
tuned_model_display_name=tuned_model_display_name,
)
# Alternatively, you can set up the judge model with an existing tuned model endpoint
autorater_config = AutoraterConfig(autorater_model=TUNED_MODEL)
# Use the tuned judge model
eval_result = EvalTask(
dataset=EVAL_DATASET,
metrics=[METRICS],
autorater_config=autorater_config,
).evaluate()
後續步驟
設定評分模型
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-19 (世界標準時間)。