code: def translate_text(
      models,
      args,
      src_text,
      tgt_text,
      tgt_text_all,
      src_texts,
      all_scores,
      all_timing,
      ensemble_generator,
  ):
      if len(models) > 1:
          src_ids, src_mask = models[0].prepare_inference_batch(
              src_text
          )
          best_translations = ensemble_generator(
              src_ids, src_mask, return_beam_scores=args.write_scores
          )
          if args.write_scores:
              all_results, scores, best_translations = (
                  best_translations[0],
                  best_translations[1],
                  best_translations[2],
              )
              scores = scores.view(-1).data.cpu().numpy().tolist()
              all_scores += scores
              src_texts += [
                  item
                  for item in src_text
                  for i in range(args.beam_size)
              ]
              all_results = models[0].ids_to_postprocessed_text(
                  all_results,
                  models[0].decoder_tokenizer,
                  models[0].target_processor,
              )
              tgt_text_all += all_results
          best_translations = models[0].ids_to_postprocessed_text(
              best_translations,
              models[0].decoder_tokenizer,
              models[0].target_processor,
          )
          tgt_text += best_translations
      else:
          model = models[0]
          best_translations = model.translate(
              text=src_text,
              source_lang=args.source_lang,
              target_lang=args.target_lang,
              return_beam_scores=args.write_scores,
              log_timing=args.write_timing,
          )
  
          if args.write_timing:
              *best_translations, timing_dict = best_translations
              all_timing.append(timing_dict)
          else:
              best_translations = (best_translations,)
  
          if args.write_scores:
              all_results, scores, best_translations = (
                  best_translations[0],
                  best_translations[1],
                  best_translations[2],
              )
              all_scores += scores
              src_texts += [
                  item
                  for item in src_text
                  for i in range(args.beam_size)
              ]
              tgt_text_all += all_results
          else:
              best_translations = best_translations[0]
  
          tgt_text += best_translations
  
      print(f"Translated {len(tgt_text)} sentences")
  
imports: import json
  from argparse import ArgumentParser
  import torch
  import nemo.collections.nlp
  from nemo.collections.nlp.modules.common.transformer import BeamSearchSequenceGenerator, BeamSearchSequenceGeneratorWithLanguageModel, EnsembleBeamSearchSequenceGenerator
  from nemo.utils import logging
label_desc: Use image node_id 1 for calling a global function with example usage: translate_text(models, args, src_text, tgt_text, tgt_text_all, src_texts, all_scores, all_timing, ensemble_generator) without return types