Skip to content

Language models, retrieval, prompting, and language adaptation · Encoder–decoder and multilingual models · LNG026 · Training method

MASS

Jointly pretrains encoder–decoder sequence generation by masking a consecutive input fragment and predicting that fragment.

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 here in one language.
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

Jointly pretrains encoder–decoder sequence generation by masking a consecutive input fragment and predicting that fragment. It was motivated by low-resource and unsupervised sequence-to-sequence tasks, including translation.

Question / objective

Can masked-span reconstruction jointly initialize both sides of a sequence transducer?

Architecture / computational structure

A sequence-to-sequence encoder/decoder hides a consecutive span and predicts its content without target leakage. Learned network weights are parameters; span policy and subsequent task mixture are hyperparameters.

Assumptions

Denoising alone does not identify an accurate cross-language mapping.

Formula / computational definition

LMASS=−log⁡pθ(xu:v∣x∖u:v).\mathcal L_{\mathrm{MASS}}=-\log p_\theta(x_{u:v}\mid x_{\setminus u:v}).

For sampled span positions u:v, maximize log p_theta(x_u:v|x_without_u:v). Encoder input hides the target fragment; decoder conditioning and masking prevent simply copying exposed target tokens.

Parameters and notation

Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Masked-span fraction, location sampling, vocabulary sharing, language balancing, model capacity, and subsequent supervised or back-translation objectives.

Fitting, fine-tuning, and adaptation

Pretrain with exact MASS masking and decoder inputs, then adapt using parallel pairs, back-translation, or another explicitly described objective. Freeze selected layers only after a baseline; adapters require compatible modules. Validate translation direction, monolingual-domain mismatch, and retained language competence.

How to use and calibrate

Compare held-out span prediction, downstream translation quality, low-resource data curves, and performance by language pair and direction. 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

Initialize translation between languages with abundant monolingual text but little parallel data.

Interpretation / pitfalls

Watch out

Related scripts, shared lexical structure, and monolingual corpus quality can materially affect unsupervised translation; target leakage invalidates the intended objective. 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: Use the authors' released implementation or a carefully documented encoder–decoder training loop in Python. R bridges that code through reticulate; the native example constructs a masked span and target only, with exact algorithmic masking made explicit.

Example scope: MASS consecutive-span masking and target extraction; decoder training masks remain required.

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 — MASS consecutive-span masking and target extraction; decoder training masks remain required.

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)
tokens = ["a","model","predicts","missing","text"]
start, stop = 1, 4
masked = tokens[:start] + ["<mask>"]*(stop-start) + tokens[stop:]
print(masked, tokens[start:stop])
R

Component demo, not a trained model — MASS consecutive-span masking and target extraction; decoder training masks remain required.

Shared setup for this chapter
softmax <- function(x) {
  shifted <- exp(x-max(x))
  shifted/sum(shifted)
}
tokens <- c("a","model","predicts","missing","text")
span <- 2:4; masked <- tokens; masked[span] <- "<mask>"
print(list(masked=masked, target=tokens[span]))

Sources

From the CodeSplash reference, entry LNG026.