Att(Q,K,V) = softmax(Q K^T / sqrt(d_k)) V. Masked entries are set to -Inf before the row-wise softmax; a query row with no visible key is an error.
Examples
morie_geron_scaled_dot_product(Q = 0.5, K = 5L, V = 5L)
#> $Y
#> [,1]
#> [1,] 5
#>
#> $output
#> [,1]
#> [1,] 5
#>
#> $attention
#> [,1]
#> [1,] 1
#>
#> $scores
#> [,1]
#> [1,] 2.5
#>
#> $d_k
#> [1] 1
#>
#> $estimate
#> [1] 1
#>
#> $n
#> [1] 1
#>
#> $method
#> [1] "Scaled dot-product attention with pre-softmax masking"
#>
