class_docstr: Scores p(x|y) with a reverse model and switching src and tgt sentences
docstr: For reverse model, we need to switch src_tokens and tgt_tokens.
  We also make sure source is reversed if original task vs new task
  has different reverse_source settings.
docstr_tok: ["For","reverse","model",",","we","need","to","switch","src_tokens","and","tgt_tokens",".","We","also","make","sure","source","is","reversed","if","original","task","vs","new","task","has","different","reverse_source","settings","."]
code: def prepare_inputs(self, src_tokens, hypos):
      """
      For reverse model, we need to switch src_tokens and tgt_tokens.
      We also make sure source is reversed if original task vs new task
      has different reverse_source settings.
      """
      eos = self.task.target_dictionary.eos()
  
      # Prepare target tokens
      # Map token ids from original dictionary to reverse model dictionary
      src_string = self.forward_task.src_dict.string(src_tokens)
      src_tokens_mapped = self.task.tgt_dict.encode_line(
          src_string, add_if_not_exist=False
      )[
          :-1
      ]  # remove eos
      # Swap target and source tokens with necessary modifications
      tgt_tokens = (
          torch.cat(
              (
                  torch.tensor([eos]).type_as(src_tokens_mapped),
                  reversed(src_tokens_mapped)
                  if self.forward_task.args.reverse_source
                  else src_tokens_mapped,
                  torch.tensor([eos]).type_as(src_tokens_mapped),
              ),
              dim=0,
          )
          .view(1, -1)
          .type_as(src_tokens)
      )
      # In reverse model, tgt_tokens are repeated instead of source
      tgt_tokens = tgt_tokens.repeat(len(hypos), 1)
  
      # Prepare source tokens
      max_tgt_len = max(len(hypo["tokens"]) for hypo in hypos)
      if not self.args.append_eos_to_source:
          max_tgt_len -= 1  # no eos
      pad = self.task.target_dictionary.pad()
      src_tokens = torch.full(
          (len(hypos), max_tgt_len), fill_value=pad, dtype=torch.long
      ).type_as(tgt_tokens)
  
      src_lengths = torch.zeros(len(hypos)).type_as(src_tokens)
      for i, hypo in enumerate(hypos):
          tgt_string = self.forward_task.tgt_dict.string(hypo["tokens"])
          tgt_tokens_mapped = self.task.src_dict.encode_line(
              tgt_string, add_if_not_exist=False
          )
          if not self.args.append_eos_to_source:
              tgt_tokens_mapped = tgt_tokens_mapped[
                  :-1
              ]  # last token is eos
  
          src_lengths[i] = len(tgt_tokens_mapped)
          src_tokens[i, : len(tgt_tokens_mapped)] = (
              reversed(tgt_tokens_mapped)
              if self.task.args.reverse_source
              else tgt_tokens_mapped
          )
  
      encoder_inputs = (src_tokens, src_lengths)
      return encoder_inputs, tgt_tokens
  
imports: import torch
  from pytorch_translate import utils
label_desc: Use image node_id 1 for calling the ReverseModelScorer obj's underlying member method code with example usage: obj.prepare_inputs(src_tokens, hypos) and returns: encoder_inputs,  tgt_tokens