
Contrastive learning with in-batch negatives (hmcst)
Source:R/geron_w4a_native.R
morie_geron_contrastive_learning.RdDelegates the InfoNCE loss to morie_geron_contrastive_infonce; this
wrapper builds the negative set from positives (every other row of
the batch except the anchor and its positive).
Value
List with loss, per_anchor_loss, pos_sim, neg_sim,
hardest_negative, accuracy, chance_loss, n_negatives.
Examples
morie_geron_contrastive_learning(matrix(c(1, 0, 1, 0, 0, 1),
3, 2, byrow = TRUE), c(1, 0, 0), tau = 1)
#> $loss
#> [1] 0.4398902
#>
#> $per_anchor_loss
#> [1] 0.3132617 0.3132617 0.6931472
#>
#> $pos_sim
#> [1] 1 1 0
#>
#> $neg_sim
#> [,1]
#> [1,] 0
#> [2,] 0
#> [3,] 0
#>
#> $hardest_negative
#> [1] 0 0 0
#>
#> $accuracy
#> [1] 1
#>
#> $chance_loss
#> [1] 0.6931472
#>
#> $n_negatives
#> [1] 1
#>
#> $negative_indices
#> $negative_indices[[1]]
#> [1] 2
#>
#> $negative_indices[[2]]
#> [1] 2
#>
#> $negative_indices[[3]]
#> [1] 1
#>
#>
#> $tau
#> [1] 1
#>
#> $estimate
#> [1] 0.4398902
#>
#> $n
#> [1] 3
#>
#> $method
#> [1] "InfoNCE with in-batch negatives; loss delegated to grctr"
#>