Browse Source

update model (fix loss bug)

gongjy 2 years ago
parent
commit
a87f628400
1 changed files with 2 additions and 1 deletions
  1. 2 1
      model/model.py

+ 2 - 1
model/model.py

@@ -369,7 +369,8 @@ class Transformer(PreTrainedModel):
 
         if targets is not None:
             logits = self.output(h)
-            self.last_loss = F.cross_entropy(logits.view(-1, logits.size(-1)), targets.view(-1), ignore_index=-1)
+            self.last_loss = F.cross_entropy(logits.view(-1, logits.size(-1)), targets.view(-1),
+                                             ignore_index=0, reduction='none')
         else:
             logits = self.output(h[:, [-1], :])
             self.last_loss = None