1from transformers import RobertaForSequenceClassification, AutoTokenizer
2import torch
3
4# Load model and tokenizer
5model = RobertaForSequenceClassification.from_pretrained("alxdev/echocheck-political-stance")
6tokenizer = AutoTokenizer.from_pretrained("alxdev/echocheck-political-stance")
7
8# Move to GPU if available
9device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10model.to(device)
11model.eval()
12
13# Classify text
14text = "The government should increase social spending to support working families."
15inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512, padding=True)
16inputs = {k: v.to(device) for k, v in inputs.items()}
17
18with torch.no_grad():
19 outputs = model(**inputs)
20 probs = torch.softmax(outputs.logits, dim=-1)
21 prediction = probs.argmax().item()
22
23labels = {0: "center", 1: "left", 2: "right"}
24print(f"Prediction: {labels[prediction]}")
25print(f"Confidence: {probs[0][prediction]:.2%}")1from transformers import pipeline
2
3classifier = pipeline(
4 "text-classification",
5 model="alxdev/echocheck-political-stance",
6 device=0 # Use GPU, or -1 for CPU
7)
8
9result = classifier("Lower taxes will stimulate economic growth and job creation.")
10print(result)
11# [{'label': 'LABEL_2', 'score': 0.85}] # LABEL_2 = right| Label ID | Label Name | Description |
|---|---|---|
| 0 | center | Moderate/neutral political stance |
| 1 | left | Progressive political stance |
| 2 | right | Conservative political stance |
| Parameter | Value |
|---|---|
| Base Model | roberta-base |
| Optimizer | AdamW |
| Learning Rate | 2e-5 |
| Batch Size | 24 |
| Epochs | 3 |
| Warmup | 10% of total steps |
| Weight Decay | 0.01 |
| LR Schedule | Linear with warmup |
| Training Regime | FP32 |
| Loss Function | CrossEntropyLoss |
| Metric | Score |
|---|---|
| Accuracy | 95.50% |
| Macro F1 | 95.49% |
| Weighted F1 | 95.49% |
| Class | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| Center | 0.949 | 0.955 | 0.952 | 77,220 |
| Left | 0.953 | 0.964 | 0.959 | 77,951 |
| Right | 0.963 | 0.945 | 0.954 | 77,987 |
| Predicted Center | Predicted Left | Predicted Right | |
|---|---|---|---|
| Actual Center | 73,756 | 1,890 | 1,574 |
| Actual Left | 1,543 | 75,164 | 1,244 |
| Actual Right | 2,426 | 1,826 | 73,735 |
1@misc{morariu2026echocheck,
2 author = {Morariu, Alexandru-Gabriel},
3 title = {EchoCheck: Political Stance and Ideology Classification using NLP Techniques},
4 year = {2026},
5 publisher = {HuggingFace},
6 howpublished = {\url{https://huggingface.co/alxdev/echocheck-political-stance}},
7 note = {Bachelor's Thesis, "Titu Maiorescu" University}
8}