Hi,
I want to define a function that will calculate the cosine distance between two normalized vectors v1 and v2 is defined as 1 - dot_product(v1, v2) in pytorch.
def     cosine_distance (f_x, f_y):
        f_xx_normalized  = F.normalize(f_x, p=2, dim=1)
        f_yy_normalized  = F.normalize(f_y, p=2, dim=1)
        f_yy_normalized_transpose = f_yy_normalized.transpose(0,1)    
        cosine_loss = 1 - torch.sum(torch.mm(f_xx_normalized, f_yy_normalized_transpose ))
        return cosine_loss

The expected loss would be 0 < cosine_loss <1, but I got the loss approximately -90.78. Is it working ? I am confused.