DistilBERT Text Classifier (MLOps Assignment 2)

Fine-tuned DistilBERT model for text classification.

What this model does

  • Input: a short text (news headline/article style text)
  • Output: one category label (4 classes for ag_news)

Model used

  • Base model: distilbert-base-uncased
  • Task: sequence classification
  • Framework: Hugging Face Transformers + Trainer

Training setup (smoke run)

  • Dataset: ag_news (quick test run for pipeline validation)
  • Train samples per class: 200
  • Epochs: 1
  • Batch size: 8 (train), 16 (eval)
  • Optimizer settings: lr=3e-5, warmup_steps=100, weight_decay=0.01
  • Experiment tracking: Weights & Biases (mlops-assignment2)

Final test results

Metric Score
Accuracy 0.87145
F1 (weighted) 0.86951
Eval Loss 0.46378

How to use

from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

model_name = "YOUR_USERNAME/distilbert-agnews-smoke"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

text = "Stock markets rose today after strong earnings reports."
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256)
with torch.no_grad():
    logits = model(**inputs).logits
pred_id = int(torch.argmax(logits, dim=-1))
print("Predicted class id:", pred_id)
Downloads last month
50
Safetensors
Model size
65.8M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train tejinder482/distilbert-goodreads-kaggle