本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
创建基于人工的模型评测作业
以下示例展示了如何创建使用人工的模型评测作业。
控制台:
创建使用人工的模型评估作业
-
打开 Amazon Bedrock 控制台。
-
在导航窗格中,在推理和评测下选择评测。
-
在模型评测窗格中,在人工下,选择创建,然后选择人工:引入自己的工作团队。
-
在指定作业详细信息页面上,提供以下信息:
-
评估名称 — 为模型评估作业指定一个可描述该作业的名称。此名称将显示在模型评估作业列表中。此名称在您的 AWS 区域的账户中必须是唯一的。
-
描述(可选)— 提供可选描述。
-
选择下一步。
-
在设置评估页面上的推理来源下,选择模型评测的来源。您既可以评测 Amazon Bedrock 模型的性能,又可以通过在提示数据集内提供自己的推理响应数据来评测其他模型的性能。最多可以选择两个推理来源。对于具有两个来源的作业,您无需为两个来源选择相同的类型;您可以选择一个 Amazon Bedrock 模型,然后为第二个来源提供自己的推理响应数据。要评测 Amazon Bedrock 模型,请执行以下操作:
-
在选择来源下,选择 Bedrock 模型。
-
选择选择模型以选择要评测的模型。
-
要选择第二个模型,请选择添加模型并重复前面的步骤。
-
要自带推理回复数据,请执行以下操作:
-
在选择来源下,选择自带推理回复。
-
对于来源名称,输入用于创建响应数据的模型的名称。您输入的名称必须与提示数据集内的 modelIdentifier 参数相匹配。
-
要添加第二个来源,请选择添加模型并重复前面的步骤。
-
对于任务类型,选择您希望模型在模型评测作业期间执行的任务类型。模型的所有说明都必须包含在提示中。任务类型不能控制模型的响应。
-
在数据集窗格中,提供以下信息。
-
在选择提示数据集下,指定提示数据集文件的 S3 URI,或者选择浏览 S3 以查看可用的 S3 存储桶。自定义提示数据集中最多可以有 1000 个提示。
-
在评估结果目标下,指定您希望将模型评测作业结果保存到的目录的 S3 URI,或者选择浏览 S3 以查看可用的 S3 存储桶。
-
(可选)在 KMS 密钥 - 可选下,提供要用于加密模型评测作业的客户自主管理型密钥的 ARN。
-
在 Amazon Bedrock IAM 角色 – 权限窗格中,执行以下操作。要了解有关模型评测所需权限的更多信息,请参阅 模型评估作业的服务角色要求。
-
要使用现有 Amazon Bedrock 服务角色,请选择使用现有角色。否则,请使用创建新角色来指定新 IAM 服务角色的详细信息。
-
在服务角色名称中,指定 IAM 服务角色的名称。
-
准备就绪后,选择创建角色以创建新的 IAM 服务角色。
-
选择下一步。
-
在工作团队下,使用选择团队下拉列表来选择现有团队,或通过执行以下操作来创建新团队:
-
在团队名称下,输入您团队的名称。
-
在电子邮件地址下,输入您团队中人工工作人员的电子邮件地址。
-
在每个提示的工作人员人数下,选择评测每个提示的工作人员人数。您所选人数的工作人员审核完每个提示的响应之后,该提示及其响应将从工作团队负责的工作中删除。最终结果报告将包含每位工作人员的所有评级。
众所周知,大型语言模型偶尔会出错,生成令人反感或不适的内容。在此评估期间,工作人员可能会看到令人反感或不适的材料。在他们开始评估工作之前,请务必采取适当的措施,为其提供培训并发送通知。他们可以拒绝和放弃任务,也可以在使用人工评估工具进行评估期间稍事休息。
-
在人工工作流 IAM 角色 - 权限下,选择现有角色或选择创建新角色。
-
选择下一步。
-
在评估说明下,提供完成任务的说明。可以预览工作团队用来评估响应的评估 UI,包括指标、评级方法和您提供的说明。预览结果取决于您为该作业创建的配置。
-
选择下一步。
-
检查配置,然后选择创建以创建作业。
作业成功启动后,状态将变为进行中。作业完成后,状态将变为已完成。当模型评测作业仍在进行中时,您可以选择在工作团队评测所有模型的响应之前停止该作业。为此,请在模型评测登录页面上选择停止评测。这会将模型评测作业的状态更改为正在停止。成功停止模型评测作业后,您可以删除该模型评测作业。
API 和 AWS CLI
如果在 Amazon Bedrock 控制台之外创建基于人工的模型评测作业,您需要创建一个 Amazon SageMaker AI 流定义 ARN。
流定义 ARN 是指定义模型评测作业工作流的地方。流定义用于定义工作人员界面和您要为任务分配的工作团队,并连接到 Amazon Bedrock。
对于使用 Amazon Bedrock API 操作开始的模型评测作业,您必须使用 AWS CLI 或支持的 AWS SDK 创建一个流定义 ARN。要详细了解流定义的工作原理以及如何以编程方式创建流定义,请参阅《SageMaker AI 开发人员指南》中的创建人工审核工作流(API)。
在 CreateFlowDefinition 中,您必须指定 AWS/Bedrock/Evaluation 作为 AwsManagedHumanLoopRequestSource 的输入。Amazon Bedrock 服务角色还必须拥有访问流定义输出存储桶的权限。
以下是一个使用 AWS CLI 的示例请求。在请求中,HumanTaskUiArn 是 SageMaker AI 自有 ARN。在 ARN 中,您只能修改 AWS 区域。
aws sagemaker create-flow-definition --cli-input-json '
{
"FlowDefinitionName": "human-evaluation-task01",
"HumanLoopRequestSource": {
"AwsManagedHumanLoopRequestSource": "AWS/Bedrock/Evaluation"
},
"HumanLoopConfig": {
"WorkteamArn": "arn:aws:sagemaker:AWS 区域:111122223333:workteam/private-crowd/my-workteam",
## The Task UI ARN is provided by the service team, you can only modify the AWS 区域.
"HumanTaskUiArn":"arn:aws:sagemaker:AWS 区域:394669845002:human-task-ui/Evaluation"
"TaskTitle": "Human review tasks",
"TaskDescription": "Provide a real good answer",
"TaskCount": 1,
"TaskAvailabilityLifetimeInSeconds": 864000,
"TaskTimeLimitInSeconds": 3600,
"TaskKeywords": [
"foo"
]
},
"OutputConfig": {
"S3OutputPath": "s3://amzn-s3-demo-destination-bucket"
},
"RoleArn": "arn:aws:iam::111122223333:role/SageMakerCustomerRoleArn"
}'
创建流定义 ARN 后,使用以下示例通过 AWS CLI 或支持的 AWS SDK 创建基于人工的模型评测作业。
- AWS CLI
-
以下示例命令和 JSON 文件展示了如何创建使用人工工作人员的模型评测作业,您将在该作业中提供自己的推理响应数据。要了解如何为使用人工工作人员的模型评测作业指定提示数据集,请参阅为使用人工工作人员的模型评测作业创建自定义提示数据集。
例 AWS CLI 命令和 JSON 文件,用于创建采用您自己的推理响应数据的评测作业
aws bedrock create-evaluation-job --cli-input-json file://my_eval_job.json
{
"jobName": "model-eval-llama-vs-my-other-model",
"roleArn": "arn:aws:iam::111122223333:role/service-role/Amazon-Bedrock-IAM-Role-20250218T223671",
"evaluationConfig": {
"human": {
"customMetrics": [
{
"description": "Measures the organization and structure of a generated text.",
"name": "Coherence",
"ratingMethod": "ThumbsUpDown"
},
{
"description": "Indicates the accuracy of a generated text.",
"name": "Accuracy",
"ratingMethod": "ComparisonChoice"
}
],
"datasetMetricConfigs": [
{
"dataset": {
"datasetLocation": {
"s3Uri": "s3://amzn-s3-demo-bucket/input/model-eval/fitness-dataset-model-eval-byoir-2-models.jsonl"
},
"name": "dataset1"
},
"metricNames": [
"Coherence",
"Accuracy"
],
"taskType": "Generation"
}
],
"humanWorkflowConfig": {
"flowDefinitionArn": "arn:aws:sagemaker:us-east-1:111122223333:flow-definition/bedrock-fitness-human-byoir",
"instructions": "<h3>The following are the metrics and their descriptions for this evaluation</h3>\n<p><strong>Coherence</strong>: Measures the organization and structure of a generated text. - <em>Thumbs up/down</em>\n<strong>Accuracy</strong>: Indicates the accuracy of a generated text. - <em>Choice buttons</em></p>\n<h3>Instructions for how to use the evaluation tool</h3>\n<p>The evaluation creator should use this space to write detailed descriptions for every rating method so your evaluators know how to properly rate the responses with the buttons on their screen.</p>\n<h4>For example:</h4>\n<p>If using <strong>Likert scale - individual</strong>, define the 1 and 5 of the 5 point Likert scale for each metric so your evaluators know if 1 or 5 means favorable/acceptable/preferable.\nIf using <strong>Likert scale - comparison</strong>, describe what the evaluator is looking for to determine their preference between two responses.\nIf using <strong>Choice buttons</strong>, describe what is preferred according to your metric and its description.\nIf using <strong>Ordinal ranking</strong>, define what should receive a #1 ranking according to your metric and its description.\nIf using <strong>Thumbs up/down</strong>, define what makes an acceptable response according to your metric and its description.</p>\n<h3>Describing your ground truth responses if applicable to your dataset</h3>\n<p>Describe the purpose of your ground truth responses that will be shown on screen next to each model response. Note that the ground truth responses you provide are not rated/scored by the evaluators - they are meant to be a reference standard for comparison against the model responses.</p>"
}
}
},
"inferenceConfig": {
"models": [
{
"precomputedInferenceSource": {
"inferenceSourceIdentifier": "llama-3-1-80b"
}
},
{
"precomputedInferenceSource": {
"inferenceSourceIdentifier": "my_other_model"
}
}
]
},
"outputDataConfig": {
"s3Uri": "s3://amzn-s3-demo-bucket/output/"
}
}
- SDK for Python
-
以下代码示例展示了如何通过适用于 Python 的 SDK 创建使用人工的模型评测作业。
import boto3
client = boto3.client('bedrock')
job_request = client.create_evaluation_job(
jobName="111122223333-job-01",
jobDescription="two different task types",
roleArn="arn:aws:iam::111122223333:role/example-human-eval-api-role",
inferenceConfig={
## You must specify and array of models
"models": [
{
"bedrockModel": {
"modelIdentifier":"arn:aws:bedrock:us-west-2::foundation-model/amazon.titan-text-lite-v1",
"inferenceParams":"{\"inferenceConfig\":{\"maxTokens\": 512,\"temperature\":0.7,\"topP\":0.9}}"
}
},
{
"bedrockModel": {
"modelIdentifier": "anthropic.claude-v2",
"inferenceParams": "{\"inferenceConfig\":{\"maxTokens\":512,\"temperature\":1,\"topP\":0.999,\"stopSequences\":[\"stop\"]},\"additionalModelRequestFields\":{\"top_k\": 128}}"
}
}
]
},
outputDataConfig={
"s3Uri":"s3://job-bucket/outputs/"
},
evaluationConfig={
"human": {
"humanWorkflowConfig": {
"flowDefinitionArn": "arn:aws:sagemaker:us-west-2:111122223333:flow-definition/example-workflow-arn",
"instructions": "some human eval instruction"
},
"customMetrics": [
{
"name": "IndividualLikertScale",
"description": "testing",
"ratingMethod": "IndividualLikertScale"
}
],
"datasetMetricConfigs": [
{
"taskType": "Summarization",
"dataset": {
"name": "Custom_Dataset1",
"datasetLocation": {
"s3Uri": "s3://job-bucket/custom-datasets/custom-trex.jsonl"
}
},
"metricNames": [
"IndividualLikertScale"
]
}
]
}
}
)
print(job_request)