Fine-tuned
DistilBERT for 4-class English news article classification on the
AG News dataset.
1from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
2
3model_name = "YuvarajK-g25ait2054/ag-news-distilbert"
4
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
8classifier = pipeline(
9 "text-classification",
10 model=model,
11 tokenizer=tokenizer,
12 top_k=None
13)
14
15text = "The stock market rallied today as tech companies reported strong earnings."
16results = classifier(text)
17print(results)
18# [{'label': 'LABEL_2', 'score': 0.97}, ...] -> Business
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_name = "YuvarajK-g25ait2054/ag-news-distilbert"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
8text = "NASA launches new Mars exploration mission next spring."
9inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
10
11with torch.no_grad():
12 outputs = model(**inputs)
13 predicted_class = outputs.logits.argmax(-1).item()
14
15id2label = {0: "World", 1: "Sports", 2: "Business", 3: "Sci/Tech"}
16print(f"Category: {id2label[predicted_class]}")
17# Category: Sci/Tech
1docker pull yuvarajkg25ait2054/ag-news-classifier:latest
2
3docker run --rm yuvarajkg25ait2054/ag-news-classifier:latest \
4 --text "NASA launches new Mars exploration mission." \
5 --model "YuvarajK-g25ait2054/ag-news-distilbert"
Classify English news headlines/articles into one of four categories: World, Sports, Business, Sci/Tech.
1@misc{ag-news-distilbert-2026,
2 author = {Kosuru, Yuvaraj},
3 title = {AG News Text Classification with DistilBERT},
4 year = {2026},
5 publisher = {HuggingFace},
6 howpublished = {\url{https://huggingface.co/YuvarajK-g25ait2054/ag-news-distilbert}}
7}
Yuvaraj Kosuru —
g25ait2054@iitj.ac.in
IIT Jodhpur · MLOps Assignment · Group 13