Built to order

News Article Category Classification using DistilBERT

This project fine-tunes a DistilBERT transformer to sort news articles into five topics — business, entertainment, politics, sport and tech — on the BBC News dataset. Paste any article text into the demo and watch the model assign category probabilities, or browse the per-class performance analysis showing exactly where the model is strongest and where topics overlap. The fine-tuning notebook, evaluation and explainability notes are all documented for the viva. Suitable for B.E./B.Tech final-year projects in AI & Machine Learning, Computer Science and IT.

News Article Category Classification using DistilBERT — project thumbnail preview
More project photos (2)

The problem

Every news aggregator, content-moderation queue and research corpus needs automatic topic tagging, and keyword rules fail at it — "bank" means opposite things in a river-conservation piece and a central-bank story. Contextual language models solved this: a transformer fine-tuned on a few thousand labeled articles classifies topics at near-human accuracy. This project does exactly that on the BBC News corpus (2,225 articles, 5 topics), using DistilBERT — the lighter, faster sibling of BERT that trains in minutes on modest hardware. The demo makes the model tangible: paste article text, get category probabilities instantly. The evaluation is honest about the hard pairs (politics vs entertainment share named entities) and reports per-class F1 rather than hiding behind a single accuracy number.

How it works

  1. The 2,225 BBC articles are loaded with their 5 topic labels and split with stratification into train/validation/test sets.
  2. Text is tokenized with the DistilBERT tokenizer (truncation to 512 tokens) and batched for fine-tuning.
  3. A DistilBERT sequence-classification head is fine-tuned for a few epochs with early stopping on validation macro-F1.
  4. The held-out test set yields accuracy, macro-F1 and per-class precision/recall for the report.
  5. In the demo, pasted text goes through the same tokenizer and model; softmax probabilities are rendered as category bars.
  6. Example headlines per category let examiners probe the model live during the demonstration.

Tech stack:

  • Python 3, Hugging Face Transformers (DistilBERT)
  • PyTorch, scikit-learn
  • pandas, NumPy
  • HTML/CSS/JavaScript classifier demo
  • BBC News dataset (D. Greene)

Dataset & model details

  • Dataset: BBC News corpus (D. Greene & P. Cunningham) — 2,225 full articles from 2004–2005 in 5 classes: business (510), entertainment (386), politics (417), sport (511), tech (401).
  • Task: Single-label topic classification; input = article text ≤512 tokens, output = probability distribution over 5 topics.
  • Model: DistilBERT-base fine-tuned (66M parameters) with a classification head; AdamW, early stopping on validation macro-F1.
  • Metrics: Macro-F1 0.97, accuracy 97.4% (design targets for the built-to-order fine-tuning run); per-class F1 reported. No measured figures are claimed before the run.
Parameter Value
Articles 2,225 across 5 topics
Model DistilBERT-base, 66M parameters
Max sequence 512 tokens
Macro-F1 0.97 (design target)
Accuracy 97.4% (design target)
Inference Approximately 40 ms/article on CPU (expected)
Training Approximately 20 min on a free-tier GPU (expected)

Project features

  • [DistilBERT topic classifier] Fine-tuned on BBC News; input = article text (≤512 tokens), output = probabilities over 5 categories.
  • [Live text-classifier demo] Paste any article or headline; the demo returns the full probability distribution with the predicted category highlighted.
  • [Per-class performance analysis] F1 for each of the 5 categories with a confusion analysis of the overlapping pairs.
  • [Category explorer] The five topics with article counts and real-style example headlines per category.
  • [Why-transformers explainer] A documented comparison of the contextual approach vs keyword/TF-IDF baselines, for the viva.
  • [Stratified evaluation] 80/10/10 stratified split keeps the minority categories fairly represented in every split.
  • [Fast inference] ~40 ms per article on CPU — the demo classifies pasted text instantly.

What is included

  • Fine-tuning notebook (preprocessing → training → evaluation)
  • Fine-tuned DistilBERT weights and tokenizer
  • Live classifier web demo
  • Per-class metrics and confusion analysis plots
  • Project report PDF (background, transformer theory, methodology, results)
  • PPT presentation for final review
  • Viva Q&A preparation document (attention, BERT vs DistilBERT, fine-tuning, evaluation metrics)

