Prepare an evaluation dataset - Amazon SageMaker AI
Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.

Prepare an evaluation dataset

The evaluation dataset holds the prompts that a job sends to the candidate model, and optionally the reference answers that Evaluators compare with. You bring data in a format that you already have. An evaluation job reads the same formats that SageMaker AI training jobs read, so you can split one dataset into training and evaluation sets without converting it.

Prepare data with SageMaker AI Data Preparation

If you don't have an evaluation dataset, or your data isn't ready, you can prepare it with Preparing Data with SageMaker AI Data Preparation. The jobs register the data that you produce as a dataset in your account, so that you can use the dataset ARN in your Evaluation Criteria. You can use the following data preparation capabilities to create or improve an evaluation dataset:

For more information about setting up and getting started with data preparation, see Get started with SageMaker AI Data Preparation.

Choose a dataset format

A dataset is a JSON Lines file, with one sample on each line. SageMaker AI detects the format from the fields of each row, so you don't declare it. Use one format throughout a file. The following table lists the supported formats, how SageMaker AI detects each one, and where it reads the prompt and the reference answer.

Format Detected by Prompt Reference answer
OpenAI chat messages (a list), and no reference_answer object The messages, without a trailing assistant message The trailing assistant message, if there is one. SageMaker AI removes it from the prompt, so the model doesn't see it.
Nova RLVR messages and a reference_answer object The messages The reference_answer object
Hugging Face prompt-completion prompt and completion prompt, as a string or a list of messages completion, as a string or the last assistant message of a list
Hugging Face preference prompt, chosen, and rejected prompt, as a string or a list of messages chosen. The job doesn't use rejected.
verl prompt only prompt, as a string or a list of messages extra_info.answer, or reward_model.ground_truth if that is missing
SageMaker Evaluation query system (optional) and query response

For the full list of fields and more examples of each format, see Supported Dataset Formats for Bring-Your-Own-Dataset (BYOD) Tasks.

Examples

Each of the following lines is one sample, shown in a different format.

{"messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the capital of France?"}, {"role": "assistant", "content": "Paris"}]} {"system": "Answer in one word.", "query": "What is the capital of France?", "response": "Paris"} {"prompt": "What is the capital of France?", "completion": "Paris"} {"prompt": "What is the capital of France?", "chosen": "Paris", "rejected": "Lyon"} {"prompt": [{"role": "user", "content": "What is the capital of France?"}], "extra_info": {"answer": "Paris"}}

In practice, a file uses only one of these formats.

Reference answers

A reference answer is optional. SageMaker AI reads it from the field that your format uses, as shown in the preceding table, and converts it to text. A string is used as is. An object without a text field becomes its JSON text. If a row has a top-level reference_answer field, SageMaker AI uses that value instead, whatever the format.

Whether you need a reference answer depends on your Evaluators:

  • A judge prompt that contains {{ground_truth}} uses the reference answer. If a row has none, the placeholder is empty, so write the prompt so that it still makes sense in that case.

  • The built-in Builtin.Correctness and Builtin.Completeness judges use the reference answer when a row has one, and use a prompt written for no reference when it doesn't. The other built-in judges don't use it.

  • A built-in code Evaluator, such as one that checks a math answer, compares the response with the reference answer, so each row needs one.

  • A RewardFunction Evaluator receives the reference answer in its input. Whether it needs one is up to your code.

For more information about Evaluators, see Create Evaluators.

Extra fields

Fields in a row that the format doesn't use, such as a category or a split, stay with the sample. The job writes the original record with each result, so you can group results by any field of your data. A RewardFunction Evaluator also receives these fields. For more information, see Create an AWS Lambda function Evaluator.

Upload the dataset and create a dataset ARN

To use a dataset, upload the file to Amazon S3, and then create a dataset in SageMaker AI. The dataset has an Amazon Resource Name (ARN) that you use in your Evaluation Criteria. Use a bucket in the same AWS Region as the job.

Run the following command to upload the file to Amazon S3:

aws s3 cp support-eval.jsonl s3://amzn-s3-demo-bucket/datasets/support-eval.jsonl

To create the dataset with the SageMaker AI Python SDK, run the following code. It prints the dataset ARN:

from sagemaker.ai_registry.dataset import DataSet dataset = DataSet.create( name="support-eval", source="s3://amzn-s3-demo-bucket/datasets/support-eval.jsonl", wait=True ) print(dataset.arn)

To create the dataset with the AWS CLI instead, run the following command. Set DatasetFileFormat to the format of your file: SageMaker_Eval, OpenAI_Messages, HF_Prompt_Completion, HF_Preference, Verl, or Nova_RLVR.

aws sagemaker import-hub-content \ --hub-name my-hub \ --hub-content-name support-eval \ --hub-content-type DataSet \ --document-schema-version 5.0.0 \ --hub-content-document '{ "DatasetFileFormat": "SageMaker_Eval", "DatasetS3Bucket": "amzn-s3-demo-bucket", "DatasetS3Prefix": "datasets/support-eval.jsonl" }'

The dataset ARN has the following form:

arn:aws:sagemaker:us-west-2:111122223333:hub-content/my-hub/DataSet/support-eval/1.0.0

Replace the file name, bucket name, dataset name, hub name, Region, and account ID with your own values.

Define the dataset in the Evaluation Criteria

You define the dataset in the Evaluation Criteria, not in the job. In the Evaluation Criteria document, set CustomBenchmark.Dataset to the dataset ARN in DatasetArn, or to the Amazon S3 URI of the file in S3Uri. A job that runs the Evaluation Criteria reads this dataset.

{ "DisplayName": "Support answer quality", "CustomBenchmark": { "Dataset": { "DatasetArn": "arn:aws:sagemaker:us-west-2:111122223333:hub-content/my-hub/DataSet/support-eval/1.0.0" }, "Scorers": [ { "BuiltInEvaluator": "Builtin.Correctness" } ] } }

The example shows only the part of the Evaluation Criteria document that names the dataset. For the complete document, see Define Evaluation Criteria.

Datasets for public benchmarks

A public benchmark has its own scoring, but currently you provide its dataset. Download the benchmark dataset yourself, for example from Hugging Face, and then do the following:

  1. Convert the dataset to one of the formats in Choose a dataset format, if it isn't in one already.

  2. Upload the file to Amazon S3, and create a dataset to get a dataset ARN, as described in Upload the dataset and create a dataset ARN.

  3. Provide the dataset ARN as the dataset of the evaluation.

Next steps

  • For instructions on creating the Evaluators that score your responses, see Create Evaluators.