class_docstr: R2L model works by reversing target tokens to right to left direction
docstr: tgt_tokens has paddings to the right since they are batched.
  while reversing, we should roll first to keep paddings.
  
  Note:
      input:
          [1 2 3]
          [1 2 0]
          [1 0 0]
      output:
          [3 2 1]
          [2 1 0]
          [1 0 0]
docstr_tok: ["tgt_tokens","has","paddings","to","the","right","since","they","are","batched",".","while","reversing",",","we","should","roll","first","to","keep","paddings",".","Note",":","input",":","[","1","2","3","]","[","1","2","0","]","[","1","0","0","]","output",":","[","3","2","1","]","[","2","1","0","]","[","1","0","0","]"]
code: def reverse_tgt_tokens(self, tgt_tokens):
      """
      tgt_tokens has paddings to the right since they are batched.
      while reversing, we should roll first to keep paddings.
  
      Note:
          input:
              [1 2 3]
              [1 2 0]
              [1 0 0]
          output:
              [3 2 1]
              [2 1 0]
              [1 0 0]
      """
      reversed_tgt_tokens = torch.zeros_like(tgt_tokens)
  
      def roll(x, n):
          return torch.cat((x[-n:], x[:-n]))
  
      pad = self.task.tgt_dict.pad()
      for i, row in enumerate(tgt_tokens):
          pad_count = torch.sum(row == pad)
          reversed_tgt_tokens[i] = reversed(roll(row, int(pad_count)))
  
      return reversed_tgt_tokens
  
imports: import torch
  from pytorch_translate import utils
label_desc: Use image node_id 1 for calling the R2LModelScorer obj's underlying member method code with example usage: obj.reverse_tgt_tokens(tgt_tokens) and returns: reversed_tgt_tokens, torch