code: def calc_banned_bad_words_ids(prev_input_ids, bad_words_ids):
      banned_tokens = []
  
      def _tokens_match(prev_tokens, tokens):
          if len(tokens) == 0:
              # if bad word tokens is just one token always ban it
              return True
          if len(tokens) > len(prev_tokens):
              # if bad word tokens are longer than prev tokens they can't be equal
              return False
  
          if prev_tokens[-len(tokens) :] == tokens:
              # if tokens match
              return True
          else:
              return False
  
      for prev_input_ids_slice in prev_input_ids:
          banned_tokens_slice = []
  
          for banned_token_seq in bad_words_ids:
              assert (
                  len(banned_token_seq) > 0
              ), f"Banned words token sequences { bad_words_ids} cannot have an empty list"
  
              if (
                  _tokens_match(
                      prev_input_ids_slice.numpy().tolist(),
                      banned_token_seq[:-1],
                  )
                  is False
              ):
                  # if tokens do not match continue
                  continue
  
              banned_tokens_slice.append(banned_token_seq[-1])
  
          banned_tokens.append(banned_tokens_slice)
  
      return banned_tokens
  
imports: import inspect
  import warnings
  from dataclasses import dataclass
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  import tensorflow
  from tensorflow.compiler.tf2xla.python.xla import dynamic_update_slice
  from .generation_tf_logits_process import TFForcedBOSTokenLogitsProcessor, TFForcedEOSTokenLogitsProcessor, TFForceTokensLogitsProcessor, TFLogitsProcessorList, TFMinLengthLogitsProcessor, TFNoBadWordsLogitsProcessor, TFNoRepeatNGramLogitsProcessor, TFRepetitionPenaltyLogitsProcessor, TFSuppressTokensAtBeginLogitsProcessor, TFSuppressTokensLogitsProcessor, TFTemperatureLogitsWarper, TFTopKLogitsWarper, TFTopPLogitsWarper
  from .models.auto import TF_MODEL_FOR_CAUSAL_LM_MAPPING, TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING, TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING, TF_MODEL_FOR_VISION_2_SEQ_MAPPING
  from .tf_utils import shape_list, stable_softmax
  from .utils import ModelOutput, logging
label_desc: Use image node_id 3 for calling a global function with example usage: calc_banned_bad_words_ids(prev_input_ids, bad_words_ids) and returns: banned_tokens, True, False, True, False