code: def mock_translator(
      batch_size: int = 1,
      beam_size: int = 5,
      nbest_size: int = 1,
      num_source_factors: int = 1,
      dtype: pt.dtype = pt.float32,
  ):
      """
      Creates a fake translator object but with real values for things that we need.
      This lets us avoid a messy call to the constructor.
      """
      with patch.object(
          sockeye.inference.Translator,
          "__init__",
          lambda self, **kwargs: None,
      ):
          translator = sockeye.inference.Translator(
              device=None,
              batch_size=None,
              beam_size=None,
              ensemble_mode=None,
              scorer=None,
              beam_search_stop=None,
              nbest_size=None,
              models=None,
              source_vocabs=None,
              target_vocabs=None,
              restrict_lexicon=None,
              strip_unknown_words=None,
          )
  
          # This is needed for returning the right number of source factors
          def mock_model():
              t_mock = Mock(sockeye.model.SockeyeModel)
              t_mock.num_source_factors = num_source_factors
              t_mock.dtype = dtype
              return t_mock
  
          translator.batch_size = batch_size
          translator.beam_size = beam_size
          translator.nbest_size = nbest_size
          translator.models = [mock_model()]
          translator.dtype = translator.models[0].dtype
          translator.zeros_array = pt.zeros(beam_size, dtype=pt.int)
          translator.inf_array = pt.full(
              (batch_size * beam_size,),
              fill_value=np.inf,
              dtype=pt.float32,
          )
          translator.inf_array = translator.inf_array[:beam_size]
          translator.restrict_lexicon = None
          return translator
  
imports: import itertools
  import json
  from math import ceil
  from unittest.mock import patch, Mock
  import numpy
  import pytest
  import torch
  import sockeye.beam_search
  import sockeye.constants
  import sockeye.data_io
  import sockeye.inference
  import sockeye.lexicon
  import sockeye.model
  import sockeye.utils
label_desc: Use image node_id 1 for calling a global function with example usage: mock_translator(batch_size, beam_size, nbest_size, num_source_factors, dtype) and returns: translator, t_mock