Skip to content

Model research

Custom model fine-tuning

End-to-end custom model work: a labeled multilingual dataset, a disciplined architecture ablation, and a multi-task fine-tuned model.

Data

A 54,000-row multilingual dataset built via translation, validated with back-translation and similarity scoring, and independently reconstructed from raw annotations.

Modeling

Compared 6 model variants in an ablation ladder, from a pooled baseline to a custom attention-gated fusion architecture. One shared encoder handles 2 prediction tasks across 3 languages.

Rigor

The baseline, the 3-branch Final and the Proposed Architecture ran on two random seeds, every run was logged in a shared experiment tracker, and a fairness metric is reported next to raw accuracy.

Result

The final architecture improved both emotion F1 and a custom cross-lingual fairness metric, consistently across seeds. The training instability it introduced is reported, not hidden.

162,789instances: 54,263 rows in each of 3 languages
3languages: English, Hindi and Spanish
2tasks from one encoder: 7 emotions, 3 sentiments
7model variants in the ablation ladder
2seeds on the headline models (42 and 43)
~291Mparameters in the final model

The dataset

Emotion datasets are mostly English, and translated data usually carries its errors straight into training. The first job was a multilingual version of GoEmotions in which every translation has a measured quality score.

Building the multilingual dataset: translate GoEmotions, back-translate and score every row, retry weak translations, then verify against the raw annotations GoEmotions English source54,263 rows27 emotions Translate Hindi: IndicTrans2Spanish: NLLB-200 Back-translate each row returns toEnglish Score LaBSE similaritybelow 0.80 is flagged Retry flagged rows re-run;kept only if better Verify rebuilt from rawannotations: exact match No rows are removed after the retry, 5.96% of Hindi and 20.07% of Spanish rows stay flagged as a column, so training on everything can be compared with training on the clean subset
Translate, score, retry, verify. Nothing is deleted, so flagged rows stay available for a controlled comparison.

Official splits kept

43,410 train, 5,426 validation and 5,427 test rows per language, matching GoEmotions.

Labels carried over

The 27 emotions, the 7 Ekman groups and a coarse 3-way sentiment label are copied unchanged through translation.

Measured, not trusted

Every translation is translated back and scored with LaBSE similarity, and anything below 0.80 is flagged, so quality is a number instead of an assumption.

Independently rebuilt

The dataset and its per-category label counts were reconstructed from the raw rater-level annotations and matched exactly.

Class imbalance, openly

Joy outnumbers fear 23.4 to 1. Class-balanced loss weights are computed once from the English distribution and reused for every language.

Known limit

The text is machine-translated, not naturally written, and the similarity score favours longer sentences, so it is a triage signal and not a precise error measure.

The model

One shared multilingual encoder serves two prediction tasks across three languages. Two parallel branches look at the sentence in different ways, a fusion bridge combines them, and each task has its own head on the same shared representation.

The multitask model: an XLM-RoBERTa encoder and BiLSTM feed a context branch and a token branch, a fusion bridge combines them, and two heads predict emotion and sentiment XLM-RoBERTa shared multilingualencoder BiLSTM sequence modelling Context branch self-attention overthe whole sentence Token branch weights the wordsthat carry emotion Fusion bridge combines thetwo branches Emotion head 7 emotion classes Sentiment head 3 sentiment classes
Encoder, sequence model, two branches, fusion and two heads. The best variant found later removes one of the branches.

Training setup

SettingValue
EncoderXLM-RoBERTa, shared across all three languages and both tasks
OptimiserAdamW, learning rate 2e-5, weight decay 0.01, cosine schedule
Batch and lengthBatch size 16, up to 10 epochs
StoppingEarly stopping after 3 epochs without validation improvement, so the epoch count is an upper bound
LossClass-balanced weights from the English label distribution
StabilityGradient clipping, which the proposed architecture needed: the unclipped run diverged
TrackingEvery run logged to Weights & Biases, with a results ledger kept alongside

The ablation ladder

Each stage adds one component to the baseline, with everything else held fixed. A second phase then removes components from the best model one at a time.

The ablation ladder: one component added per stage from a plain baseline, then leave-one-out on the best model, with emotion F1 at each step M1 baseline XLM-R only0.5133 M2 +BiLSTM 0.5180 M3 +token token attention0.5190 M4 +context 0.4988serial collapsed M5 +bridge fusion bridge0.5062 M6 +gate 0.5087gate collapsed Final gate removed0.5203 Phase 2: leave-one-out remove one component at a time from the final model,repeated on two seeds Best: remove the global branch emotion F1 0.5349, gap ratio 0.8737 (seed 42)leads on both across both seeds
Emotion F1 at each stage. Two stages collapsed and were removed. The best result came from leave-one-out.
StageEmotion F1Sentiment F1EnglishHindiSpanishGap ratioParams
M1 · XLM-R baseline0.51330.68770.55540.51350.46670.8403278M
M2 · + BiLSTM0.51800.69510.56670.51330.46900.8277282M
M3 · + token attention0.51900.68830.56260.51910.47180.8386282M
M4 · + context attention0.49880.70070.55290.48930.44960.8132285M
M5 · + fusion bridge0.50620.71380.56330.49280.45760.8123291M
M6 · adaptive gate0.50870.69350.55860.50280.46080.8249289M
Final · gate removed0.52030.69470.57010.50740.48180.8452291M

Per-language columns are test-set emotion F1. The gap ratio is Spanish divided by English, so higher means more consistent across languages. Inference on 500 examples took 0.82 s for the baseline and 1.06 s for the fullest variant.

What did not work

Serial attention collapsed

Context attention stacked before token attention produced near-identical representations (cosine similarity about 0.997), so two layers did the work of one. Parallel branches replaced them.

The adaptive gate collapsed

It settled into a near-constant routing policy, and a fixed-weight version did the same. It was removed.

Task-specific heads lost

Separate projection heads for each task did worse than the shared representation.

Instability, reported

The best architecture needs gradient clipping to train at all. That is stated next to the result instead of left out.

Rigour

One change at a time

Hyperparameters and evaluation are identical at every stage, so any difference comes from the component just added.

Leave-one-out confirms

Each part of the best model is removed in turn to prove it earns its place.

Seeds, not single runs

The baseline, Final and Proposed models ran on two seeds, and run-to-run variance is reported. The consistent ranking across seeds is the finding, not any single number.

A fairness metric

The gap ratio, Spanish F1 divided by English F1, is reported next to raw accuracy, so a gain that helps one language at another’s cost shows up.

Read the research

Stack

XLM-RoBERTaBiLSTMPyTorchIndicTrans2NLLB-200LaBSEWeights & BiasesPython