Implement the NT-Xent (Normalized Temperature-scaled Cross-Entropy) contrastive loss function, commonly known as the SimCLR contrastive loss or InfoNCE loss.
This loss is the backbone of self-supervised contrastive learning frameworks. Given a batch of 2N embedding vectors where each consecutive pair (2i, 2i+1) represents two augmented views of the same input sample, the goal is to push representations of the same sample closer together while pushing representations of different samples apart.
Your function receives:
The function should:
Use the log-sum-exp trick for numerical stability when computing the log of the sum of exponentials.