Lesson 4 of 5 Preparing Data for Generative AI

Preparing Data for Supervised and Reinforcement Fine-Tuning

This lesson explains the data shapes that Bedrock supervised fine-tuning and reinforcement fine-tuning need, and why the quality of a few thousand good examples matters more than the quantity of poor ones.

Learning outcomes

After completing this lesson, you will be able to:

  • Format supervised fine-tuning data.
  • Prepare prompts and reward functions for reinforcement fine-tuning.
  • Apply a dataset quality checklist.

Supervised fine-tuning data

Supervised fine-tuning learns from labelled examples of the desired output. Bedrock accepts JSONL training and optional validation files in S3. Depending on the model, records use a prompt and completion pair or a conversational format with a system prompt and a list of user and assistant messages (multimodal models also accept image references). Examples should look exactly like production requests, including the same system prompt and instructions, and responses should be the ideal answer in the exact format required.

{"prompt": "Classify the ticket: 'Invoice shows the wrong VAT rate.'", "completion": "billing"}
{"prompt": "Classify the ticket: 'App crashes when I upload a photo.'", "completion": "technical"}
True or false

Supervised fine-tuning data

Exam skills 1.2.9

Check the rules for supervised fine-tuning datasets.

Log in to try this activity Interactive activities are free with an account.

Reinforcement fine-tuning data

Reinforcement fine-tuning does not need ideal responses. It uses prompts plus a reward function that scores the model's attempts: a rule-based grader for verifiable answers (for example, does generated SQL return the right rows, does code pass unit tests) or an AI-based judge for subjective qualities, typically implemented as a Lambda function. Prompts can come from an uploaded dataset or from Bedrock invocation logs. This suits tasks where correct answers are easy to check but hard to write in advance.

The following diagram shows how a team uses all 2,000 of its questions to fine-tune a text-to-SQL model when only 300 have correct SQL answers.

Using all 2,000 questions to fine-tune the SQL model. Supervised fine-tuning on the 300 questions with correct SQL teaches the schema and style. Reinforcement fine-tuning then uses all 2,000 questions with a Lambda reward function that runs each generated query on a test database and scores the result. A held-out set of 200 questions compares base, SFT and SFT plus RFT.
The scenario is illustrative.
Scenario questions

Supervised or reinforcement?

Exam skills 1.2.9 · 2.1.2

Choose between supervised and reinforcement fine-tuning based on the data available.

Log in to try this activity Interactive activities are free with an account.

Dataset quality checklist

The quality of a fine-tuning dataset determines the quality of the fine-tuned model. The examples should be representative of real requests, balanced across task types, free of duplicates, contradictions and personal data, and within the model's token limits. They are split into training and validation sets, for example 90% and 10%, so training progress can be monitored.

A separate test set is held out to compare the customised model with the base model and with prompt engineering alone. Fine-tuning is worthwhile only if it clearly beats the simpler alternatives on that test set. The following table summarises the data each customisation method needs.

MethodData neededFormat
Supervised fine-tuningInput and ideal output pairsJSONL prompt/completion or conversation messages
Reinforcement fine-tuningPrompts plus a reward functionJSONL prompts or invocation logs; Lambda grader
DistillationRepresentative prompts (optionally pairs)JSONL prompts or invocation logs
Continued pre-trainingLarge unlabeled domain textPlain text corpus (on SageMaker AI)
Select all that apply

Ready to fine-tune?

Exam skills 1.2.9 · 1.3.6

Identify the checks a fine-tuning dataset should pass before the job starts.

Log in to try this activity Interactive activities are free with an account.
Worked example

SQL generation

A company wants a model that writes SQL for its data warehouse schema. It has 2,000 business questions but correct SQL for only 300 of them; executing a query against a test database shows whether the result matches the expected answer.

  • Supervised fine-tuning on the 300 labelled pairs teaches the schema and SQL style.
  • Reinforcement fine-tuning on all 2,000 questions uses a Lambda reward function that runs the generated SQL on a test database and scores correctness.
  • A held-out set of 200 questions compares base model, SFT model and SFT plus RFT.

Reinforcement fine-tuning uses the 1,700 questions without written answers, because correctness can be verified automatically. Writing 1,700 SQL answers by hand for supervised fine-tuning would have been slow and expensive.

Check yourself

Why should fine-tuning prompts look exactly like production prompts?

Show answer

The model learns to respond to the format it is trained on, so a different format in production lowers quality.

Exam Tips

Remember for the exam

  • Bedrock fine-tuning data: JSONL in S3, with training and validation files.
  • Make training prompts look exactly like production prompts.
  • Answers verifiable but hard to write: reinforcement fine-tuning with a reward function.
  • Hold out a test set to compare against the base model.
  • Quality and consistency of examples matter more than volume.