Realm

oa::ml::loss::cosine_embedding

Compute the cosine embedding loss over [N, D] pairs. Rows with target == 1 contribute 1 - cos(x1, x2); rows with target == -1 contribute max(0, cos(x1, x2) - margin). target is an [N, 1] ±1 mask. Errors Returns an error for mismatched, empty, non-rank-two, or non-FP32 inputs, or when runtime recording fails.

FnRust public API

Function Documentation

pub fn cosine_embedding( input1: &Matrix, input2: &Matrix, target: &Matrix, margin: f32 ) -> Result<Matrix>
Compute the cosine embedding loss over [N, D] pairs. Rows with target == 1 contribute 1 - cos(x1, x2); rows with target == -1 contribute max(0, cos(x1, x2) - margin). target is an [N, 1] ±1 mask. Errors Returns an error for mismatched, empty, non-rank-two, or non-FP32 inputs, or when runtime recording fails.