Given two input tensors x1 and x2 with the shape [batch_size, hidden_size], let S be the matrix of similarity between all pairs (predict, target), where predict and target are dense vectors with the shape [hidden_size] and predict belongs to x1 and target belongs to x2.

Is there any loss function that is minimized as the values in the diagonal of S are close to 1 while the other values are close to -1?
That is, the similarity between the vectors from x1 and x2 of the same index must be greater than between vectors of different indexes.