Training the Level Predictor
OpenL2’s difficulty predictor (src/openl2/courses/level_predictor.py) scores passages and transcripts on OpenL2’s canonical 0.0–100.0 proficiency scale, then maps that score onto any course or framework’s levels—CEFR (A1–C2), JLPT (N5–N1), HSK (1–9), or custom proficiency_range bands defined in level.yaml (src/openl2/courses/proficiency_scale.py).
Pre-trained per-language weights live in src/openl2/courses/data/level_weights.json and currently include calibrated models for en, de, fr, nl, it (CEFR bands A1–B2+) and ja (JLPT bands N5–N1).
Raw third-party training corpora are not committed to git. Use scripts/train_cefr_level_model.py to download CEFR corpora locally and reproduce or retrain weights whenever a course’s inventory or task progression changes.
How framework-agnostic scoring works
Section titled “How framework-agnostic scoring works”- Extract proficiency-scale features: Every lexical Concept and grammatical Skill matched in a passage is mapped to its position on the
0–100proficiency scale (using the course’sproficiency_rangeor framework defaults), rather than hardcoding CEFR level names. - Predict a
0–100score: Per-language calibrated multinomial logistic regression weights produce band probabilities and an expected0–100score using each model’sclass_midpoints(for example,[10, 30, 50, 70]for CEFRA1–B2+or[10.0, 27.5, 45.0, 65.0, 83.5]for JLPTN5–N1). - Map to any target framework: At inference time, the
0–100score maps cleanly onto whatever framework or custom level bands the target course declares.
Datasets (UniversalCEFR)
Section titled “Datasets (UniversalCEFR)”The bundled European-language weights train on passages from the open UniversalCEFR collection on HuggingFace:
| Language | HuggingFace Dataset | File | Passages | Bands Trained | License |
|---|---|---|---|---|---|
English (en) |
UniversalCEFR/elg_cefr_en |
elg-cefr-en.json |
712 | A1, A2, B1, B2+ | CC BY-NC-SA 4.0 |
German (de) |
UniversalCEFR/elg_cefr_de |
elg-cefr-de.json |
509 | A1, A2, B1, B2+ | CC BY-NC-SA 4.0 |
French (fr) |
UniversalCEFR/kwiqiz_fr + UniversalCEFR/readme_fr |
kwiziq-fr.json, readme_fr.json |
344 + 1,669 | A1, A2, B1, B2+ | CC BY-NC 4.0 / CC BY-SA-NC 4.0 |
Dutch (nl) |
UniversalCEFR/elg_cefr_nl |
elg-cefr-nl.json |
3,596 | A1, A2, B1, B2+ | CC BY-NC-SA 4.0 |
Italian (it) |
UniversalCEFR/merlin_it |
merlin-it.json |
813 | A1, A2, B1 | CC BY-SA 4.0 |
Spanish candidate (es) |
UniversalCEFR/kwiqiz_es |
kwiziq-es.json |
206 before filtering | A1, A2, B1, B2+ | CC BY-NC 4.0 |
License note: The ELG, Kwiziq, and ReadMe-FR subsets carry non-commercial (
NC) Creative Commons licenses. Raw datasets are downloaded intoopenl2/.openl2/cefr_training_data/(gitignored) and must not be committed.
Prerequisites
Section titled “Prerequisites”numpy(required for--train)stanzaandwordfreq(required for--extract)- Stanza models for the target languages (downloaded automatically on first run)
Reproducing or Retraining the Weights
Section titled “Reproducing or Retraining the Weights”From the openl2/ directory:
# 1. Full pipeline: download -> extract features -> train & overwrite weightsPYTHONPATH=src python scripts/train_cefr_level_model.py --allYou can also run each stage independently:
# Download UniversalCEFR JSON files into .openl2/cefr_training_data/PYTHONPATH=src python scripts/train_cefr_level_model.py --download
# Run Stanza + OpenL2 open-world analysis to cache per-language feature vectorsPYTHONPATH=src python scripts/train_cefr_level_model.py --extract
# Run 5-fold stratified CV and write src/openl2/courses/data/level_weights.jsonPYTHONPATH=src python scripts/train_cefr_level_model.py --trainTo test on a subset of languages or write to an alternate output file:
PYTHONPATH=src python scripts/train_cefr_level_model.py \ --download --extract --train \ --languages en de \ --output /tmp/level_weights.jsonSpanish research candidate
Section titled “Spanish research candidate”Run PYTHONPATH=src python scripts/train_cefr_level_model.py --all --languages es.
This uses Spanish Stanza parses and the Mexican Spanish course inventory. It
fits on Kwiziq documents and evaluates on the entire HablaCultura publisher
holdout. The
HablaCultura sample contains A2–C1 and has no A1 support. B2 and C1 are grouped
into the B2+ prediction band. Repeated text counts once, ambiguous duplicate
labels are discarded, and any passage with invalid parser spans is reported and
excluded in full.
Use --spanish-holdout once per additional source during extraction. Passages
must have an A1–C2 prefix, for example a1-title.txt. Those sources are used only
for evaluation. Output defaults to cefr_spanish_candidate.json and
cefr_spanish_candidate.evaluation.json in the local data directory. The report
includes per-band recall, confusion matrices, calibration error and comparisons
against majority and length-and-frequency baselines.
The datasets carry non-commercial licenses. Credit Vásquez-Rodríguez et al.’s Spanish readability benchmark and the UniversalCEFR transformations.
Model & Features
Section titled “Model & Features”For each language, the training pipeline fits two standardized, class-balanced, L2-regularized multinomial logistic regression models (lam=3.0, lr=0.2, steps=600):
core(19 features, zero optional dependencies at inference):- Open-world lexical coverage & proficiency-band distribution:
oov_non_propn,lex_0_20_pct,lex_20_40_pct - Continuous proficiency-scale task-position percentiles:
skill_pos_mean,skill_pos_p75,skill_pos_p90,skill_pos_p95,lex_pos_mean,lex_pos_p90 - Banded skill density per 100 tokens:
sk_0_10_100,sk_10_20_100,sk_20_30_100,sk_30_40_100,sk_40_60_100 - Structural complexity:
unx_100,zero_edge_pct,tok_per_sent,subord_per_sent,avg_word_len
- Open-world lexical coverage & proficiency-band distribution:
zipf(23 features, used automatically whenwordfreqis installed):- All 19
corefeatures plusoov_mid_freq_pct,oov_low_freq_pct,p10_content_zipf, andmean_content_zipf.
- All 19
Training calls the same _extract_sentence_stats and _aggregate_window_features helpers used at inference time in level_predictor.py, keeping training and inference features identical.