快速评估服务使用户能够跨多个指标逐点和成对评估其 LLM 模型。用户提供推理时间输入、LLM 回答和其他参数,而该服务会返回特定于评估任务的指标。指标包括基于模型的指标(例如 SummarizationQuality)和内存中计算的指标(例如 Rouge、Bleu 和工具/函数调用指标)。由于该服务直接从模型获取预测结果作为输入,因此可能会评估 Vertex 支持的所有模型。
局限性
- 基于模型的指标会消耗 text-bison 配额。快速评估服务利用 text-bison 作为底层仲裁者模型来计算基于模型的指标。
- 此服务存在传播延迟。首次调用服务后,它可能在几分钟内都不可用。
语法
- PROJECT_ID =
PROJECT_ID
- REGION =
REGION
- MODEL_ID =
MODEL_ID
curl
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://${REGION}-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${REGION}:evaluateInstances
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://${REGION}-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${REGION}:evaluateInstances' result = google_auth_requests.AuthorizedSession(creds).post(uri, json=data) print(json.dumps(result.json(), indent=2))
参数列表
可用指标的完整列表。
参数 | |
---|---|
|
可选: 用于评估预测结果是否与引用完全匹配的输入。 |
|
可选: 用于通过将预测与参考进行比较来计算 BLEU 得分的输入。 |
|
可选: 输入,用于通过将预测结果与引用进行比较来计算 |
|
可选: 用于评估单个回答的语言掌握情况的输入。 |
|
可选: 用于评估单个回答能否提供连贯、易于理解的回答。 |
|
可选: 用于评估单个回答的安全等级的输入。 |
|
可选: 用于评估单个回答能否提供或参考仅输入文本中包含的信息能力的输入。 |
|
可选: 用于评估单个回答是否能够完全执行指令的输入。 |
|
可选: 用于评估单个回答的整体文本能力的输入。 |
|
可选: 用于比较两个回答的整体汇总质量的输入。 |
|
可选: 用于评估单个回答能否提供摘要的输入,其中包含替换原始文本所需的详细信息。 |
|
可选: 用于评估单个回答能否提供简洁的摘要的输入。 |
|
可选: 用于评估单个回答的整体回答问题的能力的输入,同时提供可供参考的文本内容。 |
|
可选: 用于比较两个回答的整体回答问题的能力的输入,同时提供要参考的文本正文。 |
|
可选: 用于评估单个回答在被询问时回答相关信息的能力。 |
|
可选: 用于评估单个回答在回答问题时提供关键细节的能力的输入。 |
|
可选: 用于评估单个回答正确回答问题的能力的输入。 |
|
可选: 用于评估单个回答预测有效工具调用的能力的输入。 |
|
可选: 用于评估单个回答使用正确工具名称预测工具调用的能力的输入。 |
|
可选: 用于评估单个回答使用正确的参数名称预测工具调用的能力的输入。 |
|
可选: 用于评估单个回答能否使用正确的参数名称和值预测工具调用的能力的输入 |
ExactMatchInput
{ "exact_match_input: { "metric_spec": {}, "instances": [ { "prediction": string, "reference": string } ] } }
参数 | |
---|---|
|
可选: 指标规范,定义指标的行为。 |
|
可选: 评估输入,由 LLM 回答和参考组成。 |
|
可选: LLM 回答。 |
|
可选: 黄金 LLM 回答以供参考。 |
ExactMatchResults
{ "exact_match_results: { "exact_match_metric_values": [ { "score": float } ] } }
输出 | |
---|---|
|
每个实例输入的评估结果。 |
|
以下项之一:
|
BleuInput
{ "bleu_input: { "metric_spec": {}, "instances": [ { "prediction": string, "reference": string } ] } }
参数 | |
---|---|
|
可选: 指标规范,定义指标的行为。 |
|
可选: 评估输入,由 LLM 回答和参考组成。 |
|
可选: LLM 回答。 |
|
可选: 黄金 LLM 回答以供参考。 |
BleuResults
{ "bleu_results: { "bleu_metric_values": [ { "score": float } ] } }
输出 | |
---|---|
|
每个实例输入的评估结果。 |
|
|
RougeInput
{ "rouge_input: { "metric_spec": { "rouge_type": string, "use_stemmer": bool, "split_summaries": bool }, "instances": [ { "prediction": string, "reference": string } ] } }
参数 | |
---|---|
|
可选: 指标规范,定义指标的行为。 |
|
可选: 可接受的值:
|
|
可选: 是否应使用 Porter 词干来删除字词后缀,以改善匹配。 |
|
可选: 是否在 rougeLsum 的句子之间添加换行符。 |
|
可选: 评估输入,由 LLM 回答和参考组成。 |
|
可选: LLM 回答。 |
|
可选: 黄金 LLM 回答以供参考。 |
RougeResults
{ "rouge_results: { "rouge_metric_values": [ { "score": float } ] } }
输出 | |
---|---|
|
每个实例输入的评估结果。 |
|
|
FluencyInput
{ "fluency_input: { "metric_spec": {}, "instance": { "prediction": string } } }
参数 | |
---|---|
|
可选: 指标规范,定义指标的行为。 |
|
可选: 评估输入,由 LLM 回答组成。 |
|
可选: LLM 回答。 |
FluencyResult
{ "fluency_result: { "score": float, "explanation": string, "confidence": float } }
输出 | |
---|---|
|
|
|
|
|
|
CoherenceInput
{ "coherence_input: { "metric_spec": {}, "instance": { "prediction": string } } }
参数 | |
---|---|
|
可选: 指标规范,定义指标的行为。 |
|
可选: 评估输入,由 LLM 回答组成。 |
|
可选: LLM 回答。 |
CoherenceResult
{ "coherence_result: { "score": float, "explanation": string, "confidence": float } }
输出 | |
---|---|
|
|
|
|
|
|
SafetyInput
{ "safety_input: { "metric_spec": {}, "instance": { "prediction": string } } }
参数 | |
---|---|
|
可选: 指标规范,定义指标的行为。 |
|
可选: 评估输入,由 LLM 回答组成。 |
|
可选: LLM 回答。 |
SafetyResult
{ "safety_result: { "score": float, "explanation": string, "confidence": float } }
输出 | |
---|---|
|
|
|
|
|
|
GroundednessInput
{ "groundedness_input: { "metric_spec": {}, "instance": { "prediction": string, "context": string } } }
参数 |
说明 |
|
可选:GroundednessSpec 指标规范,定义指标的行为。 |
|
可选:GroundednessInstance 评估输入,由推理输入和相应的回答组成。 |
|
可选: LLM 回答。 |
|
可选: 包含所有信息的推理时间文本,可在 LLM 回答中使用。 |
GroundednessResult
{ "groundedness_result: { "score": float, "explanation": string, "confidence": float } }
输出 | |
---|---|
|
|
|
|
|
|
FulfillmentInput
{ "fulfillment_input: { "metric_spec": {}, "instance": { "prediction": string, "instruction": string } } }
参数 | |
---|---|
|
可选: 指标规范,定义指标的行为。 |
|
可选: 评估输入,由推理输入和相应的回答组成。 |
|
可选: LLM 回答。 |
|
可选: 推理时使用的指令。 |
FulfillmentResult
{ "fulfillment_result: { "score": float, "explanation": string, "confidence": float } }
输出 | |
---|---|
|
|
|
|
|
|
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 } }
输出 | |
---|---|
|
|
|
|
|
|
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 } }
输出 | |
---|---|
|
|
|
|
|
|
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 } }
输出 | |
---|---|
|
|
|
|
|
|
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 } }
输出 | |
---|---|
|
|
|
|
|
|
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 } }
输出 | |
---|---|
|
|
|
|
|
|
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 } }
输出 | |
---|---|
|
|
|
|
|
|
QuestionAnsweringRelevanceInput
{ "question_answering_quality_input: { "metric_spec": {}, "instance": { "prediction": string, "instruction": string, "context": string } } }
参数 | |
---|---|
|
可选: 指标规范,定义指标的行为。 |
|
可选: 评估输入,由推理输入和相应的回答组成。 |
|
可选: LLM 回答。 |
|
可选: 推理时使用的指令。 |
|
可选: 包含所有信息的推理时间文本,可在 LLM 回答中使用。 |
QuestionAnsweringRelevancyResult
{ "question_answering_relevancy_result: { "score": float, "explanation": string, "confidence": float } }
输出 | |
---|---|
|
|
|
|
|
|
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 } }
输出 | |
---|---|
|
|
|
|
|
|
QuestionAnsweringCorrectnessInput
{ "question_answering_correctness_input: { "metric_spec": { "use_reference": bool }, "instance": { "prediction": string, "reference": string, "instruction": string, "context": string } } }
参数 | |
---|---|
|
可选: |
|
可选: 评估中是否使用引用。 |
|
可选: 评估输入,由推理输入和相应的回答组成。 |
|
可选: LLM 回答。 |
|
可选: 黄金 LLM 回答以供参考。 |
|
可选: 推理时使用的指令。 |
|
可选: 包含所有信息的推理时间文本,可在 LLM 回答中使用。 |
QuestionAnsweringCorrectnessResult
{ "question_answering_correctness_result: { "score": float, "explanation": string, "confidence": float } }
输出 | |
---|---|
|
|
|
|
|
|
ToolCallValidInput
{ "tool_call_valid_input: { "metric_spec": {}, "instance": { "prediction": string, "reference": string } } }
参数 | |
---|---|
|
可选: 指标规范,定义指标的行为。 |
|
可选: 评估输入,由 LLM 回答和参考组成。 |
|
可选: 候选模型 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 } ] } }
输出 | |
---|---|
|
重复 |
|
|
ToolNameMatchInput
{ "tool_name_match_input: { "metric_spec": {}, "instance": { "prediction": string, "reference": string } } }
参数 | |
---|---|
|
可选: 指标规范,定义指标的行为。 |
|
可选: 评估输入,由 LLM 回答和参考组成。 |
|
可选: 候选模型 LLM 回答,这是一个包含 |
|
可选: 与预测格式相同的黄金模型输出。 |
ToolNameMatchResults
{ "tool_name_match_results: { "tool_name_match_metric_values": [ { "score": float } ] } }
输出 | |
---|---|
|
重复 |
|
|
ToolParameterKeyMatchInput
{ "tool_parameter_key_match_input: { "metric_spec": {}, "instance": { "prediction": string, "reference": string } } }
参数 | |
---|---|
|
可选: 指标规范,定义指标的行为。 |
|
可选: 评估输入,由 LLM 回答和参考组成。 |
|
可选: 候选模型 LLM 回答,这是一个包含 |
|
可选: 与预测格式相同的黄金模型输出。 |
ToolParameterKeyMatchResults
{ "tool_parameter_key_match_results: { "tool_parameter_key_match_metric_values": [ { "score": float } ] } }
输出 | |
---|---|
|
重复 |
|
|
ToolParameterKVMatchInput
{ "tool_parameter_kv_match_input: { "metric_spec": {}, "instance": { "prediction": string, "reference": string } } }
参数 | |
---|---|
|
可选: 指标规范,定义指标的行为。 |
|
可选: 评估输入,由 LLM 回答和参考组成。 |
|
可选: 候选模型 LLM 回答,这是一个包含 |
|
可选: 与预测格式相同的黄金模型输出。 |
ToolParameterKVMatchResults
{ "tool_parameter_kv_match_results: { "tool_parameter_kv_match_metric_values": [ { "score": float } ] } }
输出 | |
---|---|
|
重复 |
|
|
示例
- PROJECT_ID =
PROJECT_ID
- REGION =
REGION
成对摘要质量
这里我们将演示如何调用 Rapid Eval API 来评估 LLM 的输出。在这种情况下,我们会进行两两汇总质量比较。
curl
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://${REGION}-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${REGION}:evaluateInstances \ -d '{ "pairwise_summarization_quality_input": { "metric_spec": {}, "instance": { "prediction": "France is a country located in Western Europe.", "baseline_prediction": "France is a country.", "instruction": "Summarize the context.", "context": "France is a country located in Western Europe. It'\''s bordered by Belgium, Luxembourg, Germany, Switzerland, Italy, Monaco, Spain, and Andorra. France'\''s coastline stretches along the English Channel, the North Sea, the Atlantic Ocean, and the Mediterranean Sea. Known for its rich history, iconic landmarks like the Eiffel Tower, and delicious cuisine, France is a major cultural and economic power in Europe and throughout the world.", } } }'
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 = { "pairwise_summarization_quality_input": { "metric_spec": {}, "instance": { "prediction": "France is a country located in Western Europe.", "baseline_prediction": "France is a country.", "instruction": "Summarize the context.", "context": ( "France is a country located in Western Europe. It's bordered by " "Belgium, Luxembourg, Germany, Switzerland, Italy, Monaco, Spain, " "and Andorra. France's coastline stretches along the English " "Channel, the North Sea, the Atlantic Ocean, and the Mediterranean " "Sea. Known for its rich history, iconic landmarks like the Eiffel " "Tower, and delicious cuisine, France is a major cultural and " "economic power in Europe and throughout the world." ), } } } uri = f'https://${REGION}-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${REGION}:evaluateInstances' result = google_auth_requests.AuthorizedSession(creds).post(uri, json=data) print(json.dumps(result.json(), indent=2))
规则
接下来,我们将调用 API 来获取基于引用的预测的 ROUGE 分数。
curl
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://${REGION}-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${REGION}:evaluateInstances \ -d '{ "rouge_input": { "instances": { "prediction": "A fast brown fox leaps over a lazy dog.", "reference": "The quick brown fox jumps over the lazy dog.", }, "instances": { "prediction": "A quick brown fox jumps over the lazy canine.", "reference": "The quick brown fox jumps over the lazy dog.", }, "instances": { "prediction": "The speedy brown fox jumps over the lazy dog.", "reference": "The quick brown fox jumps over the lazy dog.", }, "metric_spec": { "rouge_type": "rougeLsum", "use_stemmer": true, "split_summaries": true } } }'
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 = { "rouge_input": { "metric_spec": { "rouge_type": "rougeLsum", "use_stemmer": True, "split_summaries": True }, "instances": [ { "prediction": "A fast brown fox leaps over a lazy dog.", "reference": "The quick brown fox jumps over the lazy dog.", }, { "prediction": "A quick brown fox jumps over the lazy canine.", "reference": "The quick brown fox jumps over the lazy dog.", }, { "prediction": "The speedy brown fox jumps over the lazy dog.", "reference": "The quick brown fox jumps over the lazy dog.", } ] } } uri = f'https://${REGION}-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${REGION}:evaluateInstances' result = google_auth_requests.AuthorizedSession(creds).post(uri, json=data) print(json.dumps(result.json(), indent=2))