
Flamingo tanh-gated cross-attention (Geron Ch 17, morie.fn grflam)
Source:R/geron_train_native.R
morie_geron_flamingo_cross_modal_attn.Rdh_new = h + tanh(alpha) * crossattn(h, visual), the cross-attention
coming from morie_geron_cross_attention().
Examples
set.seed(1)
h <- matrix(rnorm(12), 3, 4)
vf <- matrix(rnorm(8), 2, 4)
W <- diag(4)
r <- morie_geron_flamingo_cross_modal_attn(h, vf, alpha = 0.5,
weights = list(WQ = W, WK = W,
WV = W))
str(r, max.level = 1)
#> List of 9
#> $ h_new : num [1:3, 1:4] -1.251 -0.443 -1.711 1.867 0.6 ...
#> $ gate : num 0.462
#> $ alpha : num 0.5
#> $ attention_output : num [1:3, 1:4] -1.352 -1.356 -1.894 0.588 0.586 ...
#> $ attention_weights: num [1:3, 1:2] 0.541 0.539 0.201 0.459 0.461 ...
#> $ delta_norm : num 1.49
#> $ is_identity : logi FALSE
#> $ estimate : num [1:3, 1:4] -1.251 -0.443 -1.711 1.867 0.6 ...
#> $ n : int 3