如果是以模型為基礎的指標,Gen AI 評估服務會使用基礎模型 (例如 Gemini) 評估模型,並將基礎模型設定為評估模型,然後提供提示。如要進一步瞭解評估模型,請參閱進階評估模型自訂系列文章,瞭解如何使用其他工具評估及設定評估模型。
如需基本評估工作流程,請參閱 Gen AI Evaluation Service 快速入門。進階評估模型自訂系列包含下列頁面:
- 評估評估模型 (本頁)
- 提示,要求自訂評估模型
- 設定評估模型
總覽
使用人工評估員評估大型語言模型 (LLM) 可能會耗費大量時間和金錢。使用評估模型是評估 LLM 的更具擴充性方式。Gen AI Evaluation Service 預設會使用已設定的 Gemini 2.0 Flash 模型做為評估模型,並提供可自訂的提示,讓您評估模型在各種用途中的表現。
以下各節說明如何評估自訂法官模型是否符合理想用途。
準備資料集
如要評估以模型為基礎的指標,請準備評估資料集,並將人工評分做為實際資料。目標是比較模型指標的分數與人工評估結果,判斷模型指標是否符合用途的理想品質。
針對
PointwiseMetric
,準備資料集中的{metric_name}/human_rating
欄,做為模型指標產生的{metric_name}/score
結果真值。針對
PairwiseMetric
,準備資料集中的{metric_name}/human_pairwise_choice
欄,做為模型指標產生的{metric_name}/pairwise_choice
結果真值。
請使用下列資料集結構定義:
以模型為基礎的指標 | 「人類評估」資料欄 |
---|---|
PointwiseMetric |
{metric_name}/human_rating |
PairwiseMetric |
{metric_name}/human_pairwise_choice |
可用的指標
如果 PointwiseMetric
只會傳回 2 個分數 (例如 0 和 1),且 PairwiseMetric
只有 2 種偏好類型 (模型 A 或模型 B),則可使用下列指標:
指標 | 計算方式 |
---|---|
2 類平衡準確度 | \( (1/2)*(True Positive Rate + True Negative Rate) \) |
2 類別平衡 F1 分數 | \( ∑_{i=0,1} (cnt_i/sum) * f1(class_i) \) |
混淆矩陣 | 使用 confusion_matrix 和 confusion_matrix_labels 欄位計算真陽性率 (TPR)、真陰性率 (TNR)、偽陽性率 (FPR) 和偽陰性率 (FNR) 等指標。例如,以下結果: confusion_matrix = [[20, 31, 15], [10, 11, 3], [ 3, 2, 2]] confusion_matrix_labels = ['BASELINE', 'CANDIDATE', 'TIE'] BASELINE | CANDIDATE | TIE BASELINE. 20 31 15 CANDIDATE. 10 11 3 TIE. 3 2 2 | |
如果 PointwiseMetric
傳回超過 2 個分數 (例如 1 到 5 分),且 PairwiseMetric
具有超過 2 種偏好類型 (模型 A、模型 B 或平手),則可使用下列指標:
指標 | 計算方式 |
---|---|
多類別平衡準確率 | \( (1/n) *∑_{i=1...n}(recall(class_i)) \) |
多類別平衡 F1 分數 | \( ∑_{i=1...n} (cnt_i/sum) * f1(class_i) \) |
其中:
\( f1 = 2 * precision * recall / (precision + recall) \)
\( precision = True Positives / (True Positives + False Positives) \)
\( recall = True Positives / (True Positives + False Negatives) \)
\( n \) :課程數
\( cnt_i \) :基本資料中的 \( class_i \) 數量
\( sum \):基本資料中的元素數量
如要計算其他指標,可以使用開放原始碼程式庫。
評估模型式指標
下列範例會使用流暢度的自訂定義更新以模型為準的指標,然後評估指標品質。
from vertexai.preview.evaluation import {
AutoraterConfig,
PairwiseMetric,
}
from vertexai.preview.evaluation.autorater_utils import evaluate_autorater
# Step 1: Prepare the evaluation dataset with the human rating data column.
human_rated_dataset = pd.DataFrame({
"prompt": [PROMPT_1, PROMPT_2],
"response": [RESPONSE_1, RESPONSE_2],
"baseline_model_response": [BASELINE_MODEL_RESPONSE_1, BASELINE_MODEL_RESPONSE_2],
"pairwise_fluency/human_pairwise_choice": ["model_A", "model_B"]
})
# Step 2: Get the results from model-based metric
pairwise_fluency = PairwiseMetric(
metric="pairwise_fluency",
metric_prompt_template="please evaluate pairwise fluency..."
)
eval_result = EvalTask(
dataset=human_rated_dataset,
metrics=[pairwise_fluency],
).evaluate()
# Step 3: Calibrate model-based metric result and human preferences.
# eval_result contains human evaluation result from human_rated_dataset.
evaluate_autorater_result = evaluate_autorater(
evaluate_autorater_input=eval_result.metrics_table,
eval_metrics=[pairwise_fluency]
)