
BLIP multi-task loss with captioning head (Geron Ch 16, morie.fn grblip)
Source:R/geron_ml_native.R
morie_geron_blip_itm_itc.RdITC (symmetric InfoNCE) + ITM (pairwise BCE over all B^2 pairs, diagonal = match) + LM (token cross-entropy, negative targets are padding). Caption targets are 0-based token ids.
Usage
morie_geron_blip_itm_itc(
image_emb,
text_emb,
caption_logits,
caption_targets,
tau = 0.07,
lam_itc = 1,
lam_itm = 1,
lam_lm = 1,
normalize = TRUE
)Examples
cl <- array(0, dim = c(2, 2, 2))
morie_geron_blip_itm_itc(matrix(c(1, 0, 0, 1), 2, 2, byrow = TRUE),
matrix(c(1, 0.2, 0.1, 1), 2, 2, byrow = TRUE), cl, matrix(c(0,
1, 1, -1), 2, 2, byrow = TRUE), tau = 0.5)
#> $loss
#> [1] 1.356111
#>
#> $itc
#> [1] 0.1715338
#>
#> $itm
#> [1] 0.4914298
#>
#> $lm
#> [1] 0.6931472
#>
#> $similarity
#> [,1] [,2]
#> [1,] 0.9805807 0.09950372
#> [2,] 0.1961161 0.99503719
#>
#> $itm_accuracy
#> [1] 0.5
#>
#> $lm_perplexity
#> [1] 2
#>
#> $tau
#> [1] 0.5
#>
#> $weights
#> [1] 1 1 1
#>
#> $estimate
#> [1] 1.356111
#>
#> $n
#> [1] 2
#>
#> $method
#> [1] "BLIP multi-task objective (ITC + ITM + LM)"
#>