Battam's picture
Release [run release-20261111T153845Z]
82d0b24 verified
|
Raw History Blame
11.5 kB
# Training Data Foundation: a worked example
English | [简体中文](README.zh.md)
From the [public index of the Training Data Foundation](https://huggingface.co/datasets/Battam/training-data-foundation) to two training tasks that a grader accepts: the reference solution scores 1, and an agent that does nothing scores 0.
The index gives the materials;
what a task checks is decided when the task is built from them, which is the user's step, and this example shows one way.
Run the commands below in order from an empty folder on a machine with Docker.
| Task | Material set | License of the material | What the agent has to do | oracle | nop |
|---|---|---|---|---|---|
| `spreadsheet-recalc` | `uk-government-workbooks` | OGL-UK-3.0 | Work out five formula cells whose stored results were removed | 1.0 | 0.0 |
| `exfat-repair` | `exfatprogs-fsck-cases` | GPL-2.0-only | Repair a corrupted exFAT image until `fsck.exfat` finds nothing to fix | 1.0 | 0.0 |
The tasks follow the Harbor task format and the task conventions of Terminal-Bench 4.0 ([CONTRIBUTING.md of v4.0.0](https://github.com/harbor-framework/terminal-bench/blob/v4.0.0/CONTRIBUTING.md)): a filled `[metadata]` in `task.toml`, a `README.md` in every task folder, and a cheat solution that the verifier must score 0.
Three differences are on purpose:
- No network.
Terminal-Bench 4.0 is open internet;
here the network would hand over the expected values of the spreadsheet task, because its original workbook, with the stored results, is public.
- No canary strings.
Canary strings mark benchmark data that must stay out of training corpora;
these tasks are meant for training.
- No cheat inside a task.
Terminal-Bench 4.0 keeps a task's cheat in its `cheat/` folder;
here the cheats are written out in step 5 of this README, outside every task folder and every data unit of the index, so they never reach an agent or training data.
## What you need
Docker, [uv](https://docs.astral.sh/uv/), the [DuckDB](https://duckdb.org/) CLI and a copy of this folder.
Take the folder from the dataset, at the release this example is pinned to, and run everything from inside it:
```sh
TAG=release-2026-11-11.14
uvx --from huggingface_hub hf download Battam/training-data-foundation --repo-type dataset --revision $TAG --include 'examples/harbor_tasks/*' --local-dir .
cd examples/harbor_tasks
HF=https://huggingface.co/datasets/Battam/training-data-foundation
alias harbor='uv run --no-project --python 3.12 --with harbor==0.25.0 --with litellm==1.93.0 harbor'
alias py='uv run --quiet --no-project --python 3.12 --with openpyxl==3.1.5 python'
```
`TAG` is the release of the index this example is pinned to (every release gets a tag `release-<YYYY-MM-DD>.<n>`).
Every step reads that one release: the folder, the catalog, the fetch tool and the materials, so a release published later changes none of them.
Each release of the index writes its own tag into its copy of this folder: into the two lines `TAG=` (above and in step 5) and into both tasks' `index_revision`;
so the folder you take at `TAG` names that same release.
## 1. Pick the material
The catalog is a data file, so one SQL query is enough.
This example takes one material set from the collection for spreadsheets (`A`) and one from the collection for disk images (`B`);
the query shows the rows of the two:
```sh
duckdb -c "SELECT source, collection, license.tier AS license, units, files
FROM 'hf://datasets/Battam/training-data-foundation@$TAG/meta/catalog.parquet'
WHERE kind = 'material_set' AND source IN ('uk-government-workbooks', 'exfatprogs-fsck-cases')
ORDER BY collection"
```
It prints two rows: `uk-government-workbooks` in `A` and `exfatprogs-fsck-cases` in `B`.
The `units` column says how many units each material set holds.
To look through every material set of the two collections, put `collection IN ('A', 'B')` in place of the condition on `source` and run `duckdb -markdown`, which prints every row of the result, not only its first and last 20.
## 2. Fetch the files
The workbook's `unit_id` is its path, `workbooks/ukgov-uk-community-renewal-fund-index-model.xlsx`.
The exFAT case's `unit_id` is the one the fetch tool records for it:
a fetch of the source writes one line per file into `_meta/fetch_manifest.jsonl`, with its address and its `unit_id`.
```sh
uv run $HF/resolve/$TAG/tools/fetch.py --revision $TAG --source exfatprogs-fsck-cases --out ./listing
EXFAT=$(duckdb -noheader -list -c "SELECT DISTINCT json_extract_string(json, '\$.unit_id')
FROM read_json_objects('listing/_meta/fetch_manifest.jsonl')
WHERE json_extract_string(json, '\$.uri') LIKE '%/file_invalid_clus/%'")
echo $EXFAT
```
Fetch the two units:
```sh
uv run $HF/resolve/$TAG/tools/fetch.py \
--revision $TAG \
--source uk-government-workbooks \
--unit workbooks/ukgov-uk-community-renewal-fund-index-model.xlsx \
--source exfatprogs-fsck-cases \
--unit "$EXFAT" \
--out ./data
```
Before its first download the command prints one line per source with the units it takes, their files and their size, then the total.
`--unit` names each unit by its `unit_id`, so the command takes these two units and nothing else;
each task records its unit in `source_units` of its `task.toml`, by the same source and `unit_id`.
Each unit comes whole, with the files of its source (its README.md and LICENSE), and each file is checked against the size and hash in the index.
The index holds no answer files, so the units bring none;
step 3 takes the workbook and the image by their file names, and the spreadsheet task's expected values come from the original workbook.
Each unit lands in a folder of its own, `data/<domain>/<source>/<unit folder>/`, with its files at their paths in the unit;
`data/_meta/manifest.jsonl` gives the `unit_id` of every file (defined once, in `docs/sources.md` of the dataset).
## 3. Build the tasks
A task is an instruction, an environment, a reference solution, tests and a README.
Those files are in [`tasks/`](tasks);
the steps below add the material.
**Spreadsheet.**
The task checks the values of five formula cells, and the published workbook stores those same values next to the formulas.
So the tests take them from the original file (`tools/show_cells.py` writes them to `tests/answer.json`);
an agent given the original file could read them straight out of it, so the agent gets a copy saved by openpyxl, which keeps the formulas and drops the stored results:
```sh
WB=$(find data/D3_data/uk-government-workbooks -type f -name ukgov-uk-community-renewal-fund-index-model.xlsx)
py tools/show_cells.py $WB tasks/spreadsheet-recalc/tests/answer.json
py tools/strip_results.py $WB tasks/spreadsheet-recalc/environment/$(basename $WB)
py tools/show_cells.py tasks/spreadsheet-recalc/environment/$(basename $WB)
```
The reference solution opens the workbook with headless LibreOffice, saves a copy and reads the five cells from it.
The stored results are gone, so LibreOffice calculates those cells when it opens the file.
**exFAT.**
Here the task checks no stored value: its tests follow the upstream test script of exfatprogs, at a fixed commit.
The [tests](tasks/exfat-repair/tests/test.sh) follow two of its assertions: the original image is reported as corrupted, and `fsck.exfat` exits with 0 on the repaired image.
Two checks are ours: the repaired image keeps its size, and the three files and the directory whose names start with `l0_` are still there; `fsck.exfat` reports no error for them.
A freshly formatted image passes checks 1 to 3 and fails check 4.
```sh
IMG=$(find data/D2_sysadmin/exfatprogs-fsck-cases -type f -name exfat.img)
cp $IMG tasks/exfat-repair/environment/exfat.img
cp $IMG tasks/exfat-repair/tests/exfat.img
```
**In both tasks** (see [`task.toml`](tasks/spreadsheet-recalc/task.toml)):
- The tests run in a separate container (`environment_mode = "separate"`), so what they check never enters the agent's environment.
- Only the files listed under `artifacts` pass from the agent's container to the verifier's.
- Both containers have no network (`network_mode = "no-network"`).
The materials are public, so an agent with network access could download the original files again.
## 4. Check the tasks
```sh
harbor lint --extend-select root-agent --extend-select unpinned-image \
tasks/spreadsheet-recalc tasks/exfat-repair
```
The two extra rules require that the agent does not run as root and that images are pinned by digest.
It reports no findings.
## 5. Run them
`oracle` runs the reference solution.
`nop` does nothing.
```sh
harbor run -p tasks -a oracle -n 2
harbor run -p tasks -a nop -n 2
```
`oracle` has a mean of 1.000 and `nop` a mean of 0.000.
A task that passes both is the minimum for training: the solution is accepted, and doing nothing is not.
Each trial's record is under `jobs/`.
A cheat takes a shortcut that the verifier must refuse.
The two cheats are here, in this README, and nowhere else: they are not part of the tasks, and no data unit of the index holds them.
To run them, copy the tasks to `cheats/`, write each cheat over the copy's `solution/solve.sh`, and give the copies to Harbor's oracle agent:
```sh
cp -r tasks cheats
cat > cheats/spreadsheet-recalc/solution/solve.sh <<'EOF'
#!/bin/bash
# Cheat: download the original workbook and copy its stored results; the verifier must score it 0 (offline the download fails).
set -euo pipefail
TAG=release-2026-11-11.14
HF=https://huggingface.co/datasets/Battam/training-data-foundation
D="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
mkdir -p /app/output /tmp/cheat
python3 -m pip install --user --quiet uv==0.9.7
python3 -m uv run --python python3 $HF/resolve/$TAG/tools/fetch.py \
--revision $TAG \
--source uk-government-workbooks \
--unit workbooks/ukgov-uk-community-renewal-fund-index-model.xlsx \
--out /tmp/cheat/data
WB=$(find /tmp/cheat/data/D3_data/uk-government-workbooks -type f -name ukgov-uk-community-renewal-fund-index-model.xlsx)
python3 "$D/read_cells.py" "$WB" /app/output/values.json
cat /app/output/values.json
EOF
cat > cheats/exfat-repair/solution/solve.sh <<'EOF'
#!/bin/bash
# Cheat: write a freshly formatted exFAT image of the same size; the verifier must score it 0 (it fails check 4).
set -euo pipefail
mkdir -p /app/output
cp /app/data/exfat.img /app/output/repaired.img
mkfs.exfat /app/output/repaired.img
EOF
harbor run \
-p cheats \
-a oracle \
-n 2
```
Both cheats must score 0, a mean of 0.000.
The spreadsheet cheat fetches the original workbook with the index's fetch tool at `TAG` and copies the results it stores for the five cells, with the reference solution's `read_cells.py`, which the copy keeps;
without network the download fails.
The exFAT cheat writes a freshly formatted image of the same size, which passes checks 1 to 3 and fails check 4: the `l0_` files and directory are not on it.
To build tasks from other material, change the material set in step 2 and write the instruction and tests that fit it.
The steps stay the same.
## Licenses
The code and task files in this folder are under [CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/).
The materials are not part of this folder: they are fetched from upstream and keep their own licenses, OGL-UK-3.0 for the workbook and GPL-2.0-only for the disk image.
Checks 1 and 3 in `tasks/exfat-repair/tests/test.sh` follow `tests/test_fsck.sh` of [exfatprogs](https://github.com/exfatprogs/exfatprogs) at commit 8b42748.