code: def generate(args):
      pytorch_translate_options.print_args(args)
  
      (
          models,
          model_args,
          task,
      ) = pytorch_translate_utils.load_diverse_ensemble_for_inference(
          args.path.split(CHECKPOINT_PATHS_DELIMITER)
      )
      args.source_lang = model_args[0].source_lang
      args.target_lang = model_args[0].target_lang
  
      append_eos_to_source = model_args[0].append_eos_to_source
      reverse_source = model_args[0].reverse_source
      assert all(
          a.append_eos_to_source == append_eos_to_source
          and a.reverse_source == reverse_source
          for a in model_args
      )
      if args.source_binary_file != "":
          assert args.target_binary_file != ""
          if isinstance(task, PytorchTranslateTask):
              task.load_dataset(
                  args.gen_subset,
                  args.source_binary_file,
                  args.target_binary_file,
                  is_npz=args.is_npz,
              )
          else:
              task.load_dataset(
                  args.gen_subset,
                  args.source_binary_file,
                  args.target_binary_file,
              )
      elif pytorch_translate_data.is_multilingual_many_to_one(args):
          task.set_encoder_langs(model_args[0].multiling_encoder_lang)
          task.set_decoder_langs(model_args[0].multiling_decoder_lang)
          task.load_dataset_from_text_multilingual(
              args.gen_subset,
              source_text_file=args.source_text_file[0],
              target_text_file=args.target_text_file,
              source_lang_id=task.get_encoder_lang_id(
                  args.multiling_source_lang[0]
              ),
              target_lang_id=task.get_decoder_lang_id(
                  args.multiling_target_lang[0]
              ),
              append_eos=append_eos_to_source,
              reverse_source=reverse_source,
          )
      elif args.source_ensembling:
          task.load_multisource_dataset_from_text(
              args.gen_subset,
              source_text_files=args.source_text_file,
              target_text_file=args.target_text_file,
              append_eos=append_eos_to_source,
              reverse_source=reverse_source,
          )
      else:
          task.load_dataset_from_text(
              args.gen_subset,
              source_text_file=args.source_text_file[0],
              target_text_file=args.target_text_file,
              append_eos=append_eos_to_source,
              reverse_source=reverse_source,
          )
  
      lang_pair = None
      if isinstance(task, PyTorchTranslateMultiTask):
          if args.source_lang and args.target_lang:
              lang_pair = args.source_lang + "-" + args.target_lang
          else:
              lang_pair = "src-tgt"
      scorer, num_sentences, gen_timer, _ = generate_score(
          args=args,
          task=task,
          dataset=task.dataset(args.gen_subset),
          lang_pair=lang_pair,
          models=models,
      )
      print(
          f"| Translated {num_sentences} sentences ({gen_timer.n} tokens) "
          f"in {gen_timer.sum:.1f}s ({1. / gen_timer.avg:.2f} tokens/s)"
      )
      print(
          f"| Generate {args.gen_subset} with beam={args.beam}: "
          f"{scorer.result_string()}"
      )
      return scorer.score()
  
imports: import argparse
  import collections
  import os
  import pickle
  from typing import List, NamedTuple, Optional
  import numpy
  import torch
  from fairseq import data, iterative_refinement_generator, options, progress_bar, tasks, utils
  from fairseq.meters import StopwatchMeter, TimeMeter
  from fairseq.models import FairseqEncoderDecoderModel, FairseqMultiModel
  from fairseq.scoring import bleu
  from pytorch_translate import beam_decode, char_aware_hybrid, char_source_hybrid, char_source_model, char_source_transformer_model, hybrid_transformer_rnn, options, rnn, transformer, utils
  from pytorch_translate.constants import CHECKPOINT_PATHS_DELIMITER
  from pytorch_translate.data import data
  from pytorch_translate.dual_learning.dual_learning_models import DualLearningModel
  from pytorch_translate.research.beam_search import competing_completed
  from pytorch_translate.research.multisource import multisource_data, multisource_decode
  from pytorch_translate.tasks.pytorch_translate_multi_task import PyTorchTranslateMultiTask
  from pytorch_translate.tasks.pytorch_translate_task import PytorchTranslateTask
label_desc: Use image node_id 10 for calling a global function with example usage: generate(args) and returns: scorer