
InfoNCE contrastive loss (Geron Ch 16, morie.fn grctr)
Source:R/geron_ml_native.R
morie_geron_contrastive_infonce.RdCross-entropy over 1 positive and N negatives; chance loss log(1+N).
Examples
morie_geron_contrastive_infonce(anchors = matrix(c(1, 2, 3, 4, 5, 6), nrow = 2),
positives = matrix(c(1, 2, 3, 4, 5, 6), nrow = 2),
negatives = matrix(c(1, 2, 3, 4, 5, 6), nrow = 2))
#> $loss
#> [1] 1.078557
#>
#> $per_anchor_loss
#> [1] 1.078557 1.078557
#>
#> $pos_sim
#> [1] 1 1
#>
#> $neg_sim
#> [,1] [,2]
#> [1,] 1.0000000 0.9938587
#> [2,] 0.9938587 1.0000000
#>
#> $hardest_negative
#> [1] 1 1
#>
#> $accuracy
#> [1] 1
#>
#> $chance_loss
#> [1] 1.098612
#>
#> $tau
#> [1] 0.1
#>
#> $estimate
#> [1] 1.078557
#>
#> $n
#> [1] 2
#>
#> $method
#> [1] "InfoNCE contrastive loss"
#>