Datasets:
|
Download docs/selecting.md from Battam/training-data-foundation: direct link, hf CLI and curl.
- Browser
- Download file 46 kB
-
https://huggingface.co/datasets/Battam/training-data-foundation/resolve/refs%2Fpr%2F36/docs/selecting.md
- Command line
-
hf download hf://datasets/Battam/training-data-foundation@refs/pr/36/docs/selecting.md
-
curl -L -o selecting.md https://huggingface.co/datasets/Battam/training-data-foundation/resolve/refs%2Fpr%2F36/docs/selecting.md
46 kB
| # Selecting rows | |
| English | [简体中文](selecting.zh.md) | |
| Every table in this repository is Parquet. One row of a data file under `data/` is one downloadable item: a file, an archive member, a WARC record, a byte range or an API response. Its columns `source` and `batch` say which source and batch it belongs to; a file's path does not, and one file may hold rows of several sources. `meta/catalog.parquet` names the files of each source in its column `data_files` and those of each batch in its column `batch_files`. The tables under `meta/` are small and say which rows are worth using. | |
| A snapshot holds one row per key (source, uri, range_offset and member_path): a corrected row replaces the old one, and the file that held the old one is written again whole without it. The earlier states of each file stay in the dataset repository's history and its release tags. | |
| ## Row fields | |
| | Field | Meaning | | |
| |---|---| | |
| | `source` | Source name (see meta/sources.json). | | |
| | `batch` | Batch inside the source (one snapshot or collection run). | | |
| | `collection` | Collection name inside the source. | | |
| | `ext` | File extension without the dot, as found at the source. | | |
| | `uri` | Address to download from (HTTPS where the source offers it). | | |
| | `range_offset, range_length` | Byte range inside the file at uri, for records stored inside a larger file. | | |
| | `member_path, parent_pointer_id` | Path of a member inside an archive, and the archive's pointer. | | |
| | `zip_local_header_offset, zip_compression_method, zip_compressed_size` | Where a zip member's bytes sit, so it can be read with range requests. | | |
| | `size_bytes` | Size of the item in bytes (empty when the source does not say). | | |
| | `media_type` | Media type when the source states one. | | |
| | `sha256, sha1, md5, crc32` | Hashes as raw bytes; use lower(hex(sha256)) for the hex form. | | |
| | `origin_url, origin_time` | The page the item was found on (with signature and credential parameters removed) and when it was captured. | | |
| | `truncated` | Why stored content was cut short (empty when it was not). | | |
| | `license_spdx, license_training_ok, license_redistribution_ok, license_notes` | The row's own license when it differs from the batch license. | | |
| | `sensitive` | health or minors when the row's data is about health or about minors (empty otherwise); filter on it to leave such rows out. | | |
| | `collected_at` | When the row was collected (UTC, YYYY-MM-DDTHH:MM:SSZ): the time the collector recorded when it wrote the row's shard (for a selection source, when the collector emitted the row's file), kept when the row's file is written again; of the rows under one key the one collected last is the one a snapshot holds. Empty when no time was recorded (rows written before the column was added, or collected before the collector recorded one); such a row ranks by the start of its batch's date in UTC, and below every row with a time when its batch name has no date. | | |
| | `extra` | Anything else the full pointer carries, as JSON; fetch.py rebuilds the full pointer from it. | | |
| | `row_file, row_index` | Where the row sits: the data file (its path under data/, the name meta/bench_checked.parquet lists it by) and the row number in it, counting from 0. Not stored in the data files; tools/fetch.py adds them when reading. | | |
| ## Tables under meta/ | |
| - `meta/batches.parquet`: one row per source and batch: license tiers (training_ok, redistribution_ok), the overall size cap used by tools/fetch.py (max_size_bytes), content categories, and the constants and rules used to rebuild full pointers. | |
| - `meta/bench_overlap.parquet`: rows found in public benchmark tasks, or at the address of a GitHub repository the benchmark list names or of a fork of one: scope row matches one row, scope container matches a whole collection; hit_class says how the match was made (docs/fields.md, section Benchmark overlap classes, describes every class). When one row is a copy of benchmark data (benchmark_copy), its whole collection is listed only if the collection is one self-contained unit: one package, code repository, dataset or model repository (collection_kind "unit" in meta/sources.json, except the collections named in bucket_collections). Where collections are buckets (by file type, crawl, date, site and the like), only that row is listed. Every release compares every published data file with the benchmark list (the key version is in meta/projection.json, bench_keys); the table is sorted by source. | |
| - `meta/bench_checked.parquet`: which data files were compared with the benchmark list: scope file has one row per published data file (row_file) with checked true and the file's SHA-256 (sha256). Every release compares every published data file, so a file this table does not list belongs to an older revision of the index and counts as not compared. Scope container lists collections whose name matches a benchmark and that await a ruling (reason pending_ruling). default_keep says whether the default filter keeps the rows; the table is sorted by source. | |
| - `meta/tags.parquet`: the collection tags `campaign:<name>`: for each source, batch, collection, extension, metadata value and content category, the rows that belong to that collection, with row counts and the size cap of the batch (max_size_bytes); `tools/fetch.py --tag campaign:<name>` selects them. Subject and form of a source are not tags: they are the columns `domain` and `form` of `meta/catalog.parquet`. | |
| - `meta/size_caps.json`: the reference size cap: the overall cap over all benchmark task files (the 99th percentile of their sizes), how it was derived (sample count, percentile, value) and how it is recalibrated; provisional. It does not remove rows: tools/fetch.py uses it when downloading. | |
| - `meta/selecting.json`: the record of the last build of the tables under meta/ by the selection build (the accounting of that build, the benchmark list and date of its check, and when it ran); this page no longer shows per-source counts from it: meta/catalog.parquet is the list of sources, with their counts at every release. | |
| - `meta/sources.json`: per-source details, including the layout used to rebuild full pointers. | |
| - `meta/coverage.json`: totals by license tier, source, unit, size and collection tag; `projections.license_unknown` lists the license writings whose tier is unknown. | |
| `cards/<source>.yaml` is the card of a source: what the files of one source are (types, structure, what a task could be built from, risks), how a sample was drawn and read, and for every field `evidence.<field>.fill`: auto (computed from the index when the card was built; `checked_at` is that day), judgment (from sample files that were downloaded and read, with the basis and the files used), derived (a fixed rule over other fields) or unfilled (no evidence yet). Cards are not rebuilt with every upload. Read the evidence before relying on a field; ratios count the sample, not the whole source. [How far to trust each card field](#how-far-to-trust-each-card-field) says more. | |
| ## The default filter | |
| The default subset only contains rows of data files that were compared with the benchmark list (AA-Briefcase-Lite, AA-Omniscience, Agents' Last Exam, Aider Polyglot, AndroidWorld, AutomationBench, BrowseComp, BrowseComp-Plus, COCO, CyberGym, DeepSWE, EnterpriseOps-Gym, ExploitGym, Finance Agent, FrontierSWE v2, GDPval, GraphWalks, Harvey LAB, LHTB, LibriSpeech, MCP Atlas, MCPMark, Multi-SWE-bench, NL2Repo, OSWorld, OSWorld 2, ProofNet, PutnamBench, SEC-bench Pro, SWE-bench Multilingual, SWE-bench Multimodal, SWE-bench Pro, SWE-bench Verified, SWE-sweep, SciCode, Terminal-Bench, Toolathlon, WideSearch, miniF2F, tau2-bench), as of 2026-11-08, minus the copies of benchmark data found there and duplicate copies of the same file. Every published data file is compared at every release (the release builds meta/bench_overlap.parquet and meta/bench_checked.parquet over all of them), so meta/bench_checked.parquet lists every data file of this revision; a file it does not list belongs to an older revision of the index and counts as not compared. Rows of collections awaiting a ruling are left out too. License tiers, sizes and versions do not remove rows; the queries below choose by them. Truncated rows and empty files stay in; the reference counts below count them. A row passes when all of these hold: | |
| - `not_in_benchmark_row / not_in_benchmark_container`: the row and its collection are not in meta/bench_overlap.parquet with hit class benchmark_copy, task_file, data_address (copies of benchmark data found in the rows that were compared, including collections derived from a benchmark, and rows at the address of a GitHub repository the benchmark list names or of a fork of one). | |
| - `checked_for_benchmarks`: the row's data file is listed in meta/bench_checked.parquet as compared with the benchmark list (checked true), and its collection is not listed there as awaiting a ruling; every published data file is listed, so only rows read from an older revision of the index fail this rule. | |
| - `not_duplicate`: the row is not a duplicate copy of another row that the rules above keep, among the rows the query reads: a snapshot holds one row per key (source, uri, range_offset, member_path), but a revision written before that may hold more, and of those only the newest version is kept, by collection time: the latest batch, then the latest part file of the batch (part files are numbered in the order they are written; such a revision wrote a corrected row into a new part file while its old version stayed), then the last row of the file (natural_key_conflict true); rows of a snapshot that a newer batch replaces are removed (stackexchange-dump by source_meta.site); of rows with the same sha256, sha1 or md5 (md5 also the same size_bytes) and the same hash scope one copy is kept, the first by the source's registry_order in meta/batches.parquet, then source, batch, uri, range_offset, member_path, row_file and row_index. It is resolved over the rows of the query itself with window functions, so the copy kept is one the query returns: a query of one source keeps its rows whose copy is in another source. | |
| `tools/fetch.py` applies it as three criteria of its default profile (benchmark, rows that matched a benchmark; not compared, rows not compared with the benchmark list yet, counted apart; duplicate, judged last over the units every other criterion keeps), which also removes rows recorded in a language other than English and rows above 20 MB; it prints how many units each criterion removed. Each criterion has its own option (`--keep-duplicates`, `--allow-benchmark`, `--allow-not-compared`, `--any-language`, `--any-size`); `--all` turns off every criterion except benchmark and not compared, so rows that matched a benchmark come in only with `--allow-benchmark`, and rows not compared yet only with `--allow-not-compared` or `--allow-benchmark`. The training permit and the personal-data mark are labels of every row, not filters: by default every row comes, whatever its license and whether it is marked as carrying personal data, and two options leave such rows out only when given: `--training-only` the rows whose license does not let the files be shipped (a training tier yes and a redistribution tier yes or conditional stay), and `--no-personal-data` the rows of sources or rows marked as carrying personal data. Size caps apply only when downloading: by default the overall cap of meta/size_caps.json (the 99th percentile of all benchmark task files), and under the profile at most 20 MB, guards against huge files, and `--max-size N` uses N bytes. A row above its cap is recorded as too_large and not downloaded; a row of unknown size is downloaded up to the cap. `--max-size` limits downloads only: rows above the cap stay in the selection and in `_meta/fetch_manifest.jsonl`. | |
| ## Units and files | |
| Rows of a material set (batch name `<name>`, tag `campaign:<name>`) carry their place in a task in `extra.source_meta` (`tools/fetch.py` copies them into its manifests): | |
| | Field | Meaning | | |
| |---|---| | |
| | `unit_group` | The unit the row belongs to: a test case, one workbook, one package; the files of a unit share it. The README.md and LICENSE of the source have none. | | |
| | `pool_path`, `pool_leaf`, `pool_domain` | Where the file goes in the task layout and the domain leaf of its unit. | | |
| A unit is the group of files its upstream publishes as one thing; its key `unit_id` is defined in the glossary under How it is made in the [data page's manual](https://battam-training-data-foundation.static.hf.space/index.html?lng=en#manual). A corpus has no unit groups: it is counted in rows, and `tools/fetch.py` takes it row by row, each row under its own key as its `unit_id`. `meta/catalog.parquet` gives every source's counts in the columns `units` and `files`; it is the list of sources, and this page keeps no per-source table. To list the units of one source: | |
| ```sql | |
| SELECT json_extract_string(p.extra, '$.source_meta.unit_group') AS unit_group, count(*) AS files | |
| FROM p WHERE p.source = '<source>' GROUP BY ALL ORDER BY 1; | |
| ``` | |
| ## Batches still being collected | |
| These batches had status `collecting` in meta/batches.parquet when this page was built, so their counts above will grow. A batch that stays in this list from one build of this page to the next is a long-running collection. | |
| | Source | Batch | Rows so far | | |
| |---|---|---:| | |
| | appsec-trees | all | 383,432 | | |
| | asciinema | all | 5 | | |
| | bioinformatics-public-archives | all | 278,202 | | |
| | fedora-copr-build-results | all | 552,200 | | |
| | fedora-koji-build-logs | all | 561,233 | | |
| | gerrit-code-review | all | 4,061,745 | | |
| | github-release-assets | all | 200,439 | | |
| | habs-haer-hals | all | 2,673 | | |
| | harvard-dataverse | all | 1,191,607 | | |
| | hf-training-records | all | 487,960 | | |
| | internet-archive-open-licensed | all | 4,228,665 | | |
| | kaggle-file-listings | all | 239,737 | | |
| | launchpad-ubuntu-bugs | all | 174,719 | | |
| | mendeley-data | all | 15,943,934 | | |
| | modelscope | all | 8,726,153 | | |
| | mozilla-treeherder-ci-logs | all | 37,531 | | |
| | npm | all | 61,099,255 | | |
| | nuget | all | 1,559,773 | | |
| | openqa-os-test-results | all | 6,839 | | |
| | owid-charts | all | 3,730 | | |
| | pmc-open-access | all | 19,814,026 | | |
| | reddit-threads-arctic-shift | all | 318,856 | | |
| | rubygems | all | 1,019,540 | | |
| | solver-benchmark-instances | all | 215,670 | | |
| | zbmath-open | all | 1,576,296 | | |
| | appsec-trees | inc | 110,819 | | |
| | fedora-koji-build-logs | inc | 82,745 | | |
| | harvard-dataverse | inc | 48,586 | | |
| | hf-training-records | inc | 2,215 | | |
| | mendeley-data | inc | 110,931 | | |
| | npm | inc | 31,328,781 | | |
| | pmc-open-access | inc | 4,420,485 | | |
| ## Querying with DuckDB | |
| Run these statements once (DuckDB 1.1 or newer reads `hf://` paths and has `SET VARIABLE`; set `HF_TOKEN` for higher rate limits). The first reads `meta/catalog.parquet`, whose column `data_files` names the data files that hold each source's rows; the view `p` reads exactly those files, so no request lists the folders of `data/`. They define the views used below: `p` rows, `b` batches, `o` benchmark overlap, `c` benchmark check coverage, `t` collection tags. Duplicates have no table: the view `selected` finds them among its own rows. | |
| ```sql | |
| SET VARIABLE data_files = (SELECT list('hf://datasets/Battam/training-data-foundation/' || f ORDER BY f) FROM (SELECT DISTINCT unnest(data_files) AS f FROM read_parquet('hf://datasets/Battam/training-data-foundation/meta/catalog.parquet'))); | |
| CREATE OR REPLACE VIEW p AS SELECT * EXCLUDE (filename, file_row_number), replace(substr(filename, length('hf://datasets/Battam/training-data-foundation/data/') + 1), '\', '/') AS row_file, file_row_number AS row_index FROM read_parquet(getvariable('data_files'), union_by_name = true, filename = true, file_row_number = true); | |
| CREATE OR REPLACE VIEW b AS SELECT * FROM read_parquet('hf://datasets/Battam/training-data-foundation/meta/batches.parquet'); | |
| CREATE OR REPLACE VIEW o AS SELECT * FROM read_parquet('hf://datasets/Battam/training-data-foundation/meta/bench_overlap.parquet'); | |
| CREATE OR REPLACE VIEW t AS SELECT * FROM read_parquet('hf://datasets/Battam/training-data-foundation/meta/tags.parquet'); | |
| CREATE OR REPLACE VIEW c AS SELECT * FROM read_parquet('hf://datasets/Battam/training-data-foundation/meta/bench_checked.parquet'); | |
| CREATE OR REPLACE VIEW s AS SELECT source, domain, form, pii.level AS pii_level, license.spdx AS spdx, files FROM read_parquet('hf://datasets/Battam/training-data-foundation/meta/catalog.parquet'); | |
| CREATE OR REPLACE VIEW selected AS | |
| SELECT * EXCLUDE (duplicate_reason) FROM ( | |
| SELECT * EXCLUDE (dup_scope, dup_sha256, dup_sha1, dup_md5, dup_unit, dup_ord, dup_date, dup_sdate, dup_rev, dup_sup, dup_nk_rank, dup_nk_n, dup_r_sha256, dup_r_sha1, dup_r_md5), | |
| CASE WHEN dup_nk_rank > 1 THEN 'natural_key' WHEN dup_sup THEN 'superseded' WHEN dup_r_sha256 > 1 THEN 'same_sha256' WHEN dup_r_sha1 > 1 THEN 'same_sha1' WHEN dup_r_md5 > 1 THEN 'same_md5' END AS duplicate_reason, | |
| dup_nk_n > 1 AND dup_nk_rank = 1 AS natural_key_conflict | |
| FROM (SELECT *, | |
| CASE WHEN dup_sha256 IS NOT NULL THEN row_number() OVER (PARTITION BY dup_scope, dup_sha256 ORDER BY dup_sup, dup_nk_rank > 1, dup_ord, source, batch, uri, range_offset, member_path, row_file, row_index) END AS dup_r_sha256, CASE WHEN dup_sha1 IS NOT NULL THEN row_number() OVER (PARTITION BY dup_scope, dup_sha1 ORDER BY dup_sup, dup_nk_rank > 1, dup_ord, source, batch, uri, range_offset, member_path, row_file, row_index) END AS dup_r_sha1, CASE WHEN dup_md5 IS NOT NULL THEN row_number() OVER (PARTITION BY dup_scope, dup_md5, size_bytes ORDER BY dup_sup, dup_nk_rank > 1, dup_ord, source, batch, uri, range_offset, member_path, row_file, row_index) END AS dup_r_md5 | |
| FROM (SELECT *, row_number() OVER (PARTITION BY source, uri, range_offset, member_path ORDER BY dup_sup, dup_date DESC, dup_rev DESC, batch DESC, row_file DESC, row_index DESC) AS dup_nk_rank, | |
| count(*) OVER (PARTITION BY source, uri, range_offset, member_path) AS dup_nk_n | |
| FROM (SELECT *, dup_unit IS NOT NULL AND batch <> arg_max(batch, struct_pack(d := dup_sdate, r := dup_rev, b := batch)) OVER (PARTITION BY source, dup_unit) AS dup_sup | |
| FROM (SELECT * REPLACE (CASE WHEN length(dup_sha256) = 64 AND regexp_full_match(dup_sha256, '[0-9a-f]+') THEN dup_sha256 END AS dup_sha256, CASE WHEN length(dup_sha1) = 40 AND regexp_full_match(dup_sha1, '[0-9a-f]+') THEN dup_sha1 END AS dup_sha1, CASE WHEN length(dup_md5) = 32 AND regexp_full_match(dup_md5, '[0-9a-f]+') AND size_bytes IS NOT NULL THEN dup_md5 END AS dup_md5), | |
| contains(lower(batch), 'revised') AS dup_rev | |
| FROM (SELECT p.*, (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.pointer_id') WHEN coalesce(json_contains(json_extract(p.extra, '$._absent'), '"pointer_id"'), false) THEN NULL WHEN json_type(p.extra, '$.pointer_id') IS NOT NULL THEN json_extract_string(p.extra, '$.pointer_id') WHEN json_type(p.extra, '$.pid') IS NOT NULL THEN p.source || ':' || p.collection || ':' || json_extract_string(p.extra, '$.pid') WHEN p.parent_pointer_id IS NOT NULL AND p.member_path IS NOT NULL THEN CASE WHEN length(p.parent_pointer_id) - length(replace(p.parent_pointer_id, ':', '')) >= 2 THEN p.source || ':' || p.collection || ':' || substr(p.parent_pointer_id, strpos(p.parent_pointer_id, ':') + strpos(substr(p.parent_pointer_id, strpos(p.parent_pointer_id, ':') + 1), ':') + 1) || '!/' || p.member_path END WHEN b.pid_segments IS NOT NULL THEN p.source || ':' || p.collection || ':' || array_to_string(list_slice(string_split((CASE WHEN b.uri_swap_to IS NOT NULL AND json_extract_string(p.extra, '$._uri_orig') IS NULL THEN CASE WHEN starts_with(p.uri, b.uri_swap_to) AND ends_with(p.uri, b.uri_swap_suffix) AND length(p.uri) >= length(b.uri_swap_to) + length(b.uri_swap_suffix) THEN b.uri_swap_from || substr(p.uri, length(b.uri_swap_to) + 1, length(p.uri) - length(b.uri_swap_to) - length(b.uri_swap_suffix)) END ELSE p.uri END), '/'), -b.pid_segments, -1), '/') || CASE WHEN b.pid_at_offset THEN '@' || CAST(p.range_offset AS VARCHAR) ELSE '' END END) AS pointer_id, p.size_bytes IS NULL AS size_unknown, | |
| (CASE WHEN coalesce(nullif(CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.license_override.training_ok') WHEN json_type(p.extra, '$.license_override') IS NOT NULL THEN json_extract_string(p.extra, '$.license_override.training_ok') WHEN (p.license_spdx IS NOT NULL OR p.license_training_ok IS NOT NULL OR p.license_redistribution_ok IS NOT NULL OR p.license_notes IS NOT NULL) THEN p.license_training_ok WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"license_override"'), false) THEN b.const_training_ok END, ''), b.training_ok) IN ('yes', 'conditional', 'no') THEN coalesce(nullif(CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.license_override.training_ok') WHEN json_type(p.extra, '$.license_override') IS NOT NULL THEN json_extract_string(p.extra, '$.license_override.training_ok') WHEN (p.license_spdx IS NOT NULL OR p.license_training_ok IS NOT NULL OR p.license_redistribution_ok IS NOT NULL OR p.license_notes IS NOT NULL) THEN p.license_training_ok WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"license_override"'), false) THEN b.const_training_ok END, ''), b.training_ok) ELSE 'unknown' END) AS training_tier, | |
| (CASE WHEN coalesce(nullif(CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.license_override.redistribution_ok') WHEN json_type(p.extra, '$.license_override') IS NOT NULL THEN json_extract_string(p.extra, '$.license_override.redistribution_ok') WHEN (p.license_spdx IS NOT NULL OR p.license_training_ok IS NOT NULL OR p.license_redistribution_ok IS NOT NULL OR p.license_notes IS NOT NULL) THEN p.license_redistribution_ok WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"license_override"'), false) THEN b.const_redistribution_ok END, ''), b.redistribution_ok) IN ('yes', 'conditional', 'no') THEN coalesce(nullif(CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.license_override.redistribution_ok') WHEN json_type(p.extra, '$.license_override') IS NOT NULL THEN json_extract_string(p.extra, '$.license_override.redistribution_ok') WHEN (p.license_spdx IS NOT NULL OR p.license_training_ok IS NOT NULL OR p.license_redistribution_ok IS NOT NULL OR p.license_notes IS NOT NULL) THEN p.license_redistribution_ok WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"license_override"'), false) THEN b.const_redistribution_ok END, ''), b.redistribution_ok) ELSE 'unknown' END) AS redistribution_tier, | |
| coalesce((SELECT bool_and(c.checked) FROM c WHERE c.scope = 'file' AND c.row_file = p.row_file), false) AND NOT EXISTS (SELECT 1 FROM c WHERE c.scope = 'container' AND NOT c.checked AND c.source = p.source AND c.collection = split_part(p.collection, '@', 1)) AS checked_for_benchmarks, | |
| coalesce((CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.hash_scope') WHEN json_type(p.extra, '$.hash_scope') IS NOT NULL THEN json_extract_string(p.extra, '$.hash_scope') WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"hash_scope"'), false) THEN b.const_hash_scope END), 'file') AS dup_scope, | |
| (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.hashes.sha256') WHEN json_type(p.extra, '$.hashes.sha256') IS NOT NULL THEN json_extract_string(p.extra, '$.hashes.sha256') WHEN coalesce(json_contains(json_extract(p.extra, '$._hx'), '"sha256"'), false) THEN NULL ELSE lower(hex(p.sha256)) END) AS dup_sha256, | |
| (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.hashes.sha1') WHEN json_type(p.extra, '$.hashes.sha1') IS NOT NULL THEN json_extract_string(p.extra, '$.hashes.sha1') WHEN coalesce(json_contains(json_extract(p.extra, '$._hx'), '"sha1"'), false) THEN NULL ELSE lower(hex(p.sha1)) END) AS dup_sha1, | |
| (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.hashes.md5') WHEN json_type(p.extra, '$.hashes.md5') IS NOT NULL THEN json_extract_string(p.extra, '$.hashes.md5') WHEN coalesce(json_contains(json_extract(p.extra, '$._hx'), '"md5"'), false) THEN NULL ELSE lower(hex(p.md5)) END) AS dup_md5, | |
| CASE p.source WHEN 'stackexchange-dump' THEN nullif((CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.source_meta.' || 'site') WHEN json_type(p.extra, '$.source_meta') IS NOT NULL THEN json_extract_string(p.extra, '$.source_meta.' || 'site') WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"source_meta"'), false) THEN json_extract_string(b.const_source_meta, '$.' || 'site') END), '') END AS dup_unit, | |
| b.registry_order AS dup_ord, | |
| replace(regexp_extract(coalesce(p.batch, ''), '[0-9]{4}-?[0-9]{2}-?[0-9]{2}'), '-', '') AS dup_date, | |
| CASE WHEN p.source IN ('stackexchange-dump') THEN coalesce(nullif(replace(regexp_extract(coalesce(p.batch, ''), '[0-9]{4}-?[0-9]{2}-?[0-9]{2}'), '-', ''), ''), replace(regexp_extract(coalesce((CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.source_meta.' || 'batch') WHEN json_type(p.extra, '$.source_meta') IS NOT NULL THEN json_extract_string(p.extra, '$.source_meta.' || 'batch') WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"source_meta"'), false) THEN json_extract_string(b.const_source_meta, '$.' || 'batch') END), ''), '[0-9]{4}-?[0-9]{2}-?[0-9]{2}'), '-', '')) ELSE '' END AS dup_sdate | |
| FROM p JOIN b ON b.source = p.source AND b.batch = p.batch | |
| WHERE NOT EXISTS (SELECT 1 FROM o WHERE o.scope = 'row' AND o.hit_class IN ('benchmark_copy', 'task_file', 'data_address') AND o.source = p.source AND o.uri = p.uri AND o.range_offset IS NOT DISTINCT FROM p.range_offset AND o.member_path IS NOT DISTINCT FROM p.member_path) | |
| AND NOT EXISTS (SELECT 1 FROM o WHERE o.scope = 'container' AND o.hit_class IN ('benchmark_copy', 'task_file', 'data_address') AND o.source = p.source AND o.collection = split_part(p.collection, '@', 1)) | |
| AND coalesce((SELECT bool_and(c.default_keep) FROM c WHERE c.scope = 'file' AND c.row_file = p.row_file), false) AND NOT EXISTS (SELECT 1 FROM c WHERE c.scope = 'container' AND NOT c.default_keep AND c.source = p.source AND c.collection = split_part(p.collection, '@', 1))))))) | |
| ) WHERE duplicate_reason IS NULL; | |
| ``` | |
| The query reads the row tables remotely and only the columns it needs; a full pass over every source moves a few gigabytes. Add `WHERE source IN (...)` to the catalog read of the first statement and to `p` to stay small; the duplicates are then resolved among the rows read. The view adds training_tier and redistribution_tier (yes, conditional, no or unknown), checked_for_benchmarks (true when the row was compared with the benchmark list and its collection is not awaiting a ruling) and natural_key_conflict (true when other rows with the same natural key were removed as duplicates and this one, the newest version by collection time, was kept; only in a revision written before snapshots held one row per key). | |
| ## Ready-made queries | |
| Each query runs on the `selected` view above. | |
| 1. Only rows that may be used for training (training tier yes or conditional): | |
| ```sql | |
| SELECT p.source, p.uri, p.size_bytes, p.training_tier FROM selected p | |
| WHERE p.training_tier IN ('yes', 'conditional') LIMIT 20; | |
| ``` | |
| `python tools/fetch.py --tier yes,conditional --limit 20 --out ./files` | |
| 2. Only the latest version of each package. Latest means the version released last (by release time, so a fix released later for an older line counts as the latest); all files of that version are kept, and rows without a version or a release time are left out. Package ecosystems and the release time used: | |
| | Source | Release time | | |
| |---|---| | |
| | pypi | `source_meta.upload_time` | | |
| | npm | `source_meta.published` | | |
| | crates-io | `source_meta.created_at` | | |
| | cran | none (the snapshot lists only the current version of each package) | | |
| | conda-forge-packages | `source_meta.timestamp` | | |
| | ansible-galaxy-collections | `source_meta.published` | | |
| | artifact-hub-helm-charts | `source_meta.created` | | |
| | go-module-proxy-zips | `source_meta.index_timestamp` | | |
| | hackage-packages | `source_meta.uploaded` | | |
| Not ordered by this query: | |
| - debian-sources: rows carry no release time, and Debian versions need the dpkg ordering rules, which plain SQL does not have; each suite lists one version per source package, so choose a suite with `source_meta.suite` instead. | |
| - nuget, rubygems: no release-time field is defined for these rows yet; every version is kept. | |
| ```sql | |
| CREATE OR REPLACE VIEW latest_version AS | |
| WITH v AS ( | |
| SELECT p.*, concat_ws('/', p.collection, (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.source_meta.' || 'chart') WHEN json_type(p.extra, '$.source_meta') IS NOT NULL THEN json_extract_string(p.extra, '$.source_meta.' || 'chart') WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"source_meta"'), false) THEN json_extract_string(b.const_source_meta, '$.' || 'chart') END)) AS package, (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.source_meta.' || 'version') WHEN json_type(p.extra, '$.source_meta') IS NOT NULL THEN json_extract_string(p.extra, '$.source_meta.' || 'version') WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"source_meta"'), false) THEN json_extract_string(b.const_source_meta, '$.' || 'version') END) AS version, | |
| try_cast(CASE p.source WHEN 'pypi' THEN (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.source_meta.' || 'upload_time') WHEN json_type(p.extra, '$.source_meta') IS NOT NULL THEN json_extract_string(p.extra, '$.source_meta.' || 'upload_time') WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"source_meta"'), false) THEN json_extract_string(b.const_source_meta, '$.' || 'upload_time') END) WHEN 'npm' THEN (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.source_meta.' || 'published') WHEN json_type(p.extra, '$.source_meta') IS NOT NULL THEN json_extract_string(p.extra, '$.source_meta.' || 'published') WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"source_meta"'), false) THEN json_extract_string(b.const_source_meta, '$.' || 'published') END) WHEN 'crates-io' THEN (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.source_meta.' || 'created_at') WHEN json_type(p.extra, '$.source_meta') IS NOT NULL THEN json_extract_string(p.extra, '$.source_meta.' || 'created_at') WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"source_meta"'), false) THEN json_extract_string(b.const_source_meta, '$.' || 'created_at') END) WHEN 'cran' THEN '1970-01-01T00:00:00Z' WHEN 'conda-forge-packages' THEN (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.source_meta.' || 'timestamp') WHEN json_type(p.extra, '$.source_meta') IS NOT NULL THEN json_extract_string(p.extra, '$.source_meta.' || 'timestamp') WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"source_meta"'), false) THEN json_extract_string(b.const_source_meta, '$.' || 'timestamp') END) WHEN 'ansible-galaxy-collections' THEN (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.source_meta.' || 'published') WHEN json_type(p.extra, '$.source_meta') IS NOT NULL THEN json_extract_string(p.extra, '$.source_meta.' || 'published') WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"source_meta"'), false) THEN json_extract_string(b.const_source_meta, '$.' || 'published') END) WHEN 'artifact-hub-helm-charts' THEN (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.source_meta.' || 'created') WHEN json_type(p.extra, '$.source_meta') IS NOT NULL THEN json_extract_string(p.extra, '$.source_meta.' || 'created') WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"source_meta"'), false) THEN json_extract_string(b.const_source_meta, '$.' || 'created') END) WHEN 'go-module-proxy-zips' THEN (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.source_meta.' || 'index_timestamp') WHEN json_type(p.extra, '$.source_meta') IS NOT NULL THEN json_extract_string(p.extra, '$.source_meta.' || 'index_timestamp') WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"source_meta"'), false) THEN json_extract_string(b.const_source_meta, '$.' || 'index_timestamp') END) WHEN 'hackage-packages' THEN (CASE WHEN starts_with(coalesce(p.extra, ''), '{"_row":') THEN json_extract_string(p.extra, '$._row.source_meta.' || 'uploaded') WHEN json_type(p.extra, '$.source_meta') IS NOT NULL THEN json_extract_string(p.extra, '$.source_meta.' || 'uploaded') WHEN NOT coalesce(json_contains(json_extract(p.extra, '$._absent'), '"source_meta"'), false) THEN json_extract_string(b.const_source_meta, '$.' || 'uploaded') END) END AS TIMESTAMPTZ) AS released | |
| FROM selected p JOIN b ON b.source = p.source AND b.batch = p.batch | |
| WHERE p.source IN ('pypi', 'npm', 'crates-io', 'cran', 'conda-forge-packages', 'ansible-galaxy-collections', 'artifact-hub-helm-charts', 'go-module-proxy-zips', 'hackage-packages') | |
| ), best AS ( | |
| SELECT source, package, arg_max(version, released) AS version FROM ( | |
| SELECT source, package, version, max(released) AS released FROM v | |
| WHERE version IS NOT NULL AND released IS NOT NULL GROUP BY ALL) | |
| GROUP BY ALL | |
| ) | |
| SELECT v.* FROM v JOIN best ON best.source = v.source AND best.package = v.package AND best.version = v.version; | |
| SELECT source, package, version, count(*) AS files FROM latest_version GROUP BY ALL ORDER BY 1, 2 LIMIT 20; | |
| ``` | |
| 3. Only rows within the size cap of their batch (max_size_bytes in meta/batches.parquet, the cap `tools/fetch.py` uses by default; rows of unknown size stay in, and the script stops their download at the same cap): | |
| ```sql | |
| SELECT p.source, p.uri, p.size_bytes, b.max_size_bytes FROM selected p JOIN b ON b.source = p.source AND b.batch = p.batch | |
| WHERE p.size_bytes IS NULL OR p.size_bytes <= b.max_size_bytes LIMIT 20; | |
| ``` | |
| `python tools/fetch.py --limit 20 --out ./files` (rows above the cap are recorded as too_large and not downloaded) | |
| ## Examples | |
| `meta/catalog.parquet` has one row per source. Its column `domain` lists the subject codes of the source: a top-level code (D1 to D10) or a leaf below it (such as D1.6), or `multi` when the content spans many subjects, or `unclassified`. Its column `form` names the form of the items (for example `document-collections`). `meta/tags.parquet` holds the collection tags `campaign:<name>`. | |
| 1. Rows of the sources whose subject is D1 or one of its leaves, smallest first: | |
| ```sql | |
| SELECT p.source, p.uri, p.size_bytes FROM selected p | |
| WHERE p.source IN (SELECT source FROM (SELECT source, unnest(domain) AS code FROM read_parquet('hf://datasets/Battam/training-data-foundation/meta/catalog.parquet')) | |
| WHERE code = 'D1' OR starts_with(code, 'D1.')) | |
| ORDER BY p.size_bytes LIMIT 20; | |
| ``` | |
| `python tools/fetch.py --domain D1 --limit 20 --out ./files` | |
| 2. CSV files of the sources of one form: | |
| ```sql | |
| SELECT p.source, p.uri, p.size_bytes FROM selected p | |
| WHERE lower(p.ext) = 'csv' AND p.source IN (SELECT source FROM read_parquet('hf://datasets/Battam/training-data-foundation/meta/catalog.parquet') WHERE form = 'document-collections') | |
| LIMIT 20; | |
| ``` | |
| `python tools/fetch.py --form document-collections --ext csv --limit 20 --out ./files` | |
| 3. The rows of one collection: | |
| `python tools/fetch.py --tag campaign:<name> --limit 20 --out ./files` | |
| 4. Three units of every source of one domain and form, each in a folder of its own, laid out for building tasks: | |
| `python tools/fetch.py --domain D3 --form spreadsheets --sample 3 --out ./data` | |
| `python tools/fetch.py --print-sql ...` prints the exact query the script runs, so any selection can be repeated in DuckDB. The script writes the files under `--out` as `<domain>/<source>/<unit folder>/...` (each unit whole, in a folder of its own named after its `unit_id`; the README.md and LICENSE of a material set beside them), `_meta/manifest.jsonl` with one line per file (source, path, url, sha256, bytes, license, unit_id and more), `_meta/sizes.tsv`, and `_meta/fetch_manifest.jsonl` with one line per selected row. It checks each download against the row's stated size and the hashes the row carries, and which hashes those are depends on the kind of row: | |
| - Whole files and byte ranges: md5, sha1 and sha256 (and sha512 or a git blob sha1 when `extra` carries one; an S3 ETag of a single-part upload counts as md5). crc32 is not compared for them. | |
| - Archive members (zip, other packages, 7z): size, crc32, md5, sha1 and sha256; zip members are also checked against the CRC32 in the archive's central directory. sha512 and git blob sha1 are not compared for them. | |
| - WARC and ARC records: the payload size and md5, sha1 and sha256 of the payload. | |
| - gzip members: the CRC32 and length in the gzip trailer, plus the row's crc32, md5, sha1 and sha256 when present. | |
| - Rows with no hash are checked by size only, and rows marked `rolling` may differ from the index without failing (see below). | |
| With `--check-content` it also flags downloads that are hard to use (scanned PDFs, error pages saved as files, extensions that do not match the content) in the manifest field `content_check`; this needs the `file` command and the `pypdf` package (one of the script's dependencies), which then parse the downloaded files (files from the internet) on your machine, and a check whose tool is missing is skipped and named there. | |
| ## How far to trust each card field | |
| Each field of a card has `evidence.<field>.fill`, which says where its value came from: | |
| - `auto`: computed by a program from the rows and the collection headers of the source when the card was built (`checked_at` is that day). Cards are built separately from the data and are not rebuilt with every upload. | |
| - `judgment`: read from sample files that were downloaded and read, with `basis` (why) and `files` (which files). Some carry `second_judge`, an independent second reading. An `auto` value that was corrected after reading the sample is also recorded as `judgment`, with the reason in `basis`. | |
| - `derived`: a fixed rule over other fields of the same card. | |
| - `unfilled`: no evidence yet. The field is left empty on purpose; do not read an empty field as no or none. | |
| A card whose `audit.status` is `draft` has not been reviewed as a whole. Before relying on a card, compare `snapshot.rev` with the commit you are reading and compare `size.files` with the source's count in meta/coverage.json. | |
| | Field group | Fields | Usual fill | How far to trust it | | |
| |---|---|---|---| | |
| | Snapshot | `snapshot.rev`, `snapshot.rev_at`, `snapshot.at` | auto | Which data the card describes: `snapshot.rev` is the commit of the newest data file of the source when the card was built. If it is older than the commit you read, every count on the card is out of date. | | |
| | Counts and file types | `size.files`, `size.bytes`, `unit.batches`, `form.by_ext`, `form.size_quantiles`, `form.over_cap`, `form.date_years` | auto | Exact for the rows that existed at `snapshot.rev`. For current numbers use meta/coverage.json or query the rows; the README totals are recounted at every upload. | | |
| | License | `provenance.licence`, `provenance.licence_tiers`, `provenance.spdx_top` | auto | Copied from the source's own license statement and the rows' license columns. tools/fetch.py does not read the card: it uses the license columns and meta/batches.parquet. `provenance.licence_sample_check` is a judgment from the sample. | | |
| | Benchmark overlap | `risk.contamination`, `risk.overlap_check` | auto, or unfilled when the source was not scanned | The result of the overlap scan at card build time. The default filter does not use it; meta/bench_overlap.parquet and meta/bench_checked.parquet are newer and are what counts. | | |
| | What the files are | `unit.pointer_level`, `unit.usable_unit`, `form.artifact`, `form.source_origin`, `form.parse_cost`, `form.parse_quirks`, `structure.*`, `ships.*`, `subject.*` | judgment or unfilled | Read from a sample of downloaded files; `files` lists them. A share such as `ships.reference_solution.share` is k of the n files read. Treat it as a description of the sample. | | |
| | Risks read from samples | `risk.pii`, `risk.pii_evidence`, `risk.malware` | judgment or unfilled | An empty value means nobody has looked, not that the source is clean. Card text shows email addresses and phone numbers as `[withheld]`, but a ten-digit number written with spaces and no plus sign (such as 555 123 4567) is not treated as a phone number, because it cannot be told apart from counts. | | |
| | Access | `access.credential`, `access.range_supported`, `access.drift` | judgment or unfilled | Whether a row needs a login is in the row's `access.needs_auth` (see the README), not here. | | |
| | Rules | `class`, `unit.state`, `risk.ship_bytes` | derived | `class` is a rule over `ships.*` and `structure`, `unit.state` follows `unit.pointer_level`, and `risk.ship_bytes` equals the redistribution tier. Only as good as the fields they read. | | |
| | Retired | `access.reachable.index_flag` | auto | Retired: it counted whether one machine, since retired, could reach the files; it is now always `(none)` and will be removed in the next card version. | | |
| ## Rebuilding a batch from a collection tag | |
| Collections are published in the repository `Battam/training-data-foundation`, together with `tools/to_pool.py`; the commands below read that repository and use the tools from it. | |
| A collection is a set of rows chosen together for one task pool. Its rows carry the tag `campaign:<name>` and the batch name `<name>`, and record where each file goes in the pool (domain, path, unit) in `source_meta`. Its small files (the README, the LICENSE and the files written for a package) are placed under `campaign_files/<name>/`; their rows point there with a relative uri, which `tools/fetch.py` reads at the same commit as the tables. All other rows point to the upstream files. | |
| Two commands rebuild the batch. Pin the commit so that a later run gets the same rows: | |
| ``` | |
| python tools/fetch.py --data hf://datasets/Battam/training-data-foundation --tag campaign:<name> --all --revision <commit> --out ./fetched | |
| python tools/to_pool.py ./fetched --out ./pools --name <batch-folder> | |
| ``` | |
| `--revision <commit>` reads the tables at that commit. The same pin can be given as the root instead: `--data hf://datasets/Battam/training-data-foundation@<commit>`. | |
| `--all` keeps every row of the collection that the benchmark criteria keep: the rows were selected for the pool, and the rest of the default profile would drop some of them (for example rows above 20 MB). A row that matched a benchmark or was not compared with the benchmark list yet stays out unless `--allow-benchmark` or `--allow-not-compared` is given. `tools/fetch.py` already writes the files, one folder per unit (`<domain>/<source>/<unit folder>/...`, `_meta/manifest.jsonl` and `_meta/sizes.tsv`), copies the pool fields of each row into `_meta/fetch_manifest.jsonl` and writes `_meta/fetch_run.json` with the repository, the commit and its arguments. `tools/to_pool.py` (Python standard library only, next to `tools/transform.py`) adds what the fetch tool does not do: it extracts the units that need `transform` steps, unpacks the units marked `expand`, checks that every source has its README.md and LICENSE and writes `<batch-folder>/<domain>/<source>/<path>` and `_meta/manifest.jsonl`, `_meta/sizes.tsv` and `_meta/delivery.json`. It writes nothing when a row was not downloaded. | |
| Some upstream files change in place (live endpoints). Their rows are marked `rolling`: a size or sha256 that differs from the index is not an error, and the manifest keeps the bytes, sha256 and date actually downloaded with `differs_from_index`. Every other row must match the index exactly. | |
| A unit stored upstream inside an archive or a compressed file has `transform` steps in its row: `unzip:<member>`, `untar:<member>`, `bunzip2`, `gunzip`, `unxz`, `unxxd`, `uudecode`, `uncompress` and `gzip` (level 9, modification time 0, no file name, so the output is the same on every machine). Only the named member is taken out of an archive and it must be a regular file; links and names that leave the output folder are refused. `unxxd` turns a hex dump written by `xxd` or `xxd -a` back into bytes (16 bytes per line in groups of two, a `*` line standing for lines of zero bytes) and refuses any other layout. `uudecode` decodes the lines between the first `begin <mode> <name>` line and its `end` line, never uses that name as a path, and refuses a file with no `begin` line, a second `begin` line or a line that does not decode. `uncompress` decompresses a `.Z` file of Unix `compress` (LZW, magic `1f 9d`, codes of 9 up to at most 16 bits read in groups of eight as `compress` writes them) and refuses a wrong magic, a maximum width outside 9 to 16 and a code that is not yet in the table. The output of `unxz`, `untar`, `unxxd`, `uudecode` and `uncompress` stops at 256,000,000 bytes (a sparse tar member counts at its full size). `tools/fetch.py` downloads and checks the upstream original; `tools/to_pool.py` runs the steps and checks the result against the sha256 recorded in the index (`unit_sha256`), or, when the last step is `gzip` (whose bytes depend on the zlib build), against `content_sha256`, the hash of the bytes before that step. | |