code: def generate_score(
      args: argparse.Namespace,
      task: tasks.FairseqTask,
      dataset: data.FairseqDataset,
      models: List[FairseqEncoderDecoderModel],
      lang_pair: Optional[str] = None,
      modify_target_dict: bool = True,
  ):
      """
      Generation for single and multi model training
  
      Args:
          args: Command-line arguments.
          task: FairseqTask object.
          dataset: Dataset set object for a specific split for a specific model
          models: List[FairseqEncoderDecoderModel], an ensemble of models
          lang_pair: Optional model key in a multi model object. Specify None in
              single model set up
      """
      if (
          lang_pair
          and len(models) > 0
          and isinstance(models[0], FairseqMultiModel)
      ):
          if isinstance(dataset, data.RoundRobinZipDatasets):
              dataset = dataset.datasets[lang_pair]
          return _generate_score(
              models=[
                  multi_model.models[lang_pair]
                  for multi_model in models
              ],
              args=args,
              task=task,
              dataset=dataset,
              modify_target_dict=modify_target_dict,
          )
      elif (
          lang_pair
          and len(models) > 0
          and isinstance(models[0], DualLearningModel)
      ):
          # TODO: this could be refactored to use lang_pari as key too
          return _generate_score(
              models=[
                  multi_model.models["primal"]
                  if lang_pair == "primal_parallel"
                  else multi_model.models["dual"]
                  for multi_model in models
              ],
              args=args,
              task=task,
              dataset=dataset,
              modify_target_dict=modify_target_dict,
          )
  
      else:
          return _generate_score(
              models=models,
              args=args,
              task=task,
              dataset=dataset,
              modify_target_dict=modify_target_dict,
          )
  
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 1 for calling a global function with example usage: generate_score(args, task, dataset, models, lang_pair, modify_target_dict) and returns: _generate_score, _generate_score, _generate_score