本指南說明如何使用 Gen AI Evaluation Service API 評估大型語言模型 (LLM)。本指南涵蓋下列主題:
您可以使用 Gen AI 評估服務,依據自己的標準,透過多項指標評估大型語言模型 (LLM)。您提供推論時間輸入內容、LLM 回覆和其他參數,Gen AI 評估服務就會傳回評估工作專用的指標。
指標包括以模型為基礎的指標 (例如 PointwiseMetric
和 PairwiseMetric
),以及在記憶體中計算的指標 (例如 rouge
、bleu
和工具函式呼叫指標)。PointwiseMetric
和 PairwiseMetric
是以模型為基礎的通用指標,您可以根據自己的條件自訂。這項服務會直接接收模型提供的預測結果,因此您可以在 Vertex AI 支援的任何模型上執行推論和評估。
如要進一步瞭解如何評估模型,請參閱 Gen AI 評估服務總覽。
限制
評估服務有下列限制:
- 首次呼叫時,評估服務可能會有傳播延遲。
- 大多數以模型為基礎的指標都會耗用 gemini-2.0-flash 配額,因為 Gen AI Evaluation Service 會使用
gemini-2.0-flash
做為基礎判斷模型來計算這些指標。 - 部分以模型為準的指標 (例如 MetricX 和 COMET) 使用不同的機器學習模型,不會耗用 gemini-2.0-flash 配額。
指標類型
生成式 AI 評估服務 API 提供多種指標類別,可評估模型效能的不同面向。下表提供概要總覽,協助您為用途選擇合適的指標。
指標類別 | 說明 | 用途 |
---|---|---|
詞彙指標 (例如 bleu 、rouge 、exact_match ) |
這些指標會根據模型預測與參考 (真值) 文字的重疊程度計算分數。快速且客觀。 | 適合用於有明確「正確」答案的任務,例如翻譯或事實型問題回答,這類任務的品質可透過與參考資料的相似度來評估。 |
以模型為基準的逐點指標 (例如 fluency 、safety 、groundedness 、summarization_quality ) |
這類指標會使用評估模型,根據特定條件 (例如流暢度或安全性) 評估單一模型的回覆品質,不需要參考答案。 | 最適合評估生成文字的主觀特質,例如回覆的創意、連貫性或安全性,這類特質沒有單一正確答案。 |
以模型為基準的逐對指標 (例如 pairwise_summarization_quality ) |
這些指標會使用評估模型比較兩個模型的回應 (例如基準模型和候選模型),並判斷哪個模型的回應較佳。 | 適用於 A/B 測試,可直接比較兩個不同模型或同一模型兩個版本在相同工作上的成效。 |
工具使用指標 (例如 tool_call_valid 、tool_name_match ) |
這些指標會檢查語法是否有效、工具名稱是否正確,以及參數是否準確,藉此評估模型正確使用工具 (函式呼叫) 的能力。 | 評估模型時,如果模型設計為透過工具呼叫與外部 API 或系統互動,這項功能就非常重要。 |
自訂指標 ( pointwise_metric 、pairwise_metric ) |
這些範本提供彈性架構,方便您使用提示範本定義自己的評估條件。接著,這項服務會使用評估模型,根據自訂指令評估回覆內容。 | 對於預先定義的指標不足以評估的專業評估工作,您需要根據特定領域的獨特需求評估效能。 |
專業指標 ( comet 、metricx ) |
專為特定工作設計的高度專業指標,主要用於評估機器翻譯品質。 | 用於機器翻譯工作,可進行細緻的評估,而不只是簡單的詞彙比對。 |
語法範例
下列範例顯示傳送評估要求時的語法。
curl
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}:evaluateInstances \ -d '{ "pointwise_metric_input" : { "metric_spec" : { ... }, "instance": { ... }, } }'
Python
import json from google import auth from google.api_core import exceptions from google.auth.transport import requests as google_auth_requests creds, _ = auth.default( scopes=['https://www.googleapis.com/auth/cloud-platform']) data = { ... } uri = f'https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}:evaluateInstances' result = google_auth_requests.AuthorizedSession(creds).post(uri, json=data) print(json.dumps(result.json(), indent=2))
參數詳細資料
本節將詳細說明各項評估指標的要求和回應物件。
要求主體
頂層要求主體包含下列其中一個指標輸入物件。
參數 | |
---|---|
|
自由參加: 評估預測結果是否與參照完全相符。 |
|
自由參加: 比較預測結果與參照內容,計算 BLEU 分數。 |
|
自由參加: 比較預測結果與參照內容,計算 ROUGE 分數。 |
|
自由參加: 評估單一回覆的語言流暢度。 |
|
自由參加: 評估單一回覆的連貫性。 |
|
自由參加: 評估單一回覆的安全等級。 |
|
自由參加: 評估回覆是否以提供的內容為依據。 |
|
自由參加: 評估回覆內容是否符合指定指示。 |
|
自由參加: 評估回覆的整體摘要品質。 |
|
自由參加: 比較兩則回覆的摘要品質。 |
|
自由參加: 評估摘要是否實用,以及是否包含原文的必要詳細資料。 |
|
自由參加: 評估摘要的詳細程度。 |
|
自由參加: 根據提供的內容,評估問題答案的整體品質。 |
|
自由參加: 根據提供的脈絡,比較兩個問題答案的品質。 |
|
自由參加: 評估答案與問題的關聯性。 |
|
自由參加: 檢查關鍵詳細資料,評估答案的實用程度。 |
|
自由參加: 評估問題答案是否正確。 |
|
自由參加: 自訂逐點評估的輸入內容。 |
|
自由參加: 自訂逐對評估的輸入內容。 |
|
自由參加: 評估回覆是否預測有效的工具呼叫。 |
|
自由參加: 評估回應是否在工具呼叫中預測正確的工具名稱。 |
|
自由參加: 評估回應是否在工具呼叫中預測正確的參數名稱。 |
|
自由參加: 評估回應是否在工具呼叫中預測正確的參數名稱和值。 |
|
自由參加: 使用 COMET 評估的輸入內容。 |
|
自由參加: 使用 MetricX 評估的輸入內容。 |
完全比對 (exact_match_input
)
輸入 (ExactMatchInput
)
{ "exact_match_input": { "metric_spec": {}, "instances": [ { "prediction": string, "reference": string } ] } }
參數 | |
---|---|
|
選用: 指定指標的行為。 |
|
自由參加: 一或多個評估例項,每個例項都包含 LLM 回應和參照。 |
|
自由參加: LLM 回覆。 |
|
自由參加: 基準真相或參考回覆。 |
輸出 (ExactMatchResults
)
{ "exact_match_results": { "exact_match_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
評估結果陣列,每個輸入執行個體各有一個結果。 |
|
可以是下列其中一項:
|
BLEU (bleu_input
)
輸入 (BleuInput
)
{ "bleu_input": { "metric_spec": { "use_effective_order": bool }, "instances": [ { "prediction": string, "reference": string } ] } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 指定是否要考慮沒有相符項目的 n 元語法順序。 |
|
自由參加: 一或多個評估例項,每個例項都包含 LLM 回應和參照。 |
|
自由參加: LLM 回覆。 |
|
自由參加: 基準真相或參考回覆。 |
輸出 (BleuResults
)
{ "bleu_results": { "bleu_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
評估結果陣列,每個輸入執行個體各有一個結果。 |
|
|
ROUGE (rouge_input
)
輸入 (RougeInput
)
{ "rouge_input": { "metric_spec": { "rouge_type": string, "use_stemmer": bool, "split_summaries": bool }, "instances": [ { "prediction": string, "reference": string } ] } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 支援的值:
|
|
自由參加: 指定是否要使用 Porter 詞幹還原器去除字尾,以提高比對準確度。 |
|
自由參加: 指定是否要在 |
|
自由參加: 一或多個評估例項,每個例項都包含 LLM 回應和參照。 |
|
自由參加: LLM 回覆。 |
|
自由參加: 基準真相或參考回覆。 |
輸出 (RougeResults
)
{ "rouge_results": { "rouge_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
評估結果陣列,每個輸入執行個體各有一個結果。 |
|
|
流暢度 (fluency_input
)
輸入 (FluencyInput
)
{ "fluency_input": { "metric_spec": {}, "instance": { "prediction": string } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括 LLM 回覆。 |
|
自由參加: LLM 回覆。 |
輸出 (FluencyResult
)
{ "fluency_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
連貫性 (coherence_input
)
輸入 (CoherenceInput
)
{ "coherence_input": { "metric_spec": {}, "instance": { "prediction": string } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括 LLM 回覆。 |
|
自由參加: LLM 回覆。 |
輸出 (CoherenceResult
)
{ "coherence_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
安全性 (safety_input
)
輸入 (SafetyInput
)
{ "safety_input": { "metric_spec": {}, "instance": { "prediction": string } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括 LLM 回覆。 |
|
自由參加: LLM 回覆。 |
輸出 (SafetyResult
)
{ "safety_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
根據事實程度 (groundedness_input
)
輸入 (GroundednessInput
)
{ "groundedness_input": { "metric_spec": {}, "instance": { "prediction": string, "context": string } } }
參數 | 說明 |
---|---|
|
選用:GroundednessSpec 指定指標的行為。 |
|
選用:GroundednessInstance 評估輸入內容,包括推論輸入內容和相應的回應。 |
|
自由參加: LLM 回覆。 |
|
自由參加: LLM 回覆可使用的推論時間提供的脈絡。 |
輸出 (GroundednessResult
)
{ "groundedness_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
履行 (fulfillment_input
)
輸入 (FulfillmentInput
)
{ "fulfillment_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括推論輸入內容和相應的回應。 |
|
自由參加: LLM 回覆。 |
|
自由參加: 推論時提供的指令。 |
輸出 (FulfillmentResult
)
{ "fulfillment_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
摘要品質 (summarization_quality_input
)
輸入 (SummarizationQualityInput
)
{ "summarization_quality_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string, "context": string, } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括推論輸入內容和相應的回應。 |
|
自由參加: LLM 回覆。 |
|
自由參加: 推論時提供的指令。 |
|
自由參加: LLM 回覆可使用的推論時間提供的脈絡。 |
輸出 (SummarizationQualityResult
)
{ "summarization_quality_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
成對摘要品質 (pairwise_summarization_quality_input
)
輸入 (PairwiseSummarizationQualityInput
)
{ "pairwise_summarization_quality_input": { "metric_spec": {}, "instance": { "baseline_prediction": string, "prediction": string, "instruction": string, "context": string, } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括推論輸入內容和相應的回應。 |
|
自由參加: 基準模型的 LLM 回覆。 |
|
自由參加: 候選模型的 LLM 回覆。 |
|
自由參加: 推論時提供的指令。 |
|
自由參加: LLM 回覆可使用的推論時間提供的脈絡。 |
輸出 (PairwiseSummarizationQualityResult
)
{ "pairwise_summarization_quality_result": { "pairwise_choice": PairwiseChoice, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
摘要實用性 (summarization_helpfulness_input
)
輸入 (SummarizationHelpfulnessInput
)
{ "summarization_helpfulness_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string, "context": string, } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括推論輸入內容和相應的回應。 |
|
自由參加: LLM 回覆。 |
|
自由參加: 推論時提供的指令。 |
|
自由參加: LLM 回覆可使用的推論時間提供的脈絡。 |
輸出 (SummarizationHelpfulnessResult
)
{ "summarization_helpfulness_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
摘要詳細程度 (summarization_verbosity_input
)
輸入 (SummarizationVerbosityInput
)
{ "summarization_verbosity_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string, "context": string, } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括推論輸入內容和相應的回應。 |
|
自由參加: LLM 回覆。 |
|
自由參加: 推論時提供的指令。 |
|
自由參加: LLM 回覆可使用的推論時間提供的脈絡。 |
輸出 (SummarizationVerbosityResult
)
{ "summarization_verbosity_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
問題回答品質 (question_answering_quality_input
)
輸入 (QuestionAnsweringQualityInput
)
{ "question_answering_quality_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string, "context": string, } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括推論輸入內容和相應的回應。 |
|
自由參加: LLM 回覆。 |
|
自由參加: 推論時提供的指令。 |
|
自由參加: LLM 回覆可使用的推論時間提供的脈絡。 |
輸出 (QuestionAnsweringQualityResult
)
{ "question_answering_quality_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
逐對問題回答品質 (pairwise_question_answering_quality_input
)
輸入 (PairwiseQuestionAnsweringQualityInput
)
{ "question_answering_quality_input": { "metric_spec": {}, "instance": { "baseline_prediction": string, "prediction": string, "instruction": string, "context": string } } }
參數 | |
---|---|
|
自由參加: 指標規格,定義指標的行為。 |
|
自由參加: 評估輸入內容,包括推論輸入內容和相應的回覆。 |
|
自由參加: 基準模型的 LLM 回覆。 |
|
自由參加: 候選模型的 LLM 回覆。 |
|
自由參加: 推論時提供的指令。 |
|
自由參加: LLM 回覆可使用的推論時間提供的脈絡。 |
輸出 (PairwiseQuestionAnsweringQualityResult
)
{ "pairwise_question_answering_quality_result": { "pairwise_choice": PairwiseChoice, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
問題回答關聯性 (question_answering_relevance_input
)
輸入 (QuestionAnsweringRelevanceInput
)
{ "question_answering_quality_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string, "context": string } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括推論輸入內容和相應的回應。 |
|
自由參加: LLM 回覆。 |
|
自由參加: 推論時提供的指令。 |
|
自由參加: LLM 回覆可使用的推論時間提供的脈絡。 |
輸出 (QuestionAnsweringRelevanceResult
)
{ "question_answering_relevancy_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
問題回答實用性 (question_answering_helpfulness_input
)
輸入 (QuestionAnsweringHelpfulnessInput
)
{ "question_answering_helpfulness_input": { "metric_spec": {}, "instance": { "prediction": string, "instruction": string, "context": string } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括推論輸入內容和相應的回應。 |
|
自由參加: LLM 回覆。 |
|
自由參加: 推論時提供的指令。 |
|
自由參加: LLM 回覆可使用的推論時間提供的脈絡。 |
輸出 (QuestionAnsweringHelpfulnessResult
)
{ "question_answering_helpfulness_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
問題回答正確度 (question_answering_correctness_input
)
輸入 (QuestionAnsweringCorrectnessInput
)
{ "question_answering_correctness_input": { "metric_spec": { "use_reference": bool }, "instance": { "prediction": string, "reference": string, "instruction": string, "context": string } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 指定是否在評估中使用參照。 |
|
自由參加: 評估輸入內容,包括推論輸入內容和相應的回應。 |
|
自由參加: LLM 回覆。 |
|
自由參加: 基準真相或參考回覆。 |
|
自由參加: 推論時提供的指令。 |
|
自由參加: LLM 回覆可使用的推論時間提供的脈絡。 |
輸出 (QuestionAnsweringCorrectnessResult
)
{ "question_answering_correctness_result": { "score": float, "explanation": string, "confidence": float } }
輸出 | |
---|---|
|
|
|
|
|
|
自訂逐點 (pointwise_metric_input
)
輸入 (PointwiseMetricInput
)
{ "pointwise_metric_input": { "metric_spec": { "metric_prompt_template": string }, "instance": { "json_instance": string, } } }
參數 | |
---|---|
|
必要條件: 指定指標的行為。 |
|
必要條件: 定義指標的提示範本。系統會使用 |
|
必要條件: 評估輸入內容,由 |
|
自由參加: 鍵/值組合的 JSON 字串 (例如 |
輸出 (PointwiseMetricResult
)
{ "pointwise_metric_result": { "score": float, "explanation": string, } }
輸出 | |
---|---|
|
|
|
|
自訂成對 (pairwise_metric_input
)
輸入 (PairwiseMetricInput
)
{ "pairwise_metric_input": { "metric_spec": { "metric_prompt_template": string }, "instance": { "json_instance": string, } } }
參數 | |
---|---|
|
必要條件: 指定指標的行為。 |
|
必要條件: 定義指標的提示範本。系統會使用 |
|
必要條件: 評估輸入內容,由 |
|
自由參加: 鍵/值組合的 JSON 字串 (例如 |
輸出 (PairwiseMetricResult
)
{ "pairwise_metric_result": { "score": float, "explanation": string, } }
輸出 | |
---|---|
|
|
|
|
工具呼叫有效 (tool_call_valid_input
)
輸入 (ToolCallValidInput
)
{ "tool_call_valid_input": { "metric_spec": {}, "instance": { "prediction": string, "reference": string } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括 LLM 回覆和參考資料。 |
|
自由參加: 候選模型的回覆。這必須是包含 { "content": "", "tool_calls": [ { "name": "book_tickets", "arguments": { "movie": "Mission Impossible Dead Reckoning Part 1", "theater": "Regal Edwards 14", "location": "Mountain View CA", "showtime": "7:30", "date": "2024-03-30", "num_tix": "2" } } ] } |
|
自由參加: 實際資料或參考回應,格式與 |
輸出 (ToolCallValidResults
)
{ "tool_call_valid_results": { "tool_call_valid_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
|
|
|
工具名稱相符 (tool_name_match_input
)
輸入 (ToolNameMatchInput
)
{ "tool_name_match_input": { "metric_spec": {}, "instance": { "prediction": string, "reference": string } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括 LLM 回覆和參考資料。 |
|
自由參加: 候選模型的回覆。這必須是包含 |
|
自由參加: 實際資料或參考回應,格式與 |
輸出 (ToolNameMatchResults
)
{ "tool_name_match_results": { "tool_name_match_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
|
|
|
工具參數鍵相符 (tool_parameter_key_match_input
)
輸入 (ToolParameterKeyMatchInput
)
{ "tool_parameter_key_match_input": { "metric_spec": {}, "instance": { "prediction": string, "reference": string } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括 LLM 回覆和參考資料。 |
|
自由參加: 候選模型的回覆。這必須是包含 |
|
自由參加: 實際資料或參考回應,格式與 |
輸出 (ToolParameterKeyMatchResults
)
{ "tool_parameter_key_match_results": { "tool_parameter_key_match_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
|
|
|
工具參數 KV 比對 (tool_parameter_kv_match_input
)
輸入 (ToolParameterKVMatchInput
)
{ "tool_parameter_kv_match_input": { "metric_spec": {}, "instance": { "prediction": string, "reference": string } } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加: 評估輸入內容,包括 LLM 回覆和參考資料。 |
|
自由參加: 候選模型的回覆。這必須是包含 |
|
自由參加: 實際資料或參考回應,格式與 |
輸出 (ToolParameterKVMatchResults
)
{ "tool_parameter_kv_match_results": { "tool_parameter_kv_match_metric_values": [ { "score": float } ] } }
輸出 | |
---|---|
|
|
|
|
COMET (comet_input
)
輸入 (CometInput
)
{ "comet_input" : { "metric_spec" : { "version": string }, "instance": { "prediction": string, "source": string, "reference": string, }, } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
自由參加:
|
|
自由參加: BCP-47 格式的來源語言。 例如「es」。 |
|
自由參加: BCP-47 格式的目標語言。 例如「es」。 |
|
自由參加: 評估輸入內容。評估時使用的確切欄位取決於 COMET 版本。 |
|
自由參加: 候選模型的回覆,也就是要評估的翻譯文字。 |
|
自由參加: 翻譯前的原文。 |
|
自由參加: 實際資料或參考譯文,語言與 |
輸出 (CometResult
)
{ "comet_result" : { "score": float } }
輸出 | |
---|---|
|
|
指標 X (metricx_input
)
輸入 (MetricxInput
)
{ "metricx_input" : { "metric_spec" : { "version": string }, "instance": { "prediction": string, "source": string, "reference": string, }, } }
參數 | |
---|---|
|
自由參加: 指定指標的行為。 |
|
選填:
可以是下列其中一項:
|
|
自由參加: BCP-47 格式的來源語言。 例如「es」。 |
|
自由參加: BCP-47 格式的目標語言。 例如「es」。 |
|
自由參加: 評估輸入內容。用於評估的確切欄位取決於 MetricX 版本。 |
|
自由參加: 候選模型的回覆,也就是要評估的翻譯文字。 |
|
自由參加: 預測結果的原文語言。 |
|
自由參加: 用於與預測結果比較的基準真相。與預測結果的語言相同。 |
輸出 (MetricxResult
)
{ "metricx_result" : { "score": float } }
輸出 | |
---|---|
|
|
範例
在一次呼叫中評估多項指標
以下範例說明如何呼叫 Gen AI 評估服務 API,使用各種評估指標 (包括 summarization_quality
、groundedness
、fulfillment
、summarization_helpfulness
和 summarization_verbosity
) 評估 LLM 的輸出內容。
Python
Go
評估逐對摘要品質
以下範例說明如何呼叫 Gen AI 評估服務 API,使用成對摘要品質比較功能評估 LLM 的輸出內容。
REST
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:。
- LOCATION:處理要求的區域。
- PREDICTION:LLM 回覆。
- BASELINE_PREDICTION:基準模型 LLM 回覆。
- INSTRUCTION:推論時使用的指令。
- CONTEXT:推論時間文字,內含所有相關資訊,可用於 LLM 回覆。
HTTP 方法和網址:
POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID-/locations/LOCATION:evaluateInstances \
JSON 要求主體:
{ "pairwise_summarization_quality_input": { "metric_spec": {}, "instance": { "prediction": "PREDICTION", "baseline_prediction": "BASELINE_PREDICTION", "instruction": "INSTRUCTION", "context": "CONTEXT", } } }
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID-/locations/LOCATION:evaluateInstances \"
PowerShell
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$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://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID-/locations/LOCATION:evaluateInstances \" | Select-Object -Expand Content
Python
Python
如要瞭解如何安裝或更新 Python 適用的 Vertex AI SDK,請參閱「安裝 Python 適用的 Vertex AI SDK」。 詳情請參閱 Python API 參考說明文件。
Go
Go
在試用這個範例之前,請先按照Go使用用戶端程式庫的 Vertex AI 快速入門中的操作說明進行設定。 詳情請參閱 Vertex AI Go API 參考說明文件。
如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
評估 ROUGE 分數
以下範例說明如何呼叫 Gen AI 評估服務 API,取得預測的 ROUGE 分數。要求會使用 metric_spec
設定指標的行為。
REST
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:。
- LOCATION:處理要求的區域。
- PREDICTION:LLM 回覆。
- REFERENCE:做為參考的黃金 LLM 回覆。
- ROUGE_TYPE:用來計算 ROUGE 分數的計算方式。如要查看可接受的值,請參閱
metric_spec.rouge_type
。 - USE_STEMMER:決定是否使用 Porter 詞幹提取器去除字尾,以提升比對效果。如要瞭解可接受的值,請參閱
metric_spec.use_stemmer
。 - SPLIT_SUMMARIES:判斷是否要在
rougeLsum
句子之間新增換行符。如要瞭解可接受的值,請參閱metric_spec.split_summaries
。
HTTP 方法和網址:
POST https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID-/locations/REGION:evaluateInstances \
JSON 要求主體:
{ "rouge_input": { "instances": { "prediction": "PREDICTION", "reference": "REFERENCE.", }, "metric_spec": { "rouge_type": "ROUGE_TYPE", "use_stemmer": USE_STEMMER, "split_summaries": SPLIT_SUMMARIES, } } }
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID-/locations/REGION:evaluateInstances \"
PowerShell
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$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://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID-/locations/REGION:evaluateInstances \" | Select-Object -Expand Content
Python
Python
如要瞭解如何安裝或更新 Python 適用的 Vertex AI SDK,請參閱「安裝 Python 適用的 Vertex AI SDK」。 詳情請參閱 Python API 參考說明文件。
Go
Go
在試用這個範例之前,請先按照Go使用用戶端程式庫的 Vertex AI 快速入門中的操作說明進行設定。 詳情請參閱 Vertex AI Go API 參考說明文件。
如要向 Vertex AI 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
後續步驟
- 瞭解如何執行評估作業。