
SFT masked cross-entropy objective (Geron Ch 15, morie.fn grsft)
Source:R/geron_train_native.R
morie_geron_sft_objective.Rd-mean log p over the MASKED response tokens only; prompt tokens are excluded from the average.
Examples
set.seed(5)
logits <- matrix(rnorm(20), 4, 5)
morie_geron_sft_objective(logits, response_mask = c(FALSE, TRUE, TRUE, TRUE),
targets = c(0L, 2L, 4L, 1L))
#> $loss
#> [1] 1.746399
#>
#> $per_token
#> [1] 1.757174 1.540288 1.941734
#>
#> $perplexity
#> [1] 5.733916
#>
#> $n_response_tokens
#> [1] 3
#>
#> $token_logprobs
#> [1] -2.870247 -1.757174 -1.540288 -1.941734
#>
#> $estimate
#> [1] 1.746399
#>
#> $n
#> [1] 4
#>