← All models

text-classification · text · WASM · ~13 MB

News topic classification — tag any headline as you type

A tiny distilled BERT with a dedicated 10-class topic head reads a headline or article and picks its desk — Sports, Business & Finance, Politics, Science, Health and more — with a confidence, in a single forward pass. Type below and watch the newsroom board auto-tag it live. Nothing leaves your device.

At a glance

Modeltarekziade/topic_classification
Task / pipelinetext-classification
Labels10 fixed topics: Society & Culture · Science & Mathematics · Health · Education & Reference · Computers & Internet · Sports · Business & Finance · Entertainment & Music · Family & Relationships · Politics & Government (multi-label — an independent sigmoid score per topic)
Architecturextremedistil-l6-h256-uncased (6-layer, 256-hidden distilled BERT) with a sequence-classification head
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~13 MB, cached after first load
LicenseMIT
Web APIsWebAssembly, Web Workers — all Baseline widely available

Run it

Type a headline or paste a paragraph. It re-tags automatically (debounced) a moment after you stop typing. The verdict shows the top topic; the bars below show the full distribution.

See inside — the per-topic scores

This head is multi-label: it gives every topic its own independent 0–100% score (a sigmoid per label), so the bars below don't add up to 100% — a story can genuinely belong to several desks at once. A clear headline lights one bar; a cross-topic one lights two or three. The top bar is the primary desk; the rest tell you what else it touches.

Dedicated head vs. zero-shot — what's the difference?

This is a dedicated classification head: the label set (these 10 topics) is baked in at training time, and one forward pass produces a probability for every label at once — fast, tiny (~13 MB), and calibrated to exactly this taxonomy.

A zero-shot classifier (like BART-MNLI) works completely differently: you supply the candidate labels at query time, and it runs a separate natural-language-inference pass for each label ("does this text entail the topic X?"). That's flexible — any labels, no retraining — but it costs one model run per label and isn't tuned to a fixed set.

  • Dedicated head: fixed labels · 1 pass · ~13 MB · calibrated probabilities.
  • Zero-shot: arbitrary labels · N passes (one per label) · larger model · no per-taxonomy tuning.

Rule of thumb: a stable taxonomy you classify constantly (a news desk, a support queue) wants a dedicated head; an ad-hoc or changing label set wants zero-shot.

Why it matters

Routing text by topic is the plumbing behind every content feed, newsroom CMS, and support desk. Doing it in the browser means you can categorise a stream the instant it arrives — no server round-trip, no per-call bill, and no article text leaving the device.

Use cases

Basics

Type a headline, get its topic + confidence, updating live as you type.

Practical

Paste a feed of headlines and watch them auto-sort onto newsroom desks.

Wild

Craft a cross-topic headline and watch the model get genuinely torn — an ambiguity meter.

Multi-model

Route an article to its desk, then summarise it with DistilBART — two models, one pipeline.

How the API works

Classification is one call; top_k returns the full distribution:

import { pipeline } from "@huggingface/transformers";

const classify = await pipeline(
  "text-classification",
  "tarekziade/topic_classification",
  { dtype: "q8" },
); // downloads + caches ~13 MB once

const out = await classify("The Fed raised interest rates.", { top_k: 10 });
// → [{ label: "Business & Finance", score: 0.99 }, { label: "Politics & Government", score: 0.96 }, … ]
// multi-label: each score is independent (a sigmoid), so they don't sum to 1.

Asking for top_k: 10 (the number of classes) returns every topic's score, sorted — that's what powers the bars. All of it runs in a Web Worker so typing never janks.

References