Views
No views yet
bert-base-uncased-agnews-classifierbert-base-uncased-agnews-classifierbert-base-uncasedbert-base-uncased model on the AG News dataset for news topic classification.
It classifies English news headlines or short articles into one of four categories: World, Sports, Business, and Science/Technology.bert-base-uncased| Metric | Score |
|---|---|
| Accuracy | 0.86 |
| F1 Score (macro) | 0.86 |
Replace the above with your actual evaluation metrics if available.
| Label ID | Category |
|---|---|
| 0 | World |
| 1 | Sports |
| 2 | Business |
| 3 | Science/Technology |
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_name = "your-username/bert-base-uncased-agnews-classifier"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
8text = "NASA launches new satellite to study climate change."
9inputs = tokenizer(text, return_tensors="pt")
10
11with torch.no_grad():
12 outputs = model(**inputs)
13 probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
14 predicted_label = torch.argmax(probabilities).item()
15
16labels = ["World", "Sports", "Business", "Science/Technology"]
17print(f"Predicted label: {labels[predicted_label]}")1@misc{yourname2025bertagnews,
2 title = {BERT-based AG News Classifier},
3 author = {Your Name},
4 year = {2025},
5 howpublished = {\url{https://huggingface.co/your-username/bert-base-uncased-agnews-classifier}},
6}