Raghavan commited on
Commit
140295b
1 Parent(s): 02d1844

Upload 7 files

Browse files
Files changed (1) hide show
  1. modeling_indictrans.py +5 -3
modeling_indictrans.py CHANGED
@@ -61,11 +61,12 @@ def shift_tokens_right(input_ids: torch.Tensor, pad_token_id: int, decoder_start
61
 
62
 
63
  def prepare_decoder_input_ids_label(decoder_input_ids, decoder_attention_mask):
64
- labels = decoder_input_ids[:, 1:]
65
-
 
66
  labels_mask = labels == 1
67
  labels[labels_mask] = -100
68
-
69
  mask = (decoder_input_ids == eos_token_id)
70
  decoder_input_ids[mask] = 1
71
  decoder_attention_mask[mask] = 0
@@ -75,6 +76,7 @@ def prepare_decoder_input_ids_label(decoder_input_ids, decoder_attention_mask):
75
  return decoder_input_ids, decoder_attention_mask, labels
76
 
77
 
 
78
  # Copied from transformers.models.bart.modeling_bart._make_causal_mask
79
  def _make_causal_mask(
80
  input_ids_shape: torch.Size, dtype: torch.dtype, device: torch.device, past_key_values_length: int = 0
 
61
 
62
 
63
  def prepare_decoder_input_ids_label(decoder_input_ids, decoder_attention_mask):
64
+ labels = decoder_input_ids.full_size(decoder_input_ids.size(), -100)
65
+ labels[:, :-1] = decoder_input_ids[:, 1:]
66
+
67
  labels_mask = labels == 1
68
  labels[labels_mask] = -100
69
+
70
  mask = (decoder_input_ids == eos_token_id)
71
  decoder_input_ids[mask] = 1
72
  decoder_attention_mask[mask] = 0
 
76
  return decoder_input_ids, decoder_attention_mask, labels
77
 
78
 
79
+
80
  # Copied from transformers.models.bart.modeling_bart._make_causal_mask
81
  def _make_causal_mask(
82
  input_ids_shape: torch.Size, dtype: torch.dtype, device: torch.device, past_key_values_length: int = 0