
Binary sentiment head (Geron Ch 16, morie.fn grsnt)
Source:R/geron_train_native.R
morie_geron_sentiment_binary.Rdp = sigmoid(w . pool(E[ids]) + b); mean pooling loses order, max acts as a keyword detector. Token ids are 0-based.
Examples
set.seed(6)
E <- matrix(rnorm(20), 5, 4)
morie_geron_sentiment_binary(c(0L, 3L, 2L), E, w = c(0.5, -0.2, 0.1, 0.3),
b = 0.1)
#> $probability
#> [1] 0.6070639
#>
#> $label
#> [1] 1
#>
#> $logit
#> [1] 0.434987
#>
#> $pooled
#> [1] 0.9551538 0.3838400 0.6708304 -0.4430165
#>
#> $token_contributions
#> [1] 0.25036461 0.73098196 0.02361431
#>
#> $estimate
#> [1] 0.6070639
#>
#> $n
#> [1] 3
#>