Xlm Roberta Large Sdg Classification 2024 04
Model description
Multilingual sequence classification model fine-tuned from XLM-RoBERTa-large to predict UN Sustainable Development Goal (SDG) labels (sdg1–sdg16) from text passages.
- Task: single-label text classification
- Classes: 16 SDG labels (no SDG 17)
- Fine-tuned from:
FacebookAI/xlm-roberta-large - Selection metric: F1 macro (best checkpoint)
Intended uses & limitations
Intended uses
- Tagging policy documents, research abstracts, and project descriptions with primary SDG labels
- Multilingual SDG classification pipelines (OSDG-style text)
- Research and internal analytics on sustainability-related corpora
Out-of-scope uses
- Legal or compliance decisions without human review
- High-stakes allocation of funds based solely on model predictions
- SDG 17 classification (not supported by this label set)
Limitations
- Trained on OSDG-CD derived data; performance may drop on very different domains (social media, short snippets, etc.)
- Class imbalance (~5× between most/least frequent SDG); rare SDGs may underperform
- Evaluation in this run used the dataset test split as validation during training
- Does not provide confidence calibration or multi-label SDG assignment
Training and evaluation data
Dataset
- Hub: albertmartinez/OSDG
- Config:
2024-04-01(latest subset) - Train split: 34,420 examples
- Test split: 8,605 examples (used for evaluation each epoch)
- Input column:
text - Label column:
label(sdg1…sdg16)
Preprocessing
- Tokenizer: XLM-RoBERTa (
max_seq_length=512) - Class weights applied to cross-entropy loss (inverse frequency, normalized)
- Train shuffle: enabled
Training procedure
Framework
Fine-tuning with Hugging Face Transformers Trainer, using the official run_classification.py script (project fork with class-weight support).
Training
- Optimizer: AdamW (Trainer default)
- Precision: bf16 on NVIDIA GPU
- Best checkpoint selected by eval F1 macro (
load_best_model_at_end=True)
Training hyperparameters
| Parameter | Value |
|---|---|
| Base model | FacebookAI/xlm-roberta-large |
| Epochs (max) | 8.0 |
| Batch size / device (train) | 64 |
| Batch size / device (eval) | 64 |
| Gradient accumulation | 1 |
| Learning rate | 2e-05 |
| Weight decay | 0.01 |
| Warmup ratio | 0.1 |
| Max sequence length | 512 |
| Seed | 42 |
| BF16 | True |
| TF32 | True |
| Loss | Cross-entropy + class weights |
| Metric | F1 macro |
Training results
Final metrics (best checkpoint)
| Metric | Value |
|---|---|
| Eval F1 macro | 0.8066 |
| Eval loss | 0.8838 |
| Train loss | 0.5087 |
| Train runtime | 44m 47s |
| Train samples/sec | 102.457 |
Eval per epoch
| Epoch | Eval F1 macro | Eval loss |
|---|---|---|
| 1 | 0.7427 | 0.8750 |
| 2 | 0.7604 | 0.7748 |
| 3 | 0.7885 | 0.7242 |
| 4 | 0.7899 | 0.7168 |
| 5 | 0.7968 | 0.7520 |
| 6 | 0.8043 | 0.8001 |
| 7 | 0.8034 | 0.8529 |
| 8 | 0.8066 | 0.8838 |
Per-class evaluation
Avaluació sobre el test split d'OSDG (2024-04-01), utilitzat com a validació durant l'entrenament.
| Label | Precision | Recall | F1 | Support |
|---|---|---|---|---|
sdg1 |
0.692 | 0.733 | 0.712 | 494 |
sdg2 |
0.816 | 0.816 | 0.816 | 506 |
sdg3 |
0.880 | 0.890 | 0.885 | 526 |
sdg4 |
0.871 | 0.856 | 0.864 | 736 |
sdg5 |
0.880 | 0.835 | 0.857 | 875 |
sdg6 |
0.794 | 0.823 | 0.809 | 549 |
sdg7 |
0.830 | 0.831 | 0.830 | 610 |
sdg8 |
0.534 | 0.521 | 0.528 | 284 |
sdg9 |
0.772 | 0.836 | 0.803 | 543 |
sdg10 |
0.704 | 0.667 | 0.685 | 457 |
sdg11 |
0.824 | 0.821 | 0.823 | 497 |
sdg12 |
0.805 | 0.764 | 0.784 | 233 |
sdg13 |
0.778 | 0.838 | 0.807 | 452 |
sdg14 |
0.878 | 0.844 | 0.861 | 231 |
sdg15 |
0.862 | 0.836 | 0.849 | 554 |
sdg16 |
0.993 | 0.986 | 0.990 | 1058 |
| Macro avg | 0.807 | 0.806 | 0.806 | 8605 |
| Weighted avg | 0.830 | 0.829 | 0.829 | 8605 |
Confusion matrix
Eix Y: true label · Eix X: predicció · Valors: % de cada fila.
Matriu numèrica completa: confusion_matrix.json.
Usage
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
model_id = "albertmartinez/xlm-roberta-large-sdg-classification-2024-04"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id)
text = "Access to clean water and sanitation infrastructure in rural areas."
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
with torch.inference_mode():
pred = model(**inputs).logits.argmax(-1).item()
print(model.config.id2label[str(pred)])
Framework versions
| Package | Version |
|---|---|
transformers |
4.57.6 |
torch |
2.6.0+cu124 |
datasets |
5.0.1 |
accelerate |
1.14.0 |
tokenizers |
0.22.2 |