Views
No views yet
1import torch
2from transformers import AutoTokenizer
3from transformers import AutoModelForSequenceClassification
4
5
6model_id = "przvl/PopEuroBERT-binary-210m"
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8model = AutoModelForSequenceClassification.from_pretrained(
9 model_id, trust_remote_code=True
10)
11
12# define text to be predicted
13text = (
14 "Aber Ihnen fehlt eben der Mut, Ihnen fehlen die Visionen, um sich"
15 "gegen die Konzerne und gegen die Lobbygruppen zur Wehr zu setzen."
16)
17
18inputs = tokenizer(text, return_tensors="pt")
19outputs = model(**inputs)
20
21# get classification probability
22logits = outputs.logits
23probs = torch.softmax(logits, dim=-1) # shape [1, 2]
24populist_prob = probs[0, 1].item() # probability of class=1 (populist)
25
26# use decision threshold 0.56
27threshold = 0.56
28label = "Populist" if populist_prob > threshold else "Neutral"
29print(f"Predicted class: {label} (Confidence: {populist_prob:.2f})")Predicted class: Populist (Confidence: 0.90)0.56 for balanced performance.train/test: 7017/1758populist = 1, neutral = 0).256 tokens.| Parameter | Value |
|---|---|
| Learning Rate | 3e-05 |
| Weight Decay | 0.0 |
| Gradient Accumulation | 2 |
| Warmup Ratio | 0.1 |
| Epochs | 2 |
| Batch Size | 16 |
| Max Length | 256 |
| Model | Accuracy | Precision | Recall | F1 Score | Loss |
|---|---|---|---|---|---|
| 210M (this) | 75.99% | 73.78% | 80.66% | 77.07% | 0.4959 |
| 610M | 80.26% | 78.42% | 83.50% | 80.89% | 0.4631 |
| Model | Threshold | Accuracy | Precision | Recall | F1 Score |
|---|---|---|---|---|---|
| 210M (this) | 0.56 | 76.00% | 76.00% | 76.00% | 76.00% |
| 610M | 0.43 | 79.81% | 76.63% | 85.78% | 80.94% |
0.56) was optimized for this dataset but may need adjustment for other corpora.1@misc{boizard2025eurobertscalingmultilingualencoders,
2 title={EuroBERT: Scaling Multilingual Encoders for European Languages},
3 author={Nicolas Boizard and Hippolyte Gisserot-Boukhlef and Duarte M. Alves and André Martins and Ayoub Hammal and Caio Corro and Céline Hudelot and Emmanuel Malherbe and Etienne Malaboeuf and Fanny Jourdan and Gabriel Hautreux and João Alves and Kevin El-Haddad and Manuel Faysse and Maxime Peyrard and Nuno M. Guerreiro and Patrick Fernandes and Ricardo Rei and Pierre Colombo},
4 year={2025},
5 eprint={2503.05500},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2503.05500}
9}1@article{Erhard_Hanke_Remer_Falenska_Heiberger_2025,
2 title={PopBERT. Detecting Populism and Its Host Ideologies in the German Bundestag},
3 volume={33},
4 DOI={10.1017/pan.2024.12},
5 number={1},
6 journal={Political Analysis},
7 author={Erhard, Lukas and Hanke, Sara and Remer, Uwe and Falenska, Agnieszka and Heiberger, Raphael Heiko},
8 year={2025},
9 pages={1–17}
10}