fix occasional precision failure of CosineEmbeddingLoss

This commit is contained in:
hedongdong 2021-03-18 15:54:45 +08:00
parent 0bd1e34a4d
commit b9a773955c
1 changed files with 1 additions and 1 deletions

View File

@ -909,7 +909,7 @@ class CosineEmbeddingLoss(_Loss):
prod_sum = self.reduce_sum(x1 * x2, (1,))
square1 = self.reduce_sum(F.square(x1), (1,))
square2 = self.reduce_sum(F.square(x2), (1,))
denom = F.sqrt(square1 * square2)
denom = F.sqrt(square1) * F.sqrt(square2)
cosine = prod_sum / denom
pos_value = 1.0 - cosine