bart-midtrain / README.md
zachnorton03's picture
Add MIT license to dataset card metadata
c932201 verified
|
Raw
History Blame Contribute Delete
7.9 kB
---
license: mit
pretty_name: BART Midtrain
language:
- en
size_categories:
- 10K<n<100K
tags:
- books
- historical
- pre-1930
- ocr
- midtraining
- stem
- internet-archive
dataset_info:
features:
- name: text
dtype: string
---
# BART Midtrain
The midtraining corpus for [BART](https://huggingface.co/datasets/jbduran/bart-dataset-v3) —
pre-1930 mathematics, science, technology, and medicine — plus the full pipeline that built it and
every training mixture it was blended into.
Built by [Unbounded Labs](https://unboundedlab.com).
| | |
|---|---|
| **Corpus documents** | 11,409 |
| **Corpus characters** | 2,543,809,124 |
| **Corpus tokens** | ~604M |
| **Removed by cleaning** | 24% of documents (15,075 → 11,409) |
| **Subject focus** | math, science, technology, medicine |
| **Cutoff** | 1930 |
| **Schema** | single string column `text` |
## What midtraining is
Midtraining sits between pretraining and downstream use. Instead of continuing on the same broad
corpus, we shift the data mixture toward a smaller, higher-quality set of documents while decaying
the learning rate. The goal is to spend the model's final optimization steps on the text we most
want it to internalize — which for us meant pre-1930s math, science, technology, and medicine.
## Repository layout
```
corpus/ ← the midtrain corpus. Start here.
pipeline/
stage2/ Internet Archive harvest 15,075 docs
stage3/ OCRoscope second-opinion filter 13,552 docs
stage4/ boilerplate clean + log-prior 12,791 docs
stage5/ footer strip + anachronism 11,409 docs → corpus/
mixtures/
v1-by-docs/ SUPERSEDED — ratios computed by document count
ratio_00actual/ ratio_12actual/ ratio_25actual/
v2-by-tokens/ CURRENT — ratios computed by token count
ratio_21/ ratio_45/
```
`corpus/` is stage 5's output, promoted to the top so the deliverable isn't buried.
`pipeline/stage5/` keeps that stage's audit artifacts (`stripped/`, `hits/`, `stats/`, `_banned/`).
```python
from datasets import load_dataset
ds = load_dataset("zachnorton03/bart-midtrain", data_dir="corpus", split="train")
```
## How the corpus was built
We focused on finding high-quality math, science, technology and medicine documents from before the
1930s, and broke each major step into stages.
**Stage 1 — subject extraction** *(external, lives in
[bart-dataset-v1](https://huggingface.co/datasets/jbduran/bart-dataset-v1))*. We extracted STEM
documents by their Library of Congress subject tags from the original corpus, targeting
underrepresented Science, Technology, and Medicine subjects.
**Stage 2 — Internet Archive harvest.** We extracted vintage documents from the Internet Archive,
filtering by topic for Math, Science, Medicine, and Technology, and by published date. We then
de-duplicated and applied an OCR filter of 0.85. → **15,075 documents, 1.62B tokens**
**Stage 3 — second opinion.** To get an independent read on OCR quality, we filtered with
Pleias/OCRoscope (0.85) and an alphanumeric ratio of 0.65. Because math documents carry many
unusual symbols, we deliberately kept the alphanumeric ratio relaxed. This removed ~10% of
documents. → **13,552 kept**
**Stage 4 — structural clean + log-prior.** We filtered OCR artifacts and stripped boilerplate
(headers, library stamps, Google Books and HathiTrust furniture, Project Gutenberg headers,
hyphenation, front matter), then mirrored the main corpus with a GPT-2 token log-prior filter at
p2.5–p97.5 (−11.062 to −9.928, calibrated on 10,424 sampled documents). → **12,791 kept**
**Stage 5 — vintage enforcement.** Finally we made sure the corpus was as vintage as possible,
running it through the footer filter and the tiered banned-words list — the same 463-term,
four-tier anachronism filter used on
[bart-dataset-v3](https://huggingface.co/datasets/jbduran/bart-dataset-v3). → **11,409 kept**
As we cleaned the original corpus we learned a great deal about dataset cleaning methodology, and
we applied that knowledge to midtraining extensively. After all the cleaning, we removed **24%** of
the original midtraining data, leaving **~604M tokens** of high-quality midtraining data.
<details>
<summary><b>Per-stage filter detail</b></summary>
| Stage | In | Out | Kept | Chars kept |
|---|---:|---:|---:|---:|
| 2 — IA harvest | — | 15,075 | — | — |
| 3 — OCRoscope | 15,075 | 13,552 | 89.9% | — |
| 4 — clean + prior | 13,552 | 12,791 | 94.4% | 81.7% |
| 5 — footer + anachronism | 12,791 | 11,409 | 89.2% | 84.5% |
Stage 4 removals: `prior_high` 306, `prior_low` 300, `ocr_artifacts` 155.
Stage 5 footer strip: 1,117 of 12,791 documents changed, 1,466 lines removed.
Every stage is resumable at shard granularity — a rerun skips output shards already present and
continues with the remainder. Stage 4's log-prior table and stage 5's banned-term list are each
built once, cached under `_prior/` and `_banned/`, and reused.
</details>
## Training mixtures
Midtraining ran in **three stages of decay**, following the approach HuggingFace used for SmolLM.
Because midtrain documents are much shorter than pretraining documents, we measure the mixture in
**tokens**, not documents. We wanted the midtrain data to see fewer than 3 epochs, and used that
as the guide for the ratio at each stage.
### `mixtures/v2-by-tokens/` — current
| Folder | Target | Achieved | Train tokens | Shards |
|---|---:|---:|---:|---:|
| `ratio_21` | 21% | **20.96%** | 4,124,391,390 | 66 |
| `ratio_45` | 45% | **45.00%** | 2,074,444,767 | 34 |
The ratio is enforced by a ratio-tracking interleave, so it holds over *every* prefix of the
stream, not just the total. Document boundaries are preserved — nothing is concatenated or split
to force the ratio.
### `mixtures/v1-by-docs/` — superseded
Named for what they **actually delivered**, not what they targeted:
| Folder | Target | Achieved (docs) | Shards |
|---|---:|---:|---:|
| `ratio_00actual` | 0% | 0.1% | 99 |
| `ratio_12actual` | 30% | **11.5%** | 1,263 |
| `ratio_25actual` | 60% | **25.1%** | 525 |
Kept for reproducibility. Don't train on these.
### Why there are two generations
One of the biggest pitfalls on this journey came during our final model run. We assumed midtrain
documents would be roughly smaller than the original corpus. We were right — but we didn't realize
how *drastically* smaller they were. Because we had built the mixtures by document count rather
than token count, the blends under-delivered midtrain content badly: a folder targeting 60%
midtrain actually supplied 25%, and one targeting 30% supplied 11.5%.
Our final model was already running when we found the bug. That gave us **36 hours** to rebuild the
mixtures by token before the run would need them. We got them ready in time — and took away a
lesson worth the scare: **verify your intuition.**
## Learning rate schedule
We used nanochat's Warmup-Stable-Decay (WSD), beginning decay at roughly **35%** of training.
SmolLM, by contrast, starts decaying at around 75%.
## Lineage
This corpus is the midtraining counterpart to the BART pretraining series:
[bart-dataset-v1](https://huggingface.co/datasets/jbduran/bart-dataset-v1) →
[v2](https://huggingface.co/datasets/jbduran/bart-dataset-v2) →
[v3](https://huggingface.co/datasets/jbduran/bart-dataset-v3) →
**bart-midtrain**
Stage 1 of this pipeline draws from v1 by subject tag; all mixtures blend `corpus/` against v3.
## Citation
The stage-1 subject extraction derives from Institutional Books 1.0:
```bibtex
@misc{institutionalbooks2025,
title = {Institutional Books 1.0: A 242B Token Dataset from Harvard Library's
Collections, Refined for Accuracy and Usability},
year = {2025},
eprint = {2506.08300},
archivePrefix = {arXiv}
}
```
---
Built by [Unbounded Labs](https://unboundedlab.com).