import torch


def get_valid_negative_mask(labels):
	"""
	To be a valid negative pair (a,n),
		- a and n are different embeddings
		- a and n have the different label
	"""
	indices_equal = torch.eye(labels.size(0)).byte()
	indices_not_equal = ~indices_equal

	label_not_equal = torch.ne(labels.unsqueeze(1), labels.unsqueeze(0))

	mask = indices_not_equal & label_not_equal
	return mask