Basic

Formatting the examples

The model learns the exact string shape you give it. Message roles, field order, and punctuation are all part of what it copies, so a mismatch between how you format the training set and how you format the live request is a bug that shows up as garbage output.

What you will see

The role shaped request. Using this same function for training and serving is the fix for the mismatch bug.

About 1 min of reading

Try It

Share one template.

1

The builder

def build(inp): return [{'role': 'system', 'content': 'You convert logs.'}, {'role': 'user', 'content': inp}] print(build('ERR 4021'))

Before you run it, say out loud what it will print. Then open the answer.

What it prints
The role shaped request. Using this same function for training and serving is the fix for the mismatch bug.

Data Flow

A template shapes both sides.
1 Write the request builder
↓
2 Use it for every training example
↓
3 Use it for every live request
↓
4 Parse every expected output
Line by line

Read the first example one line at a time. A line that prints shows what appears on screen; the rest set things up quietly.

def build(inp): return [{'role': 'system', 'content': 'You convert logs.'}, {'role': 'user', 'content': inp}] sets nothing on screen
print(build('ERR 4021')) The role shaped request. Using this same function for training and serving is the fix for the mismatch bug.
Why this works
One template, both places

Write the function that builds a request once and use it for training and for serving. Two copies of a template is where the drift lives, and drift is the failure.

Validate the outputs

Parse every expected output before training. A set with unparseable outputs trains on noise, and the run looks successful while the model learns nothing usable.

Examples

Same shape as serving

If serving sends a system message plus one user message, the training examples must have that same shape. Train on a bare string and serve with roles, and the model sees a distribution it never learned.

Exact output strings

If you want JSON, the expected output is valid JSON with the exact keys. A set where half the outputs have an extra key teaches a model that sometimes emits that key.

Check before training

Print three examples in the exact bytes that will be sent. That check is cheap and it catches the mismatch that a training run then wastes hours to reveal.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← The training set
Previous Lesson
The training set
Next Lesson
Epochs and steps
Epochs and steps →