# 20 Newsgroups (1995)

> About 18,800 Usenet posts from 1993, sorted into 20 discussion groups.

Page: https://mralbu.github.io/ai-datasets/d/20-newsgroups

## Key facts

- Category: Text
- Task: Topic classification of Usenet posts
- Creators: Ken Lang
- Size: 18,846 posts (the "by date" version)
- Splits: train 11,314, test 7,532
- Input: The text of a newsgroup post
- Labels: One of 20 groups (comp.graphics, rec.autos, sci.space, talk.politics.guns, …)
- License: No formal license (public Usenet posts)
- Homepage: http://qwone.com/~jason/20Newsgroups/
- Hugging Face: [SetFit/20_newsgroups](https://huggingface.co/datasets/SetFit/20_newsgroups)
- Sampled at Hub revision f1b91292074e7cfb69be58b642d583ec262f30ed (2026-11-07)

## Why it matters

Probably collected for NewsWeeder, an early system that learned which posts a reader wanted, it became the classic text-classification and clustering dataset. Naive Bayes, tf-idf with SVMs and topic models like LDA were all demonstrated on it, and it ships with scikit-learn as fetch_20newsgroups, so it is still many people's first text dataset.

## Worth knowing

- Some groups are close cousins (five comp.* groups, three talk.politics.*), so the confusions are as instructive as the accuracy.
- Headers, signatures and quoted replies give the answer away. scikit-learn recommends removing them, and this copy has headers, signatures and quotes stripped.
- In the "by date" split, test posts were written after the training posts.

## Get the data

```bash
# pip install -U huggingface_hub
hf download SetFit/20_newsgroups --repo-type dataset \
  --local-dir 20-newsgroups
```

```python
from datasets import load_dataset   # pip install datasets

ds = load_dataset("SetFit/20_newsgroups")
print(ds)
```

```python
import polars as pl

df = pl.read_parquet("hf://datasets/SetFit/20_newsgroups@~parquet/default/test/*.parquet")
print(df.shape)
```

## Related datasets

- [Reuters-21578](https://archive.ics.uci.edu/dataset/137/reuters+21578+text+categorization+collection): 1987 newswire, the other classic
- [AG News](https://huggingface.co/datasets/fancyzhx/ag_news): 2015, 120k news articles in 4 topics
- [IMDB](https://huggingface.co/datasets/stanfordnlp/imdb): 2011, sentiment instead of topic (on this site: https://mralbu.github.io/ai-datasets/d/imdb)

## Landmark papers

- [A Comparison of Event Models for Naive Bayes Text Classification](https://www.cs.cmu.edu/~knigam/papers/multinomial-aaaiws98.pdf) (1998)
- [Latent Dirichlet Allocation](https://www.jmlr.org/papers/v3/blei03a.html) (2003)
