Views
No views yet
transformers1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_id = "durrani95/eurobert-geopolitical-multiclass"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForSequenceClassification.from_pretrained(model_id)
8
9
10texts = [
11 "Russia cut off gas supplies to Europe amid rising tensions.",
12 "Terrorist activity has increased along the southern border.",
13 "New sanctions were imposed on financial institutions.",
14 "Talks at the UN Security Council failed to reach consensus.",
15 "Tarrifs on soybeans are applied to pressure China into a deal with the US" ,
16 "Tom and Jerry have a fight! The mouse finally had enough.",
17]
18
19inputs = tokenizer(texts, padding=True, truncation=True, max_length=512, return_tensors="pt")
20
21with torch.no_grad():
22 logits = model(**inputs).logits
23 probs = torch.softmax(logits, dim=1)
24
25for text, p in zip(texts, probs):
26 label_id = int(p.argmax())
27 label = model.config.id2label[label_id]
28 confidence = float(p[label_id])
29 print(f"{label:>28} {confidence:6.2%} | {text}")| Category | Description | Example |
|---|---|---|
| war_military_conflict | Armed conflicts, military operations, or war-related issues involving states or armed groups. | Russia’s invasion of Ukraine |
| terrorism_insurgency | Terrorist attacks, counter-terrorism operations, or insurgent activity. | 9/11 attacks |
| cyber_warfare | Cyberattacks or hacking by foreign states or international actors with strategic motives. | North Korea’s Sony hack |
| trade_disputes | Tensions between states over trade policy, tariffs, or retaliation. | U.S.–China trade wars |
| financial_sanctions | Economic penalties imposed by countries against targeted states, entities, or individuals. | U.S. sanctions on Iran’s banking sector |
| regional_disintegration | Political developments that threaten the cohesion of existing regional entities. | Brexit |
| energy_resource_conflicts | Disputes over energy access, distribution, or natural resource control. | OPEC oil disputes |
| global_governance | Tensions involving international institutions or multilateral diplomacy. | NATO expansion |
| nuclear_proliferation | Issues concerning the spread or control of nuclear weapons. | Iran nuclear deal |
| territorial_disputes | Conflicts over land or maritime boundaries. | South China Sea tensions |
| non_geopol | Texts without geopolitical relevance. | Domestic politics or economic updates |
EuroBERT/EuroBERT-210m| Parameter | Value |
|---|---|
| Learning rate | 3e-5 |
| Desired (effective) batch size | 64 |
| Actual GPU batch size | 16 |
| Gradient accumulation | 4 steps |
| Weight decay | 1e-5 |
| Betas | (0.9, 0.95) |
| Epsilon | 1e-8 |
| Max epochs | 1 |