AG News BERT Classifier

Fine-tuned :contentReference[oaicite:1]{index=1} model for 4-class news topic classification using the :contentReference[oaicite:2]{index=2} dataset.

The model classifies news articles into:

  • World
  • Sports
  • Business
  • Sci/Tech

Model Details

Property Value
Base Model bert-base-uncased
Task Text Classification
Framework PyTorch + Transformers
Dataset AG News
Classes 4
Test Accuracy 94.7%
Macro F1 0.94

Label Mapping

ID Label
0 World
1 Sports
2 Business
3 Sci/Tech

Training Configuration

Parameter Value
Epochs 3
Batch Size 16
Learning Rate 2e-5
Max Sequence Length 128
Warmup Steps 500
Optimizer AdamW
Weight Decay 0.01
LR Scheduler Linear Warmup + Linear Decay
Gradient Clipping Max Norm = 1.0

Dataset Information

Split Samples
Train 120,000
Test 7,600

Dataset source:

:contentReference[oaicite:3]{index=3}


Performance

Classification Report

Class Precision Recall F1-Score
World 0.97 0.95 0.96
Sports 0.98 0.99 0.99
Business 0.92 0.91 0.92
Sci/Tech 0.91 0.93 0.92

Usage

Install

pip install transformers torch

Inference

from transformers import pipeline

classifier = pipeline(
    "text-classification",
    model="theshekslaw/ag_news_bert_full"
)

result = classifier(
    "Apple announces new MacBook Pro with M3 chip"
)

print(result)

Example output:

[{'label': 'Sci/Tech', 'score': 0.9895}]

Example Predictions

Text Prediction
Apple announces new MacBook Pro with M3 chip Sci/Tech
Federal Reserve raises interest rates Business
UN calls for ceasefire in ongoing conflict World
Real Madrid wins Champions League final Sports

Training Approach

The model was fine-tuned using a custom PyTorch training loop instead of the Hugging Face Trainer API.

Key components:

  • Dynamic padding with DataCollatorWithPadding
  • Linear learning-rate scheduling
  • AdamW optimizer
  • Mixed precision training (FP16)
  • GPU training on NVIDIA T4

Limitations

  • The model is trained only on AG News categories.
  • It may struggle with:
    • ambiguous headlines
    • multi-topic articles
    • very short text
    • domain-specific financial or scientific jargon

Citation

@misc{ag_news_bert_classifier,
  title={AG News BERT Classifier},
  author={Abhishek Pandey},
  year={2026},
  publisher={Hugging Face}
}
Downloads last month
5
Safetensors
Model size
0.1B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train theshekslaw/ag_news_bert_full

Evaluation results