Skip to main content

infonce_loss

Function infonce_loss 

Source
pub fn infonce_loss(
    anchors: &[f64],
    positives: &[f64],
    n: usize,
    d: usize,
    temperature: f64,
) -> f64
Expand description

InfoNCE contrastive loss. van den Oord et al. (2018); CEBRA.

L = -(1/N) Σ_i log( exp(sim(z_i, z_i^+)/τ) / Σ_j exp(sim(z_i, z_j)/τ) ) where sim(a, b) = cosine similarity.

anchors, positives: [N × d] row-major flat.