class_docstr: Translate from one (source) language to another (target) language.
  
  Args:
      src_dict (~fairseq.data.Dictionary): dictionary for the source language
      tgt_dict (~fairseq.data.Dictionary): dictionary for the target language
  
  .. note::
  
      The translation task is compatible with :mod:`fairseq-train`,
      :mod:`fairseq-generate` and :mod:`fairseq-interactive`.
class_docstr_tok: ["Translate","from","one","(","source",")","language","to","another","(","target",")","language",".","Args",":","src_dict","(","~fairseq.data.Dictionary",")",":","dictionary","for","the","source","language","tgt_dict","(","~fairseq.data.Dictionary",")",":","dictionary","for","the","target","language","..","note",":",":","The","translation","task","is","compatible","with",":","mod",":","`","fairseq-train","`",",",":","mod",":","`","fairseq-generate","`","and",":","mod",":","`","fairseq-interactive","`","."]
code: def _inference_with_bleu(self, generator, sample, model):
      import sacrebleu
  
      def decode(toks, escape_unk=False):
          s = self.tgt_dict.string(
              toks.int().cpu(),
              self.cfg.eval_bleu_remove_bpe,
              # The default unknown string in fairseq is `<unk>`, but
              # this is tokenized by sacrebleu as `< unk >`, inflating
              # BLEU scores. Instead, we use a somewhat more verbose
              # alternative that is unlikely to appear in the real
              # reference, but doesn't get split into multiple tokens.
              unk_string=(
                  "UNKNOWNTOKENINREF"
                  if escape_unk
                  else "UNKNOWNTOKENINHYP"
              ),
          )
          if self.tokenizer:
              s = self.tokenizer.decode(s)
          return s
  
      gen_out = self.inference_step(
          generator, [model], sample, prefix_tokens=None
      )
      hyps, refs = [], []
      for i in range(len(gen_out)):
          hyps.append(decode(gen_out[i][0]["tokens"]))
          refs.append(
              decode(
                  utils.strip_pad(
                      sample["target"][i], self.tgt_dict.pad()
                  ),
                  escape_unk=True,  # don't count <unk> as matches to the hypo
              )
          )
      if self.cfg.eval_bleu_print_samples:
          logger.info("example hypothesis: " + hyps[0])
          logger.info("example reference: " + refs[0])
      if self.cfg.eval_tokenized_bleu:
          return sacrebleu.corpus_bleu(hyps, [refs], tokenize="none")
      else:
          return sacrebleu.corpus_bleu(hyps, [refs])
  
imports: from dataclasses import dataclass, field
  import itertools
  import json
  import logging
  import os
  from typing import Optional
  from argparse import Namespace
  from omegaconf import II
  import numpy
  from fairseq import utils
  from fairseq.logging import metrics
  from fairseq.data import AppendTokenDataset, ConcatDataset, LanguagePairDataset, PrependTokenDataset, StripTokenDataset, TruncateDataset, data_utils, encoders, indexed_dataset
  from fairseq.data.indexed_dataset import get_available_dataset_impl
  from fairseq.dataclass import ChoiceEnum, FairseqDataclass
  from fairseq.tasks import FairseqTask, register_task
label_desc: Use image node_id 11 for calling the TranslationTask obj's underlying member method code with example usage: obj._inference_with_bleu(generator, sample, model) and returns: s, sacrebleu, sacrebleu