Skip to content

Language models, retrieval, prompting, and language adaptation · Encoder–decoder and multilingual models · LNG027 · Model

mBART

Extends denoising sequence-to-sequence pretraining across languages so translation systems can share representations and initialize both encoder and decoder.

Explained here Component demo, not a trained model CodeSplash's own run

In CodeSplash

Documented in the Academy only. There's no Set up button.

Availability
Explained here
Code example
Component demo, not a trained model
Who ran it
CodeSplash's own run
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: The chapter's authors report running it; there is no record for this entry alone. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Extends denoising sequence-to-sequence pretraining across languages so translation systems can share representations and initialize both encoder and decoder. Language identity and corpus balancing become essential parts of model use.

Question / objective

Can multilingual denoising supply reusable encoder and decoder representations for translation?

Architecture / computational structure

A shared multilingual encoder–decoder uses language identifiers and denoising objectives. Learned shared weights/embeddings are parameters; language sampling, corruption, and target-language tokens are hyperparameters/configuration.

Assumptions

Uneven language data can dominate transfer; shared subwords do not guarantee shared semantics.

Formula / computational definition

L=−∑ℓπℓ Ex∼Dℓlog⁡pθ(x∣corrupt⁡(x),ℓ).\mathcal L=-\sum_\ell\pi_\ell\,\mathbb E_{x\sim D_\ell}\log p_\theta(x\mid\operatorname{corrupt}(x),\ell).

Minimize a weighted multilingual reconstruction loss sum_l pi_l E_x~D_l[-log p_theta(x|corrupt(x),l)], with language label l, corpus D_l, and sampling weight pi_l. Translation then conditions generation on the source sequence and desired target language.

Parameters and notation

Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Language sampling distribution, special language tokens, noise scheme, vocabulary, target-language initialization, and task fine-tuning configuration.

Fitting, fine-tuning, and adaptation

Fine-tune on parallel translation data with the correct source/target language codes. Consider freezing embeddings/encoder or compatible adapters for low-resource pairs; use mixed languages to reduce forgetting. Validate each direction independently and verify outputs remain in the requested language.

How to use and calibrate

Report translation quality by language and direction, zero-shot versus supervised conditions, resource level, and generation-language accuracy. Use development data for settings and an independent test set for the final estimate. Report uncertainty across examples or seeds when the evaluation design supports it; model scores and self-assessments are not automatically calibrated probabilities of correctness.

Example application

Adapt a multilingual translation model to a low-resource legal-document language pair.

Interpretation / pitfalls

Watch out

Wrong language tokens or tokenizer/checkpoint combinations can produce entirely wrong-language outputs. The code below isolates one stated component; successful execution does not validate model quality or reproduce the cited experiment.

Python and R code examples

Full implementation route: Transformers supports mBART variants but token and target-language conventions differ across checkpoints; read their model cards. R can reproduce the identical Python path through reticulate. The native example illustrates language-mixture weighting, not a pretrained translator.

Example scope: Multilingual denoising loss weighted by a chosen mBART language mixture.

Dependencies: Python 3 standard library; base R; shared setup above. No model downloads or external services.

Validation: Python component executed in the combined example script; R counterpart supplied but not runtime-tested here. All numbers are synthetic.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — Multilingual denoising loss weighted by a chosen mBART language mixture.

Shared setup for this chapter
import math

def softmax(xs):
    m = max(xs)
    es = [math.exp(x-m) for x in xs]
    return [e/sum(es) for e in es]

def dot(a, b):
    return sum(x*y for x, y in zip(a, b))

def matvec(matrix, vector):
    return [dot(row, vector) for row in matrix]

def meanvec(rows):
    return [sum(row[j] for row in rows)/len(rows) for j in range(len(rows[0]))]

def sigmoid(x):
    return 1/(1+math.exp(-x))

def nll(probabilities):
    return -sum(math.log(p) for p in probabilities)
weights, losses = [0.4,0.35,0.25], [1.2,1.8,2.1]
assert abs(sum(weights)-1) < 1e-12
print(dot(weights,losses))
R

Component demo, not a trained model — Multilingual denoising loss weighted by a chosen mBART language mixture.

Shared setup for this chapter
softmax <- function(x) {
  shifted <- exp(x-max(x))
  shifted/sum(shifted)
}
weights <- c(0.4,0.35,0.25); losses <- c(1.2,1.8,2.1)
stopifnot(abs(sum(weights)-1) < 1e-12)
print(sum(weights*losses))

Sources

From the CodeSplash reference, entry LNG027.