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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FLAME2 — Financial Language Analysis for Multilingual Economics v2
|
| 2 |
+
|
| 3 |
+
**One model. Ten languages. 150,000 headlines. Perspective-aware financial sentiment.**
|
| 4 |
+
|
| 5 |
+
FLAME2 is a multilingual financial sentiment classifier that labels news headlines as **Negative**, **Neutral**, or **Positive** — but unlike other models, it does this from the **local investor's perspective** of each economy.
|
| 6 |
+
|
| 7 |
+
The same news can mean opposite things for different markets:
|
| 8 |
+
- *"Oil prices fall to $65/barrel"* → **Negative** for Arab markets (oil exporter) / **Positive** for India (oil importer)
|
| 9 |
+
- *"Yen weakens to 155 per dollar"* → **Positive** for Japan (helps exporters) / **Neutral** elsewhere
|
| 10 |
+
|
| 11 |
+
No other public model does this.
|
| 12 |
+
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
## Key Numbers
|
| 16 |
+
|
| 17 |
+
| | |
|
| 18 |
+
|---|---|
|
| 19 |
+
| **Languages** | 10 (Arabic, German, English, Spanish, French, Hindi, Japanese, Korean, Portuguese, Chinese) |
|
| 20 |
+
| **Training data** | 149,481 perspective-labeled financial headlines |
|
| 21 |
+
| **Base model** | XLM-RoBERTa-large (560M parameters) |
|
| 22 |
+
| **Labels** | Negative / Neutral / Positive |
|
| 23 |
+
| **Accuracy** | **84.11%** |
|
| 24 |
+
| **F1 (macro)** | **84.20%** |
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## Quick Start
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
from transformers import pipeline
|
| 32 |
+
|
| 33 |
+
classifier = pipeline("text-classification", model="Kenpache/flame2")
|
| 34 |
+
|
| 35 |
+
# English — US investor perspective
|
| 36 |
+
classifier("[EN] Apple reported record quarterly revenue of $124 billion")
|
| 37 |
+
# [{'label': 'positive', 'score': 0.96}]
|
| 38 |
+
|
| 39 |
+
# Arabic — Gulf investor perspective
|
| 40 |
+
classifier("[AR] أسعار النفط تنخفض إلى 65 دولارا للبرميل")
|
| 41 |
+
# [{'label': 'negative', 'score': 0.93}] (oil down = bad for exporters)
|
| 42 |
+
|
| 43 |
+
# Hindi — Indian investor perspective
|
| 44 |
+
classifier("[HI] तेल की कीमतें गिरकर 65 डॉलर प्रति बैरल हुईं")
|
| 45 |
+
# [{'label': 'positive', 'score': 0.91}] (oil down = good for importers)
|
| 46 |
+
|
| 47 |
+
# Japanese
|
| 48 |
+
classifier("[JA] 日経平均株価が大幅下落、米中貿易摩擦の懸念で")
|
| 49 |
+
# [{'label': 'negative', 'score': 0.94}]
|
| 50 |
+
|
| 51 |
+
# Korean
|
| 52 |
+
classifier("[KO] 삼성전자 실적 호조에 코스피 상승")
|
| 53 |
+
# [{'label': 'positive', 'score': 0.92}]
|
| 54 |
+
|
| 55 |
+
# Chinese
|
| 56 |
+
classifier("[ZH] 中国央行降息50个基点,股市应声上涨")
|
| 57 |
+
# [{'label': 'positive', 'score': 0.95}]
|
| 58 |
+
|
| 59 |
+
# German
|
| 60 |
+
classifier("[DE] DAX erreicht neues Allzeithoch dank starker Bankenergebnisse")
|
| 61 |
+
# [{'label': 'positive', 'score': 0.93}]
|
| 62 |
+
|
| 63 |
+
# French
|
| 64 |
+
classifier("[FR] La Bourse de Paris chute de 3% après les tensions commerciales")
|
| 65 |
+
# [{'label': 'negative', 'score': 0.91}]
|
| 66 |
+
|
| 67 |
+
# Spanish
|
| 68 |
+
classifier("[ES] El beneficio neto de la compañía creció un 25% interanual")
|
| 69 |
+
# [{'label': 'positive', 'score': 0.94}]
|
| 70 |
+
|
| 71 |
+
# Portuguese
|
| 72 |
+
classifier("[PT] Ibovespa fecha em alta com otimismo sobre reforma tributária")
|
| 73 |
+
# [{'label': 'positive', 'score': 0.90}]
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
**Important:** Always use the `[LANG]` prefix (`[EN]`, `[AR]`, `[HI]`, `[JA]`, etc.) — this tells the model which market perspective to apply.
|
| 77 |
+
|
| 78 |
+
---
|
| 79 |
+
|
| 80 |
+
## Supported Languages & Training Data
|
| 81 |
+
|
| 82 |
+
| Language | Code | Primary Economy | Oil Role | Total | Negative | Neutral | Positive |
|
| 83 |
+
|---|---|---|---|---|---|---|---|
|
| 84 |
+
| Arabic | AR | Gulf States (Saudi, UAE) | Exporter | 14,481 | 2,812 (19.4%) | 6,156 (42.5%) | 5,513 (38.1%) |
|
| 85 |
+
| German | DE | Germany / Eurozone | Importer | 15,000 | 3,544 (23.6%) | 6,636 (44.2%) | 4,820 (32.1%) |
|
| 86 |
+
| English | EN | United States | Mixed | 15,000 | 3,088 (20.6%) | 7,649 (51.0%) | 4,263 (28.4%) |
|
| 87 |
+
| Spanish | ES | Spain / Latin America | Importer | 15,000 | 3,872 (25.8%) | 5,616 (37.4%) | 5,512 (36.7%) |
|
| 88 |
+
| French | FR | France / Eurozone | Importer | 15,000 | 3,218 (21.5%) | 6,252 (41.7%) | 4,530 (30.2%) |
|
| 89 |
+
| Hindi | HI | India | Importer | 15,000 | 3,543 (23.6%) | 5,902 (39.3%) | 5,555 (37.0%) |
|
| 90 |
+
| Japanese | JA | Japan | Importer | 15,000 | 3,472 (23.1%) | 5,897 (39.3%) | 5,631 (37.5%) |
|
| 91 |
+
| Korean | KO | South Korea | Importer | 15,000 | 3,290 (21.9%) | 6,648 (44.3%) | 5,062 (33.7%) |
|
| 92 |
+
| Portuguese | PT | Brazil / Portugal | Exporter | 15,000 | 3,170 (21.1%) | 7,463 (49.8%) | 4,367 (29.1%) |
|
| 93 |
+
| Chinese | ZH | China | Importer | 15,000 | 3,542 (23.6%) | 4,055 (27.0%) | 7,403 (49.4%) |
|
| 94 |
+
|
| 95 |
+
**Total: 149,481 labeled headlines across 10 languages.**
|
| 96 |
+
|
| 97 |
+
### Overall Class Distribution
|
| 98 |
+
|
| 99 |
+
| Class | Samples | Share |
|
| 100 |
+
|---|---|---|
|
| 101 |
+
| **Negative** | 33,551 | 22.4% |
|
| 102 |
+
| **Neutral** | 62,274 | 41.7% |
|
| 103 |
+
| **Positive** | 52,656 | 35.2% |
|
| 104 |
+
|
| 105 |
+
Data sources include financial news sites, stock market reports, and economic news agencies — labeled with perspective-aware rules specific to each economy.
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
## What Makes FLAME2 Different
|
| 110 |
+
|
| 111 |
+
### The Problem
|
| 112 |
+
|
| 113 |
+
Existing financial sentiment models treat sentiment as universal. But financial sentiment is **not** universal — it depends on **where you are**:
|
| 114 |
+
|
| 115 |
+
- Oil prices drop? Bad for Saudi Arabia, great for India.
|
| 116 |
+
- Yen weakens? Good for Japanese exporters, bad for Korean competitors.
|
| 117 |
+
- Fed raises rates? Bad for US stocks, often neutral for European markets.
|
| 118 |
+
|
| 119 |
+
### Our Solution: Perspective-Aware Labels
|
| 120 |
+
|
| 121 |
+
Every headline in our dataset was labeled from the perspective of a **local investor** in that language's primary economy. The model learns that `[AR]` means "Gulf investor" and `[HI]` means "Indian investor."
|
| 122 |
+
|
| 123 |
+
#### Oil Price Rules
|
| 124 |
+
|
| 125 |
+
| Market Type | Oil Price Falls | Oil Price Rises | OPEC+ Output Increase |
|
| 126 |
+
|---|---|---|---|
|
| 127 |
+
| **Exporters** (AR, PT) | Negative | Positive | Negative |
|
| 128 |
+
| **Importers** (HI, KO, DE, FR, ES, JA, ZH) | Positive | Negative | Positive |
|
| 129 |
+
| **Mixed** (EN/US) | Positive | Context-dependent | Positive |
|
| 130 |
+
|
| 131 |
+
#### Currency Rules
|
| 132 |
+
|
| 133 |
+
| Language | Local Currency Strengthens | Local Currency Weakens |
|
| 134 |
+
|---|---|---|
|
| 135 |
+
| AR, PT, HI, KO, ZH | Positive | Negative |
|
| 136 |
+
| JA (export-driven) | Negative (hurts exporters) | Positive (helps exporters) |
|
| 137 |
+
| EN, DE, FR, ES | Neutral | Neutral |
|
| 138 |
+
|
| 139 |
+
#### Central Bank Rules
|
| 140 |
+
|
| 141 |
+
- **Home** central bank: rate cut = Positive, rate hike = Negative, hold = Neutral
|
| 142 |
+
- **Foreign** central bank: Neutral (unless headline explicitly links to local market impact)
|
| 143 |
+
|
| 144 |
+
---
|
| 145 |
+
|
| 146 |
+
## Labels
|
| 147 |
+
|
| 148 |
+
| Label | ID | Examples |
|
| 149 |
+
|---|---|---|
|
| 150 |
+
| **negative** | 0 | Stock decline, losses, layoffs, downgrades, sanctions, bankruptcy |
|
| 151 |
+
| **neutral** | 1 | Factual reporting, mixed signals, foreign data without local impact |
|
| 152 |
+
| **positive** | 2 | Revenue growth, market rally, upgrades, new launches, rate cuts |
|
| 153 |
+
|
| 154 |
+
---
|
| 155 |
+
|
| 156 |
+
## Results
|
| 157 |
+
|
| 158 |
+
### Overall
|
| 159 |
+
|
| 160 |
+
| Metric | Score |
|
| 161 |
+
|---|---|
|
| 162 |
+
| **Accuracy** | **84.11%** |
|
| 163 |
+
| **F1 (macro)** | **84.20%** |
|
| 164 |
+
|
| 165 |
+
### Per-Language Performance
|
| 166 |
+
|
| 167 |
+
| Language | Code | Accuracy | F1 Macro | Test Samples |
|
| 168 |
+
|---|---|---|---|---|
|
| 169 |
+
| Hindi | HI | 89.33% | 89.15% | 1,125 |
|
| 170 |
+
| Spanish | ES | 85.44% | 85.31% | 1,573 |
|
| 171 |
+
| Japanese | JA | 84.42% | 84.23% | 1,489 |
|
| 172 |
+
| French | FR | 84.06% | 84.24% | 2,579 |
|
| 173 |
+
| English | EN | 83.84% | 83.74% | 1,875 |
|
| 174 |
+
| Korean | KO | 83.54% | 83.71% | 3,280 |
|
| 175 |
+
| German | DE | 83.56% | 83.96% | 1,928 |
|
| 176 |
+
| Chinese | ZH | 83.50% | 81.43% | 1,751 |
|
| 177 |
+
| Portuguese | PT | 83.28% | 82.95% | 1,639 |
|
| 178 |
+
| Arabic | AR | 83.18% | 83.26% | 2,569 |
|
| 179 |
+
|
| 180 |
+
### Per-Class Performance
|
| 181 |
+
|
| 182 |
+
| Class | Precision | Recall | F1 | Support |
|
| 183 |
+
|---|---|---|---|---|
|
| 184 |
+
| Negative | 0.81 | 0.87 | 0.84 | 4,487 |
|
| 185 |
+
| Neutral | 0.86 | 0.78 | 0.82 | 8,398 |
|
| 186 |
+
| Positive | 0.84 | 0.90 | 0.87 | 6,923 |
|
| 187 |
+
|
| 188 |
+
---
|
| 189 |
+
|
| 190 |
+
## Training Pipeline
|
| 191 |
+
|
| 192 |
+
FLAME2 was built in two stages:
|
| 193 |
+
|
| 194 |
+
### Stage 1: Supervised Fine-Tuning
|
| 195 |
+
|
| 196 |
+
XLM-RoBERTa-large was fine-tuned on ~150,000 perspective-labeled headlines with:
|
| 197 |
+
- **Focal Loss** (gamma=2.0) — focuses training on hard, misclassified examples instead of easy ones
|
| 198 |
+
- **Class weights** to handle label imbalance across languages
|
| 199 |
+
- **Label smoothing** (0.1) to handle ~3-5% annotation noise
|
| 200 |
+
- **Language prefix** `[LANG]` injected before each headline for perspective routing
|
| 201 |
+
- **GroupShuffleSplit** by news source domain — no article from the same source appears in both train and test (prevents data leakage)
|
| 202 |
+
- **Gradient clipping** (max_norm=1.0) for training stability
|
| 203 |
+
|
| 204 |
+
### Stage 2: Live Stochastic Weight Averaging (SWA)
|
| 205 |
+
|
| 206 |
+
After epoch 12, the learning rate switches to a constant low rate (1e-5) and an `AveragedModel` maintains a running average of weights updated every epoch. This produces smoother, more generalizable predictions than any single checkpoint.
|
| 207 |
+
|
| 208 |
+
### Training Details
|
| 209 |
+
|
| 210 |
+
| Parameter | Value |
|
| 211 |
+
|---|---|
|
| 212 |
+
| Base model | xlm-roberta-large (560M params) |
|
| 213 |
+
| Fine-tuning data | ~150,000 labeled headlines |
|
| 214 |
+
| Languages | 10 |
|
| 215 |
+
| Loss function | Focal Loss (gamma=2.0) |
|
| 216 |
+
| Learning rate | 2e-5 (→ 1e-5 SWA phase) |
|
| 217 |
+
| Label smoothing | 0.1 |
|
| 218 |
+
| Batch size | 32 |
|
| 219 |
+
| Max sequence length | 128 tokens |
|
| 220 |
+
| Precision | FP16 (mixed precision) |
|
| 221 |
+
| Train/Val/Test split | 70% / 15% / 15% |
|
| 222 |
+
| Split strategy | GroupShuffleSplit by source domain |
|
| 223 |
+
| SWA | Live averaging from epoch 12 |
|
| 224 |
+
|
| 225 |
+
---
|
| 226 |
+
|
| 227 |
+
## Batch Processing
|
| 228 |
+
|
| 229 |
+
```python
|
| 230 |
+
from transformers import pipeline
|
| 231 |
+
|
| 232 |
+
classifier = pipeline("text-classification", model="Kenpache/flame2", device=0)
|
| 233 |
+
|
| 234 |
+
texts = [
|
| 235 |
+
"[EN] Stocks rallied after the Fed signaled a pause in rate hikes.",
|
| 236 |
+
"[EN] The company filed for Chapter 11 bankruptcy protection.",
|
| 237 |
+
"[DE] DAX erreicht neues Allzeithoch dank starker Bankenergebnisse",
|
| 238 |
+
"[FR] La Bourse de Paris chute de 3% après les tensions commerciales",
|
| 239 |
+
"[ES] El beneficio neto de la compañía creció un 25% interanual",
|
| 240 |
+
"[ZH] 中国央行降息50个基点,股市应声上涨",
|
| 241 |
+
"[PT] Ibovespa fecha em alta com otimismo sobre reforma tributária",
|
| 242 |
+
"[AR] ارتفاع مؤشر السوق السعودي بنسبة 2% بعد إعلان أرباح أرامكو",
|
| 243 |
+
"[HI] भारतीय रिजर्व बैंक ने रेपो रेट में 25 बीपीएस की कटौती की",
|
| 244 |
+
"[JA] トヨタ自動車の純利益が前年比30%増加",
|
| 245 |
+
"[KO] 삼성전자 실적 호조에 코스피 상승",
|
| 246 |
+
]
|
| 247 |
+
|
| 248 |
+
results = classifier(texts, batch_size=32)
|
| 249 |
+
for text, result in zip(texts, results):
|
| 250 |
+
print(f"{result['label']:>8} ({result['score']:.2f}) {text[:70]}")
|
| 251 |
+
```
|
| 252 |
+
|
| 253 |
+
---
|
| 254 |
+
|
| 255 |
+
## Use Cases
|
| 256 |
+
|
| 257 |
+
- **Global News Monitoring** — real-time sentiment classification across 10 markets
|
| 258 |
+
- **Algorithmic Trading** — perspective-aware signals: same event, different trades per market
|
| 259 |
+
- **Portfolio Risk Management** — track sentiment shifts across international holdings
|
| 260 |
+
- **Cross-Market Arbitrage** — detect when markets react differently to the same news
|
| 261 |
+
- **Financial NLP Research** — first multilingual perspective-aware sentiment benchmark
|
| 262 |
+
|
| 263 |
+
---
|
| 264 |
+
|
| 265 |
+
## Limitations
|
| 266 |
+
|
| 267 |
+
- Optimized for **news headlines** (short text, 1-2 sentences). May underperform on long articles or social media.
|
| 268 |
+
- Perspective rules cover major economic patterns (oil, currency, central banks). Niche sector-specific effects may not be captured.
|
| 269 |
+
- Labels reflect the perspective of the **primary economy** for each language (e.g., AR = Gulf States, not all Arabic-speaking countries).
|
| 270 |
+
|
| 271 |
+
---
|
| 272 |
+
|
| 273 |
+
## Citation
|
| 274 |
+
|
| 275 |
+
```bibtex
|
| 276 |
+
@misc{flame2_2026,
|
| 277 |
+
title={FLAME2: Financial Language Analysis for Multilingual Economics v2},
|
| 278 |
+
author={Kenpache},
|
| 279 |
+
year={2026},
|
| 280 |
+
url={https://huggingface.co/Kenpache/flame2}
|
| 281 |
+
}
|
| 282 |
+
```
|
| 283 |
+
|
| 284 |
+
## License
|
| 285 |
+
|
| 286 |
+
Apache 2.0
|