jonna32 commited on
Commit
3c0fc01
1 Parent(s): 01443ae

Ignore padding in loss method

Browse files
Files changed (1) hide show
  1. modeling_gpt_optimized.py +1 -1
modeling_gpt_optimized.py CHANGED
@@ -195,5 +195,5 @@ class GPTOptim(GPT2PreTrainedModel):
195
  logits = self.model.lm_head(x) # (B, T, vocab_size)
196
  loss = None
197
  if labels is not None:
198
- loss = F.cross_entropy(logits.view(-1, logits.size(-1)), labels.view(-1))
199
  return logits, loss
 
195
  logits = self.model.lm_head(x) # (B, T, vocab_size)
196
  loss = None
197
  if labels is not None:
198
+ loss = F.cross_entropy(logits.view(-1, logits.size(-1)), labels.view(-1), ignore_index=config.eos_token_id)
199
  return logits, loss