build and test a challenge solver with machine learning in a lab · lesson 3 of 7 · sources checked 2026-11-30
data: generation, labels, splits, and drift
This lesson builds a labeled set from your generator, splits it by scheme version, and shows the effect of a scheme change.
status of this lesson: from a public sourcepurpose
A solver that trains on one version of a task works only as long as that version stays. Know how the data of a lab model is made, labeled, and split. Then you can see what a change of version costs each side.
objectives
- Build a labeled set from your own generator, with a seed and a scheme-version tag on each record.
- Split a data set by scheme version, and keep one version out of training.
- Explain data drift, and why a scheme change costs the defender less than the solver.
- Name the sources that a lab data set can come from.
new terms
- data drift
- A change of the input data after a scheme change, which lowers the accuracy of a trained model.
how it works
A lab model learns from records. Each record holds the task, its answer, and the data that shows where the record came from. In my model, a record of this module has four fields:
| field | what it holds | why it is necessary |
|---|---|---|
| ID | A unique name of the record | You can find the record again |
| Seed | The start value of the random function of the generator | The same seed gives the same record again |
| scheme version | The version of the task set and its rules | You can split and report by version |
| Answer | The correct answer to the task | It is the label |
A scheme version is one version of the task set, the distortion, and the rules of a challenge, with an ID. For example, version 1 of a text task can use eight letters and four places. Version 2 can use sixteen letters and five places.
the sources of a lab data set
A lab data set comes from one of two sources:
- A generator that you host. It makes the task and knows the answer, for example a text task of five letters.
- A public research data set, with its licence and its paper.
No record comes from a live commercial service. A collection from such a service sends traffic to it, and it can break its terms. The commercial tasks are also not open data. Thus the lab has no route to them, and the lab guard of The solver pipeline in the lab refuses each such host.
an open-source generator
An open-source generator is one option for your own lab. For example, the lepture/captcha project is a Python library that generates audio and image CAPTCHAs. Its licence is BSD-3-Clause. Its image class takes a list of font files, and its generate method takes the answer text as a string GitHub, source 1.
Thus the code that calls the generator gives the answer. The label of each image is known before the image exists. A CAPTCHA of such a generator has the scheme of its fonts and settings. A change of the fonts is a new scheme version in my model.
the cost of a label
A label from your own generator costs nothing, because the generator chooses the answer. A label of a public research data set comes with the set. A label that a person must write costs the time of that person for each record.
example A set of 5,000 generated records has 5,000 free labels. The cost of the data is then the compute time to make it and to train on it.
the split by scheme version
A random split puts records of each version in the training set and in the test set. Then the test shows how well the model does on versions that it already saw. It does not show what happens after a change of version.
A split by scheme version keeps one version out of training. For example, the model trains on version 1 and version 2, and the test set holds only version 3. The test then measures the model on a version that it never saw.
data drift
data drift is a change of the input data after a scheme change, which lowers the accuracy of a trained model. The model learned the letters, the fonts, and the distortion of the old version. A new version changes them, and the model must have new data and new training.
For example, a model that trains on version 1 and version 2 can fail on version 3, which it never saw. Then it must have new data of version 3 and new training.
For the defender, a scheme change is a cheap step. It changes a setting of the generator. For a solver that trains one model for each type, the same change starts a new cycle of data, labels, and training.
A planned change to a new version is a scheme rotation. A rotation starts on a trigger that the defender sets. More detail is in Maintenance: rotation, solve-rate monitor, and the price of abuse (not yet published).
what the lab chart shows
The section "Data" shows the correct answers of a model against the number of training samples. For each version, more samples give more correct answers. The three versions differ much in difficulty. A low value of a hard version is not proof of a strong scheme: the step budget of the training also limits it.
the two sides
| automation side | detection side |
|---|---|
| A model for one type must have new labels and new training after each scheme change. Generated data is cheap, but it does not match a changed scheme. | A scheme change is cheap for the defender and costly for a solver of one type. Change the scheme on a trigger, and tag each result with its scheme version. |
design decisions
| option | gain | cost | when it is correct |
|---|---|---|---|
| Data from your own generator | Free labels, and each record has a known seed | It shows only the schemes that you made | For each lab model |
| A public research data set | A shared set that other papers also use | Its licence and its version are fixed | For a comparison with a paper |
| A random split | Simple to make | It hides the effect of a scheme change | Only inside one scheme version |
| A split by scheme version | It measures the model on a version that it never saw | It must have records of more than one version | For each claim about a scheme change |
| A tag of the scheme version on each record | Each result can be reported by version | One more field in each record | Always |
diagram
the data flow of a lab solver, with a split by scheme version and a held-out version
code example
The example uses a synthetic generator. It makes the answer text only, not an image, so that the run uses no font and no install. A seeded random function makes each run give the same set.
Build a labeled set from a generator of your own with a seed and a scheme-version tag, and split it by scheme version.
// Build a labeled set from a generator of your own, and split it by scheme version.
// The generator is synthetic: it makes the answer text only, not an image.
type Rec = { id: string; scheme: string; seed: number; answer: string };
function rng(seed: number): () => number {
// mulberry32: a small seeded random function, so that each run gives the same set
return () => {
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
// Each scheme version has its own letter set and answer length.
const SCHEMES: Record<string, { letters: string; length: number }> = {
v1: { letters: "ABCDEFGH", length: 4 },
v2: { letters: "ABCDEFGHJKMNPQRS", length: 5 },
v3: { letters: "ABCDEFGHJKMNPQRSTUVWXYZ2345", length: 6 },
};
function generate(scheme: string, seed: number, count: number): Rec[] {
const r = rng(seed), s = SCHEMES[scheme], out: Rec[] = [];
for (let i = 0; i < count; i++) {
let answer = "";
for (let k = 0; k < s.length; k++) answer += s.letters[Math.floor(r() * s.letters.length)];
// The generator knows the answer, so the label costs nothing.
out.push({ id: `${scheme}-${seed}-${i}`, scheme, seed, answer });
}
return out;
}
// Arguments: the seed, and the scheme version to keep out of training.
const seed = Number(process.argv[2] ?? "777");
const heldOut = process.argv[3] ?? "v3";
const all = Object.keys(SCHEMES).flatMap((v) => generate(v, seed, 4));
// Split by scheme version, not at random: the held-out version is only in the test set.
const train = all.filter((x) => x.scheme !== heldOut);
const test = all.filter((x) => x.scheme === heldOut);
console.log(`seed ${seed}, held-out scheme ${heldOut}`);
console.log(`train: ${train.length} records, schemes ${[...new Set(train.map((x) => x.scheme))].join(",")}`);
console.log(`test: ${test.length} records, schemes ${[...new Set(test.map((x) => x.scheme))].join(",")}`);
for (const x of [train[0], test[0]]) console.log(JSON.stringify(x));
const overlap = train.some((x) => x.scheme === heldOut);
console.log(`held-out scheme in the training set: ${overlap ? "yes (fault)" : "no"}`);output
The seed, the held-out version, the size and the versions of each set, one record of each set, and the overlap check.
seed 777, held-out scheme v3
train: 8 records, schemes v1,v2
test: 4 records, schemes v3
{"id":"v1-777-0","scheme":"v1","seed":777,"answer":"FABA"}
{"id":"v3-777-0","scheme":"v3","seed":777,"answer":"VAFDUM"}
held-out scheme in the training set: noThe run has two arguments: the seed 777 and the held-out version v3. The output shows that the training set holds only versions 1 and 2, and the test set holds only version 3. Each record carries its seed and its version, so the same seed gives the same set again.
data
correct answers of my lab model against the number of training samples
status of this figure: measured by me
source: Lab result of this course: my small lab model on my own generator; date 2026-11-13; sample of 2,000; condition: Own generator, one small model, 2,000 training steps, one host. Median of 5 model seeds, 2,000 test challenges for each model. Teaching values; they do not transfer.
data table
| series | training samples | correct of 2,000 |
|---|---|---|
| scheme version 1 | 500 samples | 734 |
| scheme version 1 | 1,000 samples | 1528 |
| scheme version 1 | 2,000 samples | 1795 |
| scheme version 1 | 4,000 samples | 1874 |
| scheme version 1 | 8,000 samples | 1909 |
| scheme version 1 | 16,000 samples | 1925 |
| scheme version 2 | 500 samples | 19 |
| scheme version 2 | 1,000 samples | 241 |
| scheme version 2 | 2,000 samples | 659 |
| scheme version 2 | 4,000 samples | 982 |
| scheme version 2 | 8,000 samples | 1123 |
| scheme version 2 | 16,000 samples | 1199 |
| scheme version 3 | 500 samples | 0 |
| scheme version 3 | 1,000 samples | 1 |
| scheme version 3 | 2,000 samples | 11 |
| scheme version 3 | 4,000 samples | 33 |
| scheme version 3 | 8,000 samples | 52 |
| scheme version 3 | 16,000 samples | 59 |
The chart is a lab result of this course, with a small model on my own simple generator. The values are for teaching, and they do not transfer to a different challenge.
failure modes
| problem | cause | correction |
|---|---|---|
| A model looks good in the test and fails after a scheme change. | The split was random, so each version was in training and in the test. | Split by scheme version, and keep one version out of training. |
| Nobody can say which version a result is for. | The records have no scheme-version tag. | Tag each record and each result with its scheme version. |
| A data set cannot be made again. | The generator ran with no fixed seed. | Store the seed with each record. |
| A team wants training data from a live commercial challenge. | The commercial tasks look like the best data. | Use your own generator or a public research data set. A collection from a live service contacts the service and can break its terms. |
| A low value of a hard version reads as a strong scheme. | The training budget of the model also limits the value. | Report the training budget with the result. |
check questions
Why does each record of a lab data set carry its seed?
- The seed is the answer to the task.
- The same seed gives the same record again, so the set can be made again.
- The seed gives the model the scheme version.
- The seed makes the label cost nothing.
answer
b. The same seed gives the same record again, so the set can be made again.
The seed is the start value of the random function of the generator. With the same seed, the generator makes the same record again.
A model trains on version 1 and version 2. Which test set gives a held-out test of a scheme version?
- A random part of the records of version 1 and version 2
- The records of version 1 only
- The training set again
- The records of version 3 only
answer
d. The records of version 3 only
A held-out test uses a version that was not in training. Versions 1 and 2 were in training, so only version 3 is held out.
Explain data drift, and why a scheme change costs the defender less than a solver of one type.
sample answer
Data drift is a change of the input data after a scheme change, which lowers the accuracy of a trained model. For the defender, the change is a new setting of the generator. For a solver of one type, it starts a new cycle of data, labels, and training.
Name the two sources that a lab data set of the module can come from, and the source that it never comes from.
sample answer
A lab data set comes from a generator that you host, or from a public research data set. It never comes from a live commercial service, because a collection sends traffic to that service and can break its terms.
exercise
exercise Do this task on paper. Use the synthetic results of two lab models on a generator of your own. Each test set has 1,000 challenges. No row comes from a real challenge.
| model | trained on | test version | correct answers |
|---|---|---|---|
| A | version 1, random split | version 1 | 900 |
| A | version 1, random split | version 2 | 40 |
| B | version 1 and version 2 | version 2 | 850 |
- Calculate the accuracy of each row as a percent.
- Write which row shows data drift.
- Write which test is a held-out test of a scheme version.
- Write what a defender learns about a change from version 1 to version 2.
sample answer
The answer uses the three synthetic rows of the task.
The accuracies are 900 / 1,000 = 90%, 40 / 1,000 = 4%, and 850 / 1,000 = 85%. The second row shows data drift: model A trained only on version 1, and it fails on version 2.
The second row is the held-out test, because version 2 was not in the training of model A. Row 3 is not held out, because model B trained on version 2. A defender learns that a change to version 2 cuts model A from 90% to 4%. The solver must make new data and train again to get back to a high value.
sources
- lepture/captcha, GitHub, source code, read 2026-11-22
- My model of the record fields, the split by scheme version, and the cost of a scheme change, 2026-11 (not public).