Compute the independent pairwise logistic loss for B aligned image-text pairs. Normalize every image or text embedding vector x by
x=max(∥x∥2,10−12)x.The norm is Euclidean, so a zero row remains zero. For image vector vi, text vector tj, supplied multiplier a, and bias b, the pair logit is
ℓij=aviTtj+b.The label zij is 1 for a matched diagonal pair and -1 otherwise. The loss is the mean over all image-text pairs:
L=−B21i=1∑Bj=1∑Blogσ(zijℓij).Here, i and j are pair indices, σ is the logistic sigmoid, and log is the natural logarithm. The supplied logit_scale is the multiplier a itself, not its logarithm.
Return a Python dictionary of PyTorch tensors: loss is a scalar; logits and pair_labels both have shape (B, B). All three outputs use the embedding floating dtype and device, including pair_labels.
Input: image_embeddings = [[1,0],[0,1]], text_embeddings = [[1,0],[0,1]], logit_scale = 2, bias = -1
Output: {"loss":0.313262,"logits":[[1,-1],[-1,1]],"pair_labels":[[1,-1],[-1,1]]}
Explanation: Every signed pair logit equals one, so all four logistic terms are equal.
Input: image_embeddings = [[3,4]], text_embeddings = [[6,8]], logit_scale = 10, bias = 0
Output: {"loss":0.000045,"logits":[[10]],"pair_labels":[[1]]}
Input: image_embeddings = [[1,0],[0,1]], text_embeddings = [[0,1],[1,0]], logit_scale = 2, bias = -0.5
Output: {"loss":1.337745,"logits":[[-0.5,1.5],[1.5,-0.5]],"pair_labels":[[1,-1],[-1,1]]}
torch.nn.functional.normalize bounds the normalization denominator.
Tensor.fill_diagonal_ updates the diagonal of a newly created matrix.
torch.nn.functional.logsigmoid evaluates log-sigmoid stably.
Accepts: array
Accepts: array
Accepts: number
Accepts: number
Compute the independent pairwise logistic loss for B aligned image-text pairs. Normalize every image or text embedding vector x by
x=max(∥x∥2,10−12)x.The norm is Euclidean, so a zero row remains zero. For image vector vi, text vector tj, supplied multiplier a, and bias b, the pair logit is
ℓij=aviTtj+b.The label zij is 1 for a matched diagonal pair and -1 otherwise. The loss is the mean over all image-text pairs:
L=−B21i=1∑Bj=1∑Blogσ(zijℓij).Here, i and j are pair indices, σ is the logistic sigmoid, and log is the natural logarithm. The supplied logit_scale is the multiplier a itself, not its logarithm.
Return a Python dictionary of PyTorch tensors: loss is a scalar; logits and pair_labels both have shape (B, B). All three outputs use the embedding floating dtype and device, including pair_labels.
Input: image_embeddings = [[1,0],[0,1]], text_embeddings = [[1,0],[0,1]], logit_scale = 2, bias = -1
Output: {"loss":0.313262,"logits":[[1,-1],[-1,1]],"pair_labels":[[1,-1],[-1,1]]}
Explanation: Every signed pair logit equals one, so all four logistic terms are equal.
Input: image_embeddings = [[3,4]], text_embeddings = [[6,8]], logit_scale = 10, bias = 0
Output: {"loss":0.000045,"logits":[[10]],"pair_labels":[[1]]}
Input: image_embeddings = [[1,0],[0,1]], text_embeddings = [[0,1],[1,0]], logit_scale = 2, bias = -0.5
Output: {"loss":1.337745,"logits":[[-0.5,1.5],[1.5,-0.5]],"pair_labels":[[1,-1],[-1,1]]}
torch.nn.functional.normalize bounds the normalization denominator.
Tensor.fill_diagonal_ updates the diagonal of a newly created matrix.
torch.nn.functional.logsigmoid evaluates log-sigmoid stably.
Accepts: array
Accepts: array
Accepts: number
Accepts: number