skip to content

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 source

purpose

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

  1. Build a labeled set from your own generator, with a seed and a scheme-version tag on each record.
  2. Split a data set by scheme version, and keep one version out of training.
  3. Explain data drift, and why a scheme change costs the defender less than the solver.
  4. 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:

fieldwhat it holdswhy it is necessary
IDA unique name of the recordYou can find the record again
SeedThe start value of the random function of the generatorThe same seed gives the same record again
scheme versionThe version of the task set and its rulesYou can split and report by version
AnswerThe correct answer to the taskIt 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 sidedetection 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

optiongaincostwhen it is correct
Data from your own generatorFree labels, and each record has a known seedIt shows only the schemes that you madeFor each lab model
A public research data setA shared set that other papers also useIts licence and its version are fixedFor a comparison with a paper
A random splitSimple to makeIt hides the effect of a scheme changeOnly inside one scheme version
A split by scheme versionIt measures the model on a version that it never sawIt must have records of more than one versionFor each claim about a scheme change
A tag of the scheme version on each recordEach result can be reported by versionOne more field in each recordAlways

diagram

the data flow of a lab solver, with a split by scheme version and a held-out version

The held-out version goes only to the evaluation, so the test measures the model on a version that it never saw.source: My model of the data flow of a lab solver

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-set.tstypescript

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: no

The 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

correct answers of my lab model against the number of training samples7341528179518741909192519241659982112311990111335259500 samples1,000 samples2,000 samples4,000 samples8,000 samples16,000 samplescorrect of 2,0001. scheme version 12. scheme version 23. scheme version 3

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
correct answers of my lab model against the number of training samples
seriestraining samplescorrect of 2,000
scheme version 1500 samples734
scheme version 11,000 samples1528
scheme version 12,000 samples1795
scheme version 14,000 samples1874
scheme version 18,000 samples1909
scheme version 116,000 samples1925
scheme version 2500 samples19
scheme version 21,000 samples241
scheme version 22,000 samples659
scheme version 24,000 samples982
scheme version 28,000 samples1123
scheme version 216,000 samples1199
scheme version 3500 samples0
scheme version 31,000 samples1
scheme version 32,000 samples11
scheme version 34,000 samples33
scheme version 38,000 samples52
scheme version 316,000 samples59
Full answers that are correct in 2,000 test challenges of the same scheme version. Each value is the median of 5 models. The step budget limits the values.

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

problemcausecorrection
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

  1. Why does each record of a lab data set carry its seed?

    1. The seed is the answer to the task.
    2. The same seed gives the same record again, so the set can be made again.
    3. The seed gives the model the scheme version.
    4. 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.

  2. A model trains on version 1 and version 2. Which test set gives a held-out test of a scheme version?

    1. A random part of the records of version 1 and version 2
    2. The records of version 1 only
    3. The training set again
    4. 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.

  3. 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.

  4. 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.

modeltrained ontest versioncorrect answers
Aversion 1, random splitversion 1900
Aversion 1, random splitversion 240
Bversion 1 and version 2version 2850
  1. Calculate the accuracy of each row as a percent.
  2. Write which row shows data drift.
  3. Write which test is a held-out test of a scheme version.
  4. 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

  1. lepture/captcha, GitHub, source code, read 2026-11-22
  2. My model of the record fields, the split by scheme version, and the cost of a scheme change, 2026-11 (not public).