
Permutation language-model loss under one factorization order
Source:R/bounds_native.R
morie_permutation_lm_loss.RdEquation (3) of the XLNet paper, negated: $$-\sum_{t} \log p_\theta(x_{z_t} \mid x_{z_{<t}}).$$
Usage
morie_permutation_lm_loss(
logits,
targets,
permutation,
num_predict = NULL,
reduction = c("mean", "sum", "none")
)Value
A list with loss, token_nll, scored_positions,
perplexity, order_invariant, mean_context_length.
Details
With the logits held fixed the full-sequence loss does NOT depend on
the permutation, because reordering the terms of a sum leaves the sum
alone. The permutation acts only on what the network was allowed to
condition on when producing those logits – that is, on the masks –
never on this arithmetic. order_invariant records that, and is TRUE
by construction whenever the whole sequence is scored.
Equation (5) is partial prediction: score only the trailing
num_predict positions of the factorization order, whose contexts
are the longest available. The scored subset then depends on the
permutation, so the loss does too, and order_invariant goes FALSE.