Downloads · 30 days
6
8% of all-time downloads
hannah-khallaf/e2r-strategy-xlmr-large-focal
e2r-strategy-xlmr-large-focal is a text classification model from hannah-khallaf. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
This model identifies the simplification strategies realised between a standard-language sentence and its Easy-to-Read rewrite.
Downloads · 30 days
6
8% of all-time downloads
All-time downloads
71
Public
Parameters
560M
2.3 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors2.2 GB · 99%
From the Hugging Face model README
This model identifies the simplification strategies realised between a standard-language sentence and its Easy-to-Read rewrite.
It is a multilingual sentence-pair multi-label classifier covering Arabic, Catalan, English, French, Italian and Spanish.
The model predicts any combination of the following six strategies:
The label order is fixed and must not be changed.
The model uses:
FacebookAI/xlm-roberta-large as the multilingual encoder;0.1;0.46;The classification architecture is:
XLM-R Large
→ first-token/CLS representation
→ dropout
→ linear layer with six outputs
→ sigmoid probabilities
→ threshold at 0.46
The model was trained with focal loss using positive-label weighting.
This repository contains seed 13, selected using development Macro-F1.
| Result | Value |
|---|---|
| Selected seed | 13 |
| Best epoch | 5 |
| Development Macro-F1 | 69.53 |
| Three-seed test Macro-F1, mean ± SD | 59.20 ± 0.43 |
| Decision threshold | 0.46 |
The development score refers to the released seed. The reported test result is the mean and standard deviation across seeds 13, 42 and 87.
pip install torch transformers
Because this repository includes the exact custom classification architecture, load it with trust_remote_code=True.
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
model_id = "hannah-khallaf/e2r-strategy-xlmr-large-focal"
tokenizer = AutoTokenizer.from_pretrained(
model_id,
trust_remote_code=True,
)
model = AutoModelForSequenceClassification.from_pretrained(
model_id,
trust_remote_code=True,
)
standard_sentence = (
"The committee postponed the implementation of the measure."
)
easy_to_read_rewrite = (
"The committee decided to use the measure later."
)
inputs = tokenizer(
standard_sentence,
easy_to_read_rewrite,
return_tensors="pt",
truncation=True,
max_length=512,
)
model.eval()
with torch.inference_mode():
logits = model(**inputs).logits
probabilities = torch.sigmoid(logits)[0]
labels = [
model.config.id2label[index]
for index in range(model.config.num_labels)
]
thresholds = model.config.e2r_classifier["thresholds"]
scores = {
label: float(probability)
for label, probability in zip(labels, probabilities)
}
predicted_labels = [
label
for label in labels
if scores[label] >= float(thresholds[label])
]
print("Predicted strategies:", predicted_labels)
print("Scores:", scores)
Example output:
{
"predicted_labels": [
"Explanation",
"Syntactic Change"
],
"scores": {
"Synonymy": 0.2955,
"Modulation": 0.3413,
"Compression": 0.2076,
"Explanation": 0.5029,
"Syntactic Change": 0.4802,
"Omission": 0.1881
}
}
from __future__ import annotations
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
MODEL_ID = "hannah-khallaf/e2r-strategy-xlmr-large-focal"
tokenizer = AutoTokenizer.from_pretrained(
MODEL_ID,
trust_remote_code=True,
)
model = AutoModelForSequenceClassification.from_pretrained(
MODEL_ID,
trust_remote_code=True,
)
model.eval()
def classify_rewrite(
standard_sentence: str,
easy_to_read_rewrite: str,
) -> dict:
inputs = tokenizer(
standard_sentence,
easy_to_read_rewrite,
return_tensors="pt",
truncation=True,
max_length=512,
)
with torch.inference_mode():
logits = model(**inputs).logits
probabilities = torch.sigmoid(logits)[0]
labels = [
model.config.id2label[index]
for index in range(model.config.num_labels)
]
thresholds = model.config.e2r_classifier["thresholds"]
scores = {
label: float(probability)
for label, probability in zip(labels, probabilities)
}
predicted_labels = [
label
for label in labels
if scores[label] >= float(thresholds[label])
]
return {
"predicted_labels": predicted_labels,
"scores": scores,
"thresholds": thresholds,
}
The standard sentence must be supplied first and the Easy-to-Read rewrite second:
inputs = tokenizer(
standard_sentence,
easy_to_read_rewrite,
return_tensors="pt",
truncation=True,
max_length=512,
)
Reversing the sentence order does not represent the task on which the model was trained.
The model returns six logits in the following exact order:
Synonymy
Modulation
Compression
Explanation
Syntactic Change
Omission
Apply torch.sigmoid() to convert the logits to probabilities. A strategy is predicted when its probability is at least 0.46.
The thresholds are also stored in:
model.config.e2r_classifier["thresholds"]
The model is intended for:
It may support annotation, but its output should not be treated as a substitute for expert review.
The model should not be used as evidence that a text is accessible to a particular person or reader group.
It should not be used to make medical, legal, educational or administrative decisions about individuals.
The model assigns labels at sentence level. It does not:
Performance differences between languages may reflect differences in corpus, domain, simplification practice, annotation procedure and label harmonisation. They should not be interpreted as inherent differences between languages.
The repository includes:
The exported Transformers model was verified against the original PairClassifier. The original and exported models produced identical logits, probabilities and thresholded predictions in the conversion checks.
Please cite the accompanying paper when using this model. The complete bibliographic entry will be added after publication.