Download README.md from szhuggingface/ag_news: direct link, hf CLI and curl.
- Browser
- Download file 9.94 kB
-
https://huggingface.co/datasets/szhuggingface/ag_news/resolve/main/README.md
- Command line
-
hf download hf://datasets/szhuggingface/ag_news/README.md
-
curl -L -o README.md https://huggingface.co/datasets/szhuggingface/ag_news/resolve/main/README.md
dataset_info:
features:
- name: text
dtype: string
- name: label
dtype:
class_label:
names:
'0': World
'1': Sports
'2': Business
'3': Sci/Tech
splits:
- name: test
num_bytes: 1879474
num_examples: 7600
- name: val_full
num_bytes: 5963460.6
num_examples: 24000
- name: val1
num_bytes: 2981730.3
num_examples: 12000
- name: val2
num_bytes: 2981730.3
num_examples: 12000
- name: train_full
num_bytes: 23853842.4
num_examples: 96000
- name: train_1_48k
num_bytes: 11926921.2
num_examples: 48000
- name: train_1_24k
num_bytes: 5963460.6
num_examples: 24000
- name: train_1_12k
num_bytes: 2981730.3
num_examples: 12000
- name: train_1_6k
num_bytes: 1490865.15
num_examples: 6000
- name: train_1_3k
num_bytes: 745432.575
num_examples: 3000
- name: train_1_1.5k
num_bytes: 372716.2875
num_examples: 1500
download_size: 41027925
dataset_size: 61141363.7125
configs:
- config_name: default
data_files:
- split: test
path: data/test-*
- split: val_full
path: data/val_full-*
- split: val1
path: data/val1-*
- split: val2
path: data/val2-*
- split: train_full
path: data/train_full-*
- split: train_1_48k
path: data/train_1_48k-*
- split: train_1_24k
path: data/train_1_24k-*
- split: train_1_12k
path: data/train_1_12k-*
- split: train_1_6k
path: data/train_1_6k-*
- split: train_1_3k
path: data/train_1_3k-*
- split: train_1_1.5k
path: data/train_1_1.5k-*
pretty_name: Stratified and Nested Subsets of AG News for Benchmarking
tags:
- ag_news
- text-classification
- stratified-sampling
- low-resource
- benchmarking
license: apache-2.0
Stratified and Nested Subsets of AG News for Performance Benchmarking
Dataset Summary
This repository contains a script to generate stratified and progressively smaller, nested subsets of the AG News dataset. It was specifically designed to benchmark the performance (e.g., accuracy, training time, and resource usage) of language models on varying amounts of training data.
This new version improves the benchmarking process by:
- Preserving the Original Test Set: It uses the original
ag_newstest set for final, unbiased evaluation. - Creating Dedicated Validation Sets: It carves out multiple validation sets (
val_full,val1,val2) from the original training data, allowing for robust hyperparameter tuning without touching the test set.
By using stratified samples, each subset maintains the original class distribution of the AG News dataset. This ensures that performance differences can be more reliably attributed to dataset size rather than class imbalance. The training splits are nested, meaning train_1_1.5k is a perfect subset of train_1_3k, which is a subset of train_1_6k, and so on.
Supported Tasks and Leaderboards
text-classification: The dataset is ideal for training models for news topic classification. The four classes are: World (0), Sports (1), Business (2), and Sci/Tech (3).
Dataset Structure
The dataset generation script creates multiple splits organized into three categories: training, validation, and testing.
- The
testsplit is the original, untouched test set from theag_newsdataset. - The
validationsplits are derived from 20% of the originalag_newstraining data. - The
trainingsplits are progressively smaller, nested subsets derived from the remaining 80% of the originalag_newstraining data.
| Category | Split Name | Number of Samples | Description |
|---|---|---|---|
| Test | test |
7,600 | The original ag_news test set. Use for final evaluation. |
| Validation | val_full |
24,000 | 20% of the original training data. |
val1 |
12,000 | A 50% split of val_full. |
|
val2 |
12,000 | The other 50% split of val_full. |
|
| Training | train_full |
96,000 | 80% of the original training data (full training set). |
train_1_48k |
48,000 | 1/2 of train_full. |
|
train_1_24k |
24,000 | 1/4 of train_full. |
|
train_1_12k |
12,000 | 1/8 of train_full. |
|
train_1_6k |
6,000 | 1/16 of train_full. |
|
train_1_3k |
3,000 | 1/32 of train_full. |
|
train_1_1.5k |
1,500 | 1/64 of train_full. |
Data Fields
text: astringfeature containing the news article content.label: a classification label, with possible values includingWorld(0),Sports(1),Business(2),Sci/Tech(3).
How to Use
You can load the dataset using the datasets library with a single line of code:
from datasets import load_dataset
repo_name = "szhuggingface/ag_news"
dataset = load_dataset(repo_name)
# You can now access any split
print("Medium training set:")
print(dataset['train_1_6k'])
print("\nTest set:")
print(dataset['test'])
Instead of loading pre-made splits from the Hub, this repository provides a script to generate the datasets locally. This ensures transparency and allows for easy modification of the splitting parameters (like random_state).
Save the code below as a Python file (e.g., create_splits.py) and run it.
import pandas as pd
from datasets import load_dataset, DatasetDict
def create_stratified_splits(
dataset_name="ag_news",
label_col="label",
validation_size=0.2,
random_state=42
):
"""
Loads the ag_news train and test splits. It creates multiple validation
and training sets for benchmarking purposes.
- The final 'test' set is the original ag_news test set.
- Validation sets ('val_full', 'val1', 'val2') are derived from the original train set.
- Training sets are nested, stratified subsets of the remaining training data.
Args:
dataset_name (str): The name of the dataset on the Hugging Face Hub.
label_col (str): The name of the column to stratify by.
validation_size (float): The proportion of the original train set to use for validation.
random_state (int): The seed for random operations to ensure reproducibility.
Returns:
DatasetDict: A dictionary containing all the created dataset splits.
"""
print(f"▶️ Loading original '{dataset_name}' train and test splits...")
original_train_ds = load_dataset(dataset_name, split='train')
original_test_ds = load_dataset(dataset_name, split='test')
# 1. Create the main Train/Validation stratified split from the ORIGINAL TRAIN data
print(f"\nSplitting original training data into a main training set ({1-validation_size:.0%}) and a full validation set ({validation_size:.0%})...")
main_splits = original_train_ds.train_test_split(
test_size=validation_size,
stratify_by_column=label_col,
seed=random_state
)
train_full = main_splits['train']
val_full = main_splits['test']
# 2. Split the full validation set into two halves
print("Creating two validation splits (val1, val2) from the full validation set...")
val_splits = val_full.train_test_split(
test_size=0.5,
stratify_by_column=label_col,
seed=random_state
)
val1 = val_splits['train']
val2 = val_splits['test']
# 3. Create nested, growing subsets from the main training data
print("Creating nested training subsets...")
train_1_48k = train_full.train_test_split(train_size=0.5, stratify_by_column=label_col, seed=random_state)['train']
train_1_24k = train_1_48k.train_test_split(train_size=0.5, stratify_by_column=label_col, seed=random_state)['train']
train_1_12k = train_1_24k.train_test_split(train_size=0.5, stratify_by_column=label_col, seed=random_state)['train']
train_1_6k = train_1_12k.train_test_split(train_size=0.5, stratify_by_column=label_col, seed=random_state)['train']
train_1_3k = train_1_6k.train_test_split(train_size=0.5, stratify_by_column=label_col, seed=random_state)['train']
train_1_1_5k = train_1_3k.train_test_split(train_size=0.5, stratify_by_column=label_col, seed=random_state)['train']
# 4. Consolidate all splits into a single DatasetDict
final_datasets = DatasetDict({
'test': original_test_ds,
'val_full': val_full,
'val1': val1,
'val2': val2,
'train_full': train_full,
'train_1_48k': train_1_48k,
'train_1_24k': train_1_24k,
'train_1_12k': train_1_12k,
'train_1_6k': train_1_6k,
'train_1_3k': train_1_3k,
'train_1_1.5k': train_1_1_5k
})
print("\n--- ✅ Final Dataset Statistics ---")
for name, ds in final_datasets.items():
print(f"\nDataset Split: '{name}' | Total samples: {len(ds):,}")
return final_datasets
Citation 📜
If you use this dataset in your work, please cite the original paper:
@inproceedings{zhang2015character,
title={Character-level convolutional networks for text classification},
author={Zhang, Xiang and Zhao, Junbo and LeCun, Yann},
booktitle={Advances in neural information processing systems},
pages={649--657},
year={2015}
}