Limitations & prerequisites

  • F1 and accuracy are design targets; the report records the actual metrics from the fine-tuning run for the order.
  • The corpus is 2004–2005 BBC English — modern slang, new entities and other languages are out of scope as shipped.
  • Very short headlines carry less signal than full articles; the demo notes confidence accordingly.
  • Politics/entertainment is the hardest pair (shared named entities); the confusion analysis documents this honestly.
  • Single-label only — articles spanning two topics get the dominant one.

Frequently Asked Questions

Why DistilBERT instead of BERT?

40% fewer parameters with ~97% of BERT's performance on this task — it fine-tunes in ~20 minutes on a free GPU and infers in milliseconds on CPU, which matters for a student-build demo.

What is the BBC News dataset?

2,225 full BBC articles from 2004–2005 labeled into business, entertainment, politics, sport and tech — a classic, clean benchmark for topic classification.

How does it beat keyword matching?

Contextual embeddings: the model learns that "bank raised rates" (business) and "river bank restoration" (not in this corpus, but the principle holds) differ by surrounding words — keyword lists cannot do this.

Which categories confuse it most?

Politics vs entertainment — both mention the same public figures. The per-class analysis quantifies this pair explicitly.

Can I classify my own articles?

Yes — the demo accepts any pasted English text, and the shipped model file classifies new articles through the same pipeline.

Is this project suitable for a final-year project?

Yes — for AI/ML, Computer Science and IT programs. It demonstrates transformer fine-tuning, rigorous evaluation and an interactive deployment. Suitable for B.E./B.Tech final-year projects in AI & Machine Learning, Computer Science and IT.

Components & software requirements
  • Python 3, Hugging Face Transformers (DistilBERT)
  • PyTorch, scikit-learn
  • pandas, NumPy
  • HTML/CSS/JavaScript classifier demo
  • BBC News dataset (D. Greene)

Dataset & model details

  • Dataset: BBC News corpus (D. Greene & P. Cunningham) — 2,225 full articles from 2004–2005 in 5 classes: business (510), entertainment (386), politics (417), sport (511), tech (401).
  • Task: Single-label topic classification; input = article text ≤512 tokens, output = probability distribution over 5 topics.
  • Model: DistilBERT-base fine-tuned (66M parameters) with a classification head; AdamW, early stopping on validation macro-F1.
  • Metrics: Macro-F1 0.97, accuracy 97.4% (design targets for the built-to-order fine-tuning run); per-class F1 reported. No measured figures are claimed before the run.
Delivery information

Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.

Support terms

Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.

Download abstract (PDF)

Related guides

All guides
Illustration of object tracking showing video frames with bounding boxes and persistent ID labels following people and vehicles, comparing motion prediction and appearance matching.B.E./B.Tech Computer Science and Electronics students building video analytics projects — people counting, vehicle tracking, sports analysis — who have detection working and need

Object Tracking: DeepSORT and ByteTrack Explained

Detection finds objects per frame; tracking keeps their identities across frames. This guide explains tracking-by-detection, Kalman motion models, DeepSORT's appearance embeddings vs ByteTrack's low-confidence box recovery, tracking metrics (HOTA, IDF1, ID switches), and the tuning parameters that determine real-world quality.

Read guide
Illustration of image segmentation showing U-Net's U-shaped encoder-decoder with skip connections producing pixel masks, alongside Mask R-CNN detecting instances with masks.B.E./B.Tech Computer Science and AI/ML students moving from image classification or detection to pixel-level understanding — medical imaging, defect detection, autonomous driving

Image Segmentation: U-Net and Mask R-CNN

When projects need pixel-level answers, segmentation delivers. This guide explains semantic vs instance vs panoptic segmentation, U-Net's encoder-decoder with skip connections, Mask R-CNN's parallel mask head, Dice and IoU evaluation, paired augmentation, and how to choose the right architecture for your data and question.

Read guide
Illustration of Whisper speech-to-text showing sound waves flowing into a neural network and emerging as transcribed text with timestamps and speaker labels.B.E./B.Tech Computer Science and AI/ML students adding speech-to-text to projects — voice assistants, meeting transcription, accessibility tools

Whisper for Speech-to-Text in Student Projects

Whisper transcribes speech in dozens of languages with no training required. This guide covers how it works, choosing among model sizes, running it locally with faster-whisper, handling hour-long audio, timestamps and speaker diarization, multilingual quirks, and honest evaluation with word error rate.

Read guide
Get a quotation