That makes sense! Unfortunately I have no idea how to do that.
I tried:
    def forward(self, output1, output2, label):
        cos_sim = F.cosine_similarity(output1, output2)
        loss_cos_con = torch.mean((1-label) * torch.div(torch.pow((1.0-cos_sim), 2), 4) +
                                    (label) * torch.pow(cos_sim * torch.Tensor.float(torch.lt(cos_sim, self.margin)), 2))
        return loss_cos_con

but got the AttributeError listed above. How do I coerce the tensor?