RoBERTa Large - CEFR Classifier (Joint WCE+Ordinal Method)
This repository contains a publication-grade, fine-tuned transformer model optimized for mapping English student prose directly to the Common European Framework of Reference for Languages (CEFR) proficiency scales (A1–C2).
The model is built on top of the deep contextual architecture of FacebookAI/roberta-large and is fine-tuned on a massive, structural subset of the EFCAMDAT corpus comprising 104,125 rows.
It implements a unique Joint Loss optimization framework designed to explicitly manage class imbalance and respect the continuous, ordinal sequence of language acquisition.
It achieves the following results on the evaluation set:
Loss: 0.1880
Strict Accuracy: 0.9833
Adjacent Accuracy: 0.9943
Macro F1: 0.9747
Mae: 0.0240
Qwk: 0.9863
Model description
Architectural Modification
The base model originates from FacebookAI/roberta-large (355M parameters). To repurpose the architecture for multi-class sequence classification, the pre-trained Masked Language Modeling (MLM) head (lm_head) was completely excised. It was replaced with a randomly initialized linear classification head mapped to 6 discrete output nodes corresponding to the target CEFR levels:
Standard sequence classifiers treat categorical labels as nominal variables, assuming the distance between any two mistakes is mathematically equal (e.g., misclassifying an A1 text as C2 carries the same penalty as misclassifying it as A2). Because CEFR proficiency scales operate on an ordinal ladder, this model utilizes a Joint Optimization Objective:
The training objective combines Weighted Cross-Entropy with an Ordinal Distance Penalty to address both class imbalance and the ordinal nature of the classification task.
Weighted Cross-Entropy (L_WCE)
Corrects for severe data scarcity in advanced cohorts (C1/C2) by scaling the categorical cross-entropy loss using inverse class frequencies.
w_c = N_total / (C × N_c)
where:
N_total is the total number of training samples.
C is the number of classes.
N_c is the number of samples belonging to class c.
Ordinal Distance Penalty (L_Ordinal)
Computes a continuous, differentiable expected class value from the softmax probability distribution over the ordered classes.
ŷ = Σ P(class_i) × i
The ordinal loss is then computed as the Mean Squared Error (MSE) between the expected prediction and the ground-truth label:
L_Ordinal = (1/B) Σ (ŷ_b − y_b)²
where:
B is the batch size.
ŷ_b is the expected class value for sample b.
y_b is the corresponding ground-truth ordinal label.
For this training routine, the regularization weight was set to λ = 0.5, encouraging the model to resolve nearby decision boundaries sequentially while penalizing catastrophic multi-tier classification errors.
The final training objective is:
L = L_WCE + λ × L_Ordinal
Note: For a nominal baseline optimized exclusively through class weighting without distance constraints, please refer to the sister architecture: RoBERTa Large - CEFR Classifier (WCE Method).
Intended uses & limitations
Recommended Applications
Automated Essay Scoring (AES): Instantaneous evaluation of continuous multi-paragraph student text blocks.
Educational Analytics: Longitudinal progress tracking of language learners across digital learning platforms.
Curriculum Alignment: Diagnostic screening of raw reading or writing materials to match specific target student profiles.
Technical Limitations
Domain Specificity: The model was fine-tuned heavily on non-native English learner compositions. Performance may vary on native speech, fiction prose, or specialized academic/legal discourse.
Context Length Constraints: Standard tokenization caps the input length at 512 subword tokens. Texts exceeding this threshold will undergo truncation, potentially missing macro-syntactic cues embedded at the tail end of longer essays.
Training and evaluation data
The final dataset consists of 104,125 rows with a heavily stratified 90/10 training and internal validation split:
Level A1: 25,000 samples | 24.01% allocation
Level A2: 25,000 samples | 24.01% allocation
Level B1: 25,000 samples | 24.01% allocation
Level B2: 23,529 samples | 22.60% allocation
Level C1: 4,614 samples | 4.43% allocation
Level C2: 982 samples | 0.94% allocation
Training procedure
Training hyperparameters
Learning Rate: 2e-05
Per-Device Train Batch Size: 128 (Optimized via full tensor parallel execution on NVIDIA A100 architecture)
To establish true generalizability and rule out internal data leakage, the finalized model was subjected to an Independent Out-of-Distribution (OOD) Stress-Testing Routine.
Benchmark Methodology
The evaluation architecture was frozen in pure inference mode (model.eval(), torch.no_grad()) and fed an entirely separate, non-overlapping dataset slice from EFCAMDAT originally reserved for testing a distinct Plug-and-Play Language Model (PPLM) classifier module. To remove all baseline prevalence bias and simulate a strict diagnostic environment, the evaluation subset was forcefully downsampled into a perfectly balanced profile anchored to the absolute minority class floor ($N = 928$ rows per class across all 6 categories, creating a global verification volume of 5,568 samples).
Global Generalization Metrics
Strict Accuracy: 97.74%
Adjacent Accuracy (Distance $\leq$ 1): 98.83%
Micro F1 Score: 0.9774
Macro F1 Score: 0.9774
Mean Absolute Error (MAE): 0.0383
Quadratic Weighted Kappa (QWK): 0.9861
Per-Class Diagnostic Stress Test Breakdown
CEFR Level
Evaluated Samples
Accuracy (%)
Error Rate (%)
A1
928
99.68%
0.32%
A2
928
99.03%
0.97%
B1
928
98.38%
1.62%
B2
928
98.28%
1.72%
C1
928
95.69%
4.31%
C2
928
95.26%
4.74%
How to Use
You can easily instantiate this model for high-throughput batch inference using the code snippet below:
python
1import torch
2import numpy as np
3from transformers import AutoTokenizer, AutoModelForSequenceClassification
45# Define target repository path6MODEL_ID ="MohammadKhosravi/roberta-large-cefr-classifier-JointLoss"78# 1. Load native tokenizer and joint loss classifier9tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)10model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID)1112# Place model on optimized GPU accelerator if available13device = torch.device("cuda"if torch.cuda.is_available()else"cpu")14model = model.to(device)15model.eval()1617# 2. Prepare sample student essays for diagnostic assessment18sample_texts =[19"I like to play football with my friends on Sunday. It is very fun.",20"Although the economic implications of the policy change are highly controversial, empirical data suggests a clear trend toward market stabilization."21]2223# 3. Compute inference pipeline24inputs = tokenizer(sample_texts, padding=True, truncation=True, max_length=512, return_tensors="pt").to(device)2526with torch.no_grad():27 outputs = model(**inputs)28 logits = outputs.logits
29 predictions = torch.argmax(logits, dim=-1).cpu().numpy()3031# 4. Map output tokens to clean strings32id2label = model.config.id2label
33for text, pred_id inzip(sample_texts, predictions):34print(f"\nText Sample: {text[:80]}...")35print(f"Predicted CEFR Level: {id2label[pred_id]}")36