
Image-text contrastive loss (Kamath Ch 9)
Source:R/kamath_llm2_native.R
morie_kamath_image_text_contrastive.RdSymmetric InfoNCE over cosine(I, T) / tau; the batch must hold at least two pairs.
Examples
morie_kamath_image_text_contrastive(I_emb = c(1, 2, 3, 4, 5, 6, 7, 8),
T_emb = c(1, 2, 3, 4, 5, 6, 7, 8), tau = 0.5)
#> $estimate
#> [1] 2.079442
#>
#> $loss
#> [1] 2.079442
#>
#> $loss_i2t
#> [1] 2.079442
#>
#> $loss_t2i
#> [1] 2.079442
#>
#> $similarity
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,] 1 1 1 1 1 1 1 1
#> [2,] 1 1 1 1 1 1 1 1
#> [3,] 1 1 1 1 1 1 1 1
#> [4,] 1 1 1 1 1 1 1 1
#> [5,] 1 1 1 1 1 1 1 1
#> [6,] 1 1 1 1 1 1 1 1
#> [7,] 1 1 1 1 1 1 1 1
#> [8,] 1 1 1 1 1 1 1 1
#>
#> $tau
#> [1] 0.5
#>
#> $n
#> [1] 8
#>
#> $method
#> [1] "Image-text contrastive (symmetric InfoNCE)"
#>