code: def test_lm_head_model_random_no_beam_search_generate(self):
      (
          config,
          inputs_dict,
      ) = self.model_tester.prepare_config_and_inputs_for_common()
      input_features = inputs_dict.get("input_features", None)
  
      # iterate over all generative models
      for model_class in self.all_generative_model_classes:
          model = model_class(config)
  
          if config.bos_token_id is None:
              # if bos token id is not defined model needs input_features
              with self.assertRaises(AssertionError):
                  model.generate(do_sample=True, max_length=5)
              # num_return_sequences = 1
              self._check_generated_ids(
                  model.generate(input_features, do_sample=True)
              )
  
          with self.assertRaises(ValueError):
              # generating multiple sequences when no beam search generation
              # is not allowed as it would always generate the same sequences
              model.generate(
                  input_features,
                  do_sample=False,
                  num_return_sequences=2,
              )
  
          # num_return_sequences > 1, sample
          self._check_generated_ids(
              model.generate(
                  input_features, do_sample=True, num_return_sequences=2
              )
          )
  
          # check bad words tokens language generation
          # create list of 1-seq bad token and list of 2-seq of bad tokens
          bad_words_ids = [
              self._generate_random_bad_tokens(1, model),
              self._generate_random_bad_tokens(2, model),
          ]
          output_tokens = model.generate(
              input_features,
              do_sample=True,
              bad_words_ids=bad_words_ids,
              num_return_sequences=2,
          )
          # only count generated tokens
          generated_ids = output_tokens[:, input_features.shape[-1] :]
          self.assertFalse(
              self._check_match_tokens(
                  generated_ids.numpy().tolist(), bad_words_ids
              )
          )
  
imports: import inspect
  import unittest
  from transformers import Speech2TextConfig
  from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow
  from transformers.utils import cached_property, is_tf_available
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
label_desc: Use image node_id 16 for calling the TFSpeech2TextModelTest obj's underlying member method code with example usage: obj.test_lm_head_model_random_no_beam_search_generate() without return types