Views
No views yet
FacebookAI/xlm-roberta-large as the multilingual encoder;0.1;0.46;1XLM-R Large
2→ first-token/CLS representation
3→ dropout
4→ linear layer with six outputs
5→ sigmoid probabilities
6→ threshold at 0.46| 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 |
pip install torch transformerstrust_remote_code=True.1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4model_id = "hannah-khallaf/e2r-strategy-xlmr-large-focal"
5
6tokenizer = AutoTokenizer.from_pretrained(
7 model_id,
8 trust_remote_code=True,
9)
10
11model = AutoModelForSequenceClassification.from_pretrained(
12 model_id,
13 trust_remote_code=True,
14)
15
16standard_sentence = (
17 "The committee postponed the implementation of the measure."
18)
19
20easy_to_read_rewrite = (
21 "The committee decided to use the measure later."
22)
23
24inputs = tokenizer(
25 standard_sentence,
26 easy_to_read_rewrite,
27 return_tensors="pt",
28 truncation=True,
29 max_length=512,
30)
31
32model.eval()
33
34with torch.inference_mode():
35 logits = model(**inputs).logits
36 probabilities = torch.sigmoid(logits)[0]
37
38labels = [
39 model.config.id2label[index]
40 for index in range(model.config.num_labels)
41]
42
43thresholds = model.config.e2r_classifier["thresholds"]
44
45scores = {
46 label: float(probability)
47 for label, probability in zip(labels, probabilities)
48}
49
50predicted_labels = [
51 label
52 for label in labels
53 if scores[label] >= float(thresholds[label])
54]
55
56print("Predicted strategies:", predicted_labels)
57print("Scores:", scores)1{
2 "predicted_labels": [
3 "Explanation",
4 "Syntactic Change"
5 ],
6 "scores": {
7 "Synonymy": 0.2955,
8 "Modulation": 0.3413,
9 "Compression": 0.2076,
10 "Explanation": 0.5029,
11 "Syntactic Change": 0.4802,
12 "Omission": 0.1881
13 }
14}1from __future__ import annotations
2
3import torch
4from transformers import AutoModelForSequenceClassification, AutoTokenizer
5
6
7MODEL_ID = "hannah-khallaf/e2r-strategy-xlmr-large-focal"
8
9
10tokenizer = AutoTokenizer.from_pretrained(
11 MODEL_ID,
12 trust_remote_code=True,
13)
14
15model = AutoModelForSequenceClassification.from_pretrained(
16 MODEL_ID,
17 trust_remote_code=True,
18)
19
20model.eval()
21
22
23def classify_rewrite(
24 standard_sentence: str,
25 easy_to_read_rewrite: str,
26) -> dict:
27 inputs = tokenizer(
28 standard_sentence,
29 easy_to_read_rewrite,
30 return_tensors="pt",
31 truncation=True,
32 max_length=512,
33 )
34
35 with torch.inference_mode():
36 logits = model(**inputs).logits
37 probabilities = torch.sigmoid(logits)[0]
38
39 labels = [
40 model.config.id2label[index]
41 for index in range(model.config.num_labels)
42 ]
43
44 thresholds = model.config.e2r_classifier["thresholds"]
45
46 scores = {
47 label: float(probability)
48 for label, probability in zip(labels, probabilities)
49 }
50
51 predicted_labels = [
52 label
53 for label in labels
54 if scores[label] >= float(thresholds[label])
55 ]
56
57 return {
58 "predicted_labels": predicted_labels,
59 "scores": scores,
60 "thresholds": thresholds,
61 }1inputs = tokenizer(
2 standard_sentence,
3 easy_to_read_rewrite,
4 return_tensors="pt",
5 truncation=True,
6 max_length=512,
7)1Synonymy
2Modulation
3Compression
4Explanation
5Syntactic Change
6Omissiontorch.sigmoid() to convert the logits to probabilities. A strategy is predicted when its probability is at least 0.46.model.config.e2r_classifier["thresholds"]PairClassifier. The original and exported models produced identical logits, probabilities and thresholded predictions in the conversion checks.