A fine-tuned
DeBERTa-v3-base model for classifying the political bias of English-language news articles into three classes:
Left,
Center, and
Right.
This model takes a news article's title and body as input and predicts its political leaning on a three-point scale. It builds on microsoft/deberta-v3-base (86M parameters) by adding a sequence classification head trained with weighted cross-entropy loss to handle class imbalance.
The training corpus combines two publicly available datasets, both labeled using
AllSides media bias ratings:
All metrics are computed on temporally held-out data the model never saw during training.
The 8.2-point accuracy gap between validation and test reflects genuine temporal drift: the 2020 news landscape (dominated by COVID-19 and the US presidential election) introduced topics and framing not present in earlier training data.
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_id = "jurinho17-sv/news-article-bias-classifier"
5tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
6model = AutoModelForSequenceClassification.from_pretrained(model_id)
7model.eval()
8
9title = "Senate passes bipartisan infrastructure bill"
10content = "The US Senate voted 69-30 to pass a $1 trillion infrastructure package..."
11
12inputs = tokenizer(
13 title + " [SEP] " + content,
14 truncation=True,
15 max_length=512,
16 return_tensors="pt",
17)
18
19with torch.no_grad():
20 logits = model(**inputs).logits
21 probs = torch.softmax(logits, dim=-1)
22 pred_id = torch.argmax(probs, dim=-1).item()
23
24labels = {0: "Left", 1: "Center", 2: "Right"}
25print(f"Prediction: {labels[pred_id]} ({probs[0][pred_id]:.1%})")
1@inproceedings{baly-etal-2020-detect,
2 title = "We Can Detect Your Bias: Predicting the Political Ideology
3 of News Articles",
4 author = "Baly, Ramy and Da San Martino, Giovanni and Glass, James
5 and Nakov, Preslav",
6 booktitle = "Proceedings of the 2020 Conference on Empirical Methods
7 in Natural Language Processing (EMNLP)",
8 year = "2020",
9 publisher = "Association for Computational Linguistics",
10 pages = "4982--4991",
11}
12
13@inproceedings{haak-schaer-2023-qbias,
14 title = "Qbias -- A Dataset on Media Bias in Search Queries and
15 Query Suggestions",
16 author = "Haak, Fabian and Schaer, Philipp",
17 booktitle = "Proceedings of the 15th ACM Web Science Conference (WebSci)",
18 year = "2023",
19 publisher = "Association for Computing Machinery",
20}