
Self-attention: Q=K=V come from same input
Source:R/geron_w4d_native.R
morie_geron_self_attention_modules.RdProjects X into Q, K, V with W_Q/W_K/W_V and delegates the kernel to
morie_geron_scaled_dot_product.
Examples
X <- matrix(c(1, 0, 0, 1), 2, 2, byrow = TRUE)
I2 <- diag(2)
morie_geron_self_attention_modules(X, I2, I2, I2)
#> $Y
#> [,1] [,2]
#> [1,] 0.6697615 0.3302385
#> [2,] 0.3302385 0.6697615
#>
#> $attention
#> [,1] [,2]
#> [1,] 0.6697615 0.3302385
#> [2,] 0.3302385 0.6697615
#>
#> $scores
#> [,1] [,2]
#> [1,] 0.7071068 0.0000000
#> [2,] 0.0000000 0.7071068
#>
#> $Q
#> [,1] [,2]
#> [1,] 1 0
#> [2,] 0 1
#>
#> $K
#> [,1] [,2]
#> [1,] 1 0
#> [2,] 0 1
#>
#> $V
#> [,1] [,2]
#> [1,] 1 0
#> [2,] 0 1
#>
#> $estimate
#> [1] 0.6697615
#>
#> $n
#> [1] 2
#>
#> $method
#> [1] "Self-attention: shared-source projections into hmsdp"
#>