News text classification
The Line That Refuses to Run
A news classifier comparing TF-IDF and DistilBERT.
- Role
- Author
- Classification
- Engineering prototype
Problem
A failed download can quietly become a fake score.
How it was solved
The run stops if the real dataset is missing.
- AG News
- TF-IDF and DistilBERT
- One evaluation
Result
It stops
no real data, no number
Built with
- Hugging Face Transformers
- scikit-learn
- PyTorch
Research project / Text classification
The dataset will not download and there is a synthetic fixture sitting right there. Falling back to it would keep the pipeline green. What should the code do instead?
Why the fallback is not automatic86% of its vocabulary
A loader that refuses, and a split read once
This diagram in words
- Load AG News gate — The synthetic fixture exists and is not substituted when the download fails.Datasets
- TF-IDF baselines process — Logistic regression, linear SVM, random forest.scikit-learn
- DistilBERT process — Fine-tuned through the Trainer.Hugging Face Transformers · PyTorch
- Run stops sink — No fallback. A green pipeline on invented text measures nothing.
- Validation split store — Stratified. The only split anything is tuned against.
- Published test split gate — Read once, for the final number. No choice is made after it.
- Metrics report artifact — Classification metrics and confusion matrices; latency optional.
Read the full background
Problem
Why this work exists
A pipeline that depends on a download will eventually fail to get it, and there is almost always a fixture nearby that would let it keep going. Taking that option produces a number - and a number produced from template text is indistinguishable, in a results table, from one that means something.
Contribution
What I can claim
Built both tracks and the shared evaluation, and made the loader refuse: when AG News cannot be fetched it raises, and the synthetic fixture is reachable only by passing --synthetic. The fixture is for developing code offline, and the code says so rather than treating it as a fallback.
Method
What to do when the data does not arrive
Two tracks, one task, one evaluation: TF-IDF baselines against a fine-tuned transformer on news headlines.
- AG News loadedevaluate on the published test split
- raises, and stopsthe default when the download fails
- templates, on requestonly with --synthetic, for offline development
Why the middle one is the default
Words belonging to only one of the four classes, counted across the fixture’s 20 template sentences: 86% of its vocabulary. Sorting text like that is a lookup rather than a classification, which is why the loader will not reach for it on its own. The repository publishes no accuracy, and this page reports none.
Request
The pipeline needs a public dataset, fetched at run time.
Fail
There is a synthetic fixture in the repository for developing offline.
Refuse
So the loader raises instead.
Count
The reason is in the fixture itself.
Compare
With real data the two tracks are then measured the same way, on a test split kept out of tuning entirely.
What this does not show
No result is published and none is claimed. The repository versions no data, no trained model, no checkpoints, no metrics and no run metadata, so there is no accuracy, no F1 and no verdict on whether the transformer earns its cost here. The vocabulary counts on this page describe the synthetic fixture, which exists for offline development and must not be used to report model capability.
How it was built
System
Workflow and decisions
A loader that can refuse, two training paths behind one interface, a shared evaluation, and inference helpers for locally saved artefacts. Models and results are untracked by design, which is why the repository can be read without any of it being mistaken for a measurement.
- 1Load AG News, or stop
- 2TF-IDF: logistic regression, linear SVM or random forest
- 3DistilBERT: fine-tuned through the Hugging Face Trainer
- 4a stratified validation split for tuning the transformer
- 5the published test split for the final evaluation only
- 6no tuning of model choices or thresholds against the held-out split
- 7Report classification metrics and confusion matrices, with latency optional
- Python
- Hugging Face Transformers
- Datasets
- scikit-learn
- PyTorch
Evidence
What is actually versioned
The synthetic fixture is 20 hand-written sentences, 5 per class across World, Sports, Business, Sci/Tech. Counting the words in them, 86% appear in exactly one class - so almost every word gives its label away and a bag of words would separate them perfectly. A score measured there would look like a result and be a description of the template list, which is the number an automatic fallback would have produced.
The repository versions source and notebooks but no downloaded data, no trained model, no checkpoints, no metrics, no plots and no run metadata. It states that it therefore makes no verified accuracy, F1, latency, parameter or model-comparison claim, and this page makes none.
TF-IDF (logistic regression, linear SVM or random forest); DistilBERT (fine-tuned through the Hugging Face Trainer). Both are scored the same way on the same task, which is the only arrangement under which the comparison means anything.
How the work is checked
Quality controls
How the work is checked
- The loader raises on a failed download rather than substituting its own fixture, so the pipeline cannot quietly produce a number about nothing
- The synthetic path exists for offline development and is gated behind an explicit flag, with the README stating it must not be used to report capability
- Transformer tuning uses a stratified validation split, and the published test split is kept for the final evaluation only
- The README names what must be recorded before runs are compared - dataset revision, package versions, hardware, seed, training arguments, split policy - and notes that seeding does not make GPU operations deterministic
Limitations
Where the evidence stops
- Nothing is measured here. No data, model, checkpoint or metric is versioned, so there is no accuracy to compare and no claim that either track wins
- The synthetic fixture is not a dataset. Its results are not comparable to AG News or to real news classification, and the page quotes it only to explain why it is not used by default
- Single-task, single-dataset. Whether a fine-tuned transformer earns its cost over TF-IDF is exactly the kind of question this repository is set up to ask and has not answered
- A learning and research project. It is not a deployed content-moderation, routing or editorial decision system, and the README says so first
What this changed in my practice
What this changed in my practice
The failure mode I was guarding against is not a wrong number, it is a plausible one. A fallback that keeps the pipeline green converts a missing dataset into a results table, and by the time anyone reads that table the distinction is gone. Counting the fixture's vocabulary afterwards was the part that convinced me: eighty-six percent of the words are giveaways, so the fallback would not have scored badly - it would have scored beautifully.