code: def _apply_ins_masks(
      in_tokens, in_scores, mask_ins_pred, padding_idx, unk_idx, eos_idx
  ):
      in_masks = in_tokens.ne(padding_idx)
      in_lengths = in_masks.sum(1)
  
      # HACK: hacky way to shift all the paddings to eos first.
      in_tokens.masked_fill_(~in_masks, eos_idx)
      mask_ins_pred.masked_fill_(~in_masks[:, 1:], 0)
  
      out_lengths = in_lengths + mask_ins_pred.sum(1)
      out_max_len = out_lengths.max()
      out_masks = (
          new_arange(out_lengths, out_max_len)[None, :]
          < out_lengths[:, None]
      )
  
      reordering = (mask_ins_pred + in_masks[:, 1:].long()).cumsum(1)
      out_tokens = (
          in_tokens.new_zeros(in_tokens.size(0), out_max_len)
          .fill_(padding_idx)
          .masked_fill_(out_masks, unk_idx)
      )
      out_tokens[:, 0] = in_tokens[:, 0]
      out_tokens.scatter_(1, reordering, in_tokens[:, 1:])
  
      out_scores = None
      if in_scores is not None:
          in_scores.masked_fill_(~in_masks, 0)
          out_scores = in_scores.new_zeros(*out_tokens.size())
          out_scores[:, 0] = in_scores[:, 0]
          out_scores.scatter_(1, reordering, in_scores[:, 1:])
  
      return out_tokens, out_scores
  
file_path: fairseq/fairseq/models/nat/levenshtein_utils.py
imports: import torch
  from fairseq.utils import new_arange
label_desc: Use image node_id 4 for calling a global function with example usage: _apply_ins_masks(in_tokens, in_scores, mask_ins_pred, padding_idx, unk_idx, eos_idx) and returns: out_tokens,  out_scores