
BERT masked-language-model loss (Geron Ch 16, morie.fn grmlm)
Source:R/geron_train_native.R
morie_geron_bert_mlm_loss.RdCross-entropy on the masked positions only, the selected rows handed
to morie_geron_gpt_autoregressive_loss().
Value
List with loss, mean_loss, perplexity,
per_token_loss, masked_positions (0-based), n_masked,
mask_rate.
Examples
lg <- matrix(c(2, 0.1, 0.1, 0.1, 2, 0.1), 2, 3, byrow = TRUE)
morie_geron_bert_mlm_loss(lg, targets = c(1L, 2L), mask = c(1, 1))
#> $loss
#> [1] 4.323401
#>
#> $mean_loss
#> [1] 2.1617
#>
#> $perplexity
#> [1] 8.685894
#>
#> $per_token_loss
#> [1] 2.1617 2.1617
#>
#> $masked_positions
#> [1] 0 1
#>
#> $n_masked
#> [1] 2
#>
#> $mask_rate
#> [1] 1
#>
#> $estimate
#> [1] 4.323401
#>
#> $n
#> [1] 2
#>