NTXentLoss<T>
Models & Types · AiDotNet.SelfSupervisedLearning.Losses
Normalized Temperature-scaled Cross Entropy Loss (NT-Xent) for contrastive learning.
Inheritance: ContrastiveLossBase<T> → NTXentLoss<T>
For Beginners
NT-Xent is the loss function used in SimCLR. It encourages representations of augmented views of the same image to be similar, while pushing apart representations of different images.
How It Works
How it works:
Loss formula:
Where τ (tau) is the temperature parameter.
Constructors
| Constructor | Summary |
|---|---|
NTXentLoss(double temperature, bool normalize) |
Initializes a new instance of the NTXentLoss class. |
Properties
| Property | Summary |
|---|---|
double Temperature { get; } |
Gets the temperature parameter. |
Methods
| Method | Summary |
|---|---|
Tensor<T> ComputeLoss(Tensor<T> z1, Tensor<T> z2) |
Computes the NT-Xent loss for a batch of positive pairs. |
ValueTuple<T, Tensor<T>, Tensor<T>> ComputeLossWithGradients(Tensor<T> z1, Tensor<T> z2) |
Computes the NT-Xent loss and returns gradients. |