Fine-tuning
bert-base-uncased on the
AG News dataset for 4-class news headline classification.
Given a news headline and its article body, classify it into one of four categories:
1from transformers import pipeline
2
3clf = pipeline("text-classification", model="Alfiob12/agnews-bert")
4clf("NVIDIA announces production of groundbreaking quantum GPUs")
5# [{'label': 'Sci/Tech', 'score': 0.961}]
Evaluated on a held-out test set of 19,140 samples (15% of the full dataset).
The notebook
AG _news_Classification.ipynb contains the full pipeline: data loading, tokenization, training, evaluation, and inference.
The original train/test CSV files are merged (127,600 samples) and re-split to create a validation set:
Splits are stratified by class. The dataset is perfectly balanced (equal samples per class).
1git clone https://github.com/alfiobonanno/AGNews-Bert-Tester-App.git
2cd AGNews-Bert-Tester-App
3python -m venv venv
4source venv/bin/activate # macOS/Linux
5# venv\Scripts\activate # Windows
6pip install -r requirements.txt
The dataset CSVs are included in
ag_data/. Then open and run
AG _news_Classification.ipynb.
See
requirements.txt for the full list. Key packages: