docstr: Implements TFRAG token decoding.
  
  Args:
      input_ids (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
          The sequence used as a prompt for the generation. If `input_ids` is not passed, then
          `context_input_ids` has to be provided.
      attention_mask (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
          Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
  
          - 1 for tokens that are **not masked**,
          - 0 for tokens that are **masked**.
  
          [What are attention masks?](../glossary#attention-mask)
      context_input_ids (`tf.Tensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
          Input IDs post-processed from the retrieved documents and the question encoder `input_ids` by the
          retriever.
  
          If the model has is not initialized with a `retriever`, `context_input_ids` has to be provided to the
          forward pass. `context_input_ids` are returned by [`~RagRetriever.__call__`].
      context_attention_mask (`tf.Tensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
          Attention mask post-processed from the retrieved documents and the question encoder `input_ids` by the
          retriever.
  
          If the model has is not initialized with a `retriever`, `context_input_ids` has to be provided to the
          forward pass. `context_input_ids` are returned by [`~RagRetriever.__call__`].
      doc_scores (`tf.Tensor` of shape `(batch_size, config.n_docs)`):
          Score between each retrieved document embeddings (see `retrieved_doc_embeds`) and
          `question_encoder_last_hidden_state`.
  
          If the model has is not initialized with a `retriever`, `context_input_ids` has to be provided to the
          forward pass. `context_input_ids` are returned by [`~RagRetriever.__call__`].
      max_length (`int`, *optional*, defaults to 20):
          The maximum length of the sequence to be generated.
      min_length (`int`, *optional*, defaults to 10):
          The minimum length of the sequence to be generated.
      early_stopping (`bool`, *optional*, defaults to `False`):
          Whether or not to stop the beam search when at least `num_beams` sentences are finished per batch or
          not.
      use_cache: (`bool`, *optional*, defaults to `True`):
          Whether or not the model should use the past last key/values attentions (if applicable to the model) to
          speed up decoding.
      pad_token_id (`int`, *optional*):
          The id of the *padding* token.
      bos_token_id (`int`, *optional*):
          The id of the *beginning-of-sequence* token.
      eos_token_id (`int`, *optional*):
          The id of the *end-of-sequence* token.
      length_penalty (`float`, *optional*, defaults to 1.0):
          Exponential penalty to the length that is used with beam-based generation. It is applied as an exponent
          to the sequence length, which in turn is used to divide the score of the sequence. Since the score is
          the log likelihood of the sequence (i.e. negative), `length_penalty` > 0.0 promotes longer sequences,
          while `length_penalty` < 0.0 encourages shorter sequences.
      no_repeat_ngram_size (`int`, *optional*, defaults to 0):
          If set to int > 0, all ngrams of that size can only occur once.
      bad_words_ids(`List[int]`, *optional*):
          List of token ids that are not allowed to be generated. In order to get the tokens of the words that
          should not appear in the generated text, use `tokenizer.encode(bad_word, add_prefix_space=True)`.
      num_beams (`int`, *optional*, defaults to 1):
          Number of beams for beam search. 1 means no beam search.
      num_return_sequences(`int`, *optional*, defaults to 1):
          The number of independently computed returned sequences for each element in the batch. Note that this
          is not the value we pass to the `generator`'s `[`~generation_utils.GenerationMixin.generate`] function,
          where we set `num_return_sequences` to `num_beams`. decoder_start_token_id (`int`, *optional*): If an
          encoder-decoder model starts decoding with a different token than *bos*, the id of that token.
      n_docs (`int`, *optional*, defaults to `config.n_docs`)
          Number of documents to retrieve and/or number of documents for which to generate an answer.
      output_attentions (`bool`, *optional*, defaults to `False`):
          Whether or not to return the attentions tensors of all attention layers. See `attentions` under
          returned tensors for more details.
      output_hidden_states (`bool`, *optional*, defaults to `False`):
          Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
          for more details.
      output_scores (`bool`, *optional*, defaults to `False`):
          Whether or not to return the prediction scores. See `scores` under returned tensors for more details.
      return_dict_in_generate (`bool`, *optional*, defaults to `False`):
          Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
      model_specific_kwargs:
          Additional model specific kwargs will be forwarded to the `forward` function of the model.
  
  Return:
      `tf.Tensor` of shape `(batch_size * num_return_sequences, sequence_length)`: The generated sequences. The
      second dimension (sequence_length) is either equal to `max_length` or shorter if all batches finished early
      due to the `eos_token_id`.
docstr_tok: ["Implements","TFRAG","token","decoding",".","Args",":","input_ids","(","`","tf.Tensor","`","of","shape","`","(","batch_size",",","sequence_length",")","`",",","*","optional","*",")",":","The","sequence","used","as","a","prompt","for","the","generation",".","If","`","input_ids","`","is","not","passed",",","then","`","context_input_ids","`","has","to","be","provided",".","attention_mask","(","`","tf.Tensor","`","of","shape","`","(","batch_size",",","sequence_length",")","`",",","*","optional","*",")",":","Mask","to","avoid","performing","attention","on","padding","token","indices",".","Mask","values","selected","in","`","[","0",",","1","]","`",":","-","1","for","tokens","that","are","*","*","not","masked","*","*",",","-","0","for","tokens","that","are","*","*","masked","*","*",".","[","What","are","attention","masks","?","]","(","..","\/glossary","#","attention-mask",")","context_input_ids","(","`","tf.Tensor","`","of","shape","`","(","batch_size","*","config.n_docs",",","config.max_combined_length",")","`",",","*","optional","*",",","returned","when","*","output_retrieved=True","*",")",":","Input","IDs","post-processed","from","the","retrieved","documents","and","the","question","encoder","`","input_ids","`","by","the","retriever",".","If","the","model","has","is","not","initialized","with","a","`","retriever","`",",","`","context_input_ids","`","has","to","be","provided","to","the","forward","pass",".","`","context_input_ids","`","are","returned","by","[","`","~RagRetriever.__call__","`","]",".","context_attention_mask","(","`","tf.Tensor","`","of","shape","`","(","batch_size","*","config.n_docs",",","config.max_combined_length",")","`",",","*","optional","*",",","returned","when","*","output_retrieved=True","*",")",":","Attention","mask","post-processed","from","the","retrieved","documents","and","the","question","encoder","`","input_ids","`","by","the","retriever",".","If","the","model","has","is","not","initialized","with","a","`","retriever","`",",","`","context_input_ids","`","has","to","be","provided","to","the","forward","pass",".","`","context_input_ids","`","are","returned","by","[","`","~RagRetriever.__call__","`","]",".","doc_scores","(","`","tf.Tensor","`","of","shape","`","(","batch_size",",","config.n_docs",")","`",")",":","Score","between","each","retrieved","document","embeddings","(","see","`","retrieved_doc_embeds","`",")","and","`","question_encoder_last_hidden_state","`",".","If","the","model","has","is","not","initialized","with","a","`","retriever","`",",","`","context_input_ids","`","has","to","be","provided","to","the","forward","pass",".","`","context_input_ids","`","are","returned","by","[","`","~RagRetriever.__call__","`","]",".","max_length","(","`","int","`",",","*","optional","*",",","defaults","to","20",")",":","The","maximum","length","of","the","sequence","to","be","generated",".","min_length","(","`","int","`",",","*","optional","*",",","defaults","to","10",")",":","The","minimum","length","of","the","sequence","to","be","generated",".","early_stopping","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","or","not","to","stop","the","beam","search","when","at","least","`","num_beams","`","sentences","are","finished","per","batch","or","not",".","use_cache",":","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","or","not","the","model","should","use","the","past","last","key\/values","attentions","(","if","applicable","to","the","model",")","to","speed","up","decoding",".","pad_token_id","(","`","int","`",",","*","optional","*",")",":","The","id","of","the","*","padding","*","token",".","bos_token_id","(","`","int","`",",","*","optional","*",")",":","The","id","of","the","*","beginning-of-sequence","*","token",".","eos_token_id","(","`","int","`",",","*","optional","*",")",":","The","id","of","the","*","end-of-sequence","*","token",".","length_penalty","(","`","float","`",",","*","optional","*",",","defaults","to","1.0",")",":","Exponential","penalty","to","the","length","that","is","used","with","beam-based","generation",".","It","is","applied","as","an","exponent","to","the","sequence","length",",","which","in","turn","is","used","to","divide","the","score","of","the","sequence",".","Since","the","score","is","the","log","likelihood","of","the","sequence","(","i.e",".","negative",")",",","`","length_penalty","`",">","0.0","promotes","longer","sequences",",","while","`","length_penalty","`","<","0.0","encourages","shorter","sequences",".","no_repeat_ngram_size","(","`","int","`",",","*","optional","*",",","defaults","to","0",")",":","If","set","to","int",">","0",",","all","ngrams","of","that","size","can","only","occur","once",".","bad_words_ids","(","`","List","[","int","]","`",",","*","optional","*",")",":","List","of","token","ids","that","are","not","allowed","to","be","generated",".","In","order","to","get","the","tokens","of","the","words","that","should","not","appear","in","the","generated","text",",","use","`","tokenizer.encode","(","bad_word",",","add_prefix_space=True",")","`",".","num_beams","(","`","int","`",",","*","optional","*",",","defaults","to","1",")",":","Number","of","beams","for","beam","search",".","1","means","no","beam","search",".","num_return_sequences","(","`","int","`",",","*","optional","*",",","defaults","to","1",")",":","The","number","of","independently","computed","returned","sequences","for","each","element","in","the","batch",".","Note","that","this","is","not","the","value","we","pass","to","the","`","generator","`","'s","`","[","`","~generation_utils.GenerationMixin.generate","`","]","function",",","where","we","set","`","num_return_sequences","`","to","`","num_beams","`",".","decoder_start_token_id","(","`","int","`",",","*","optional","*",")",":","If","an","encoder-decoder","model","starts","decoding","with","a","different","token","than","*","bos","*",",","the","id","of","that","token",".","n_docs","(","`","int","`",",","*","optional","*",",","defaults","to","`","config.n_docs","`",")","Number","of","documents","to","retrieve","and\/or","number","of","documents","for","which","to","generate","an","answer",".","output_attentions","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","or","not","to","return","the","attentions","tensors","of","all","attention","layers",".","See","`","attentions","`","under","returned","tensors","for","more","details",".","output_hidden_states","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","or","not","to","return","the","hidden","states","of","all","layers",".","See","`","hidden_states","`","under","returned","tensors","for","more","details",".","output_scores","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","or","not","to","return","the","prediction","scores",".","See","`","scores","`","under","returned","tensors","for","more","details",".","return_dict_in_generate","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","or","not","to","return","a","[","`","~utils.ModelOutput","`","]","instead","of","a","plain","tuple",".","model_specific_kwargs",":","Additional","model","specific","kwargs","will","be","forwarded","to","the","`","forward","`","function","of","the","model",".","Return",":","`","tf.Tensor","`","of","shape","`","(","batch_size","*","num_return_sequences",",","sequence_length",")","`",":","The","generated","sequences",".","The","second","dimension","(","sequence_length",")","is","either","equal","to","`","max_length","`","or","shorter","if","all","batches","finished","early","due","to","the","`","eos_token_id","`","."]
code: def generate(
      self,
      input_ids: Optional[TFModelInputType] = None,
      attention_mask: Optional[tf.Tensor] = None,
      context_input_ids=None,
      context_attention_mask=None,
      doc_scores=None,
      max_length=None,
      min_length=None,
      early_stopping=None,
      use_cache=None,
      num_beams=None,
      bos_token_id=None,
      pad_token_id=None,
      eos_token_id=None,
      length_penalty=None,
      no_repeat_ngram_size=None,
      bad_words_ids=None,
      num_return_sequences=None,
      decoder_start_token_id=None,
      n_docs=None,
      output_scores=None,
      output_attentions=None,
      output_hidden_states=None,
      return_dict_in_generate=None,
      **model_kwargs,
  ):
      """
      Implements TFRAG token decoding.
  
      Args:
          input_ids (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
              The sequence used as a prompt for the generation. If `input_ids` is not passed, then
              `context_input_ids` has to be provided.
          attention_mask (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
              Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
  
              - 1 for tokens that are **not masked**,
              - 0 for tokens that are **masked**.
  
              [What are attention masks?](../glossary#attention-mask)
          context_input_ids (`tf.Tensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
              Input IDs post-processed from the retrieved documents and the question encoder `input_ids` by the
              retriever.
  
              If the model has is not initialized with a `retriever`, `context_input_ids` has to be provided to the
              forward pass. `context_input_ids` are returned by [`~RagRetriever.__call__`].
          context_attention_mask (`tf.Tensor` of shape `(batch_size * config.n_docs, config.max_combined_length)`, *optional*, returned when *output_retrieved=True*):
              Attention mask post-processed from the retrieved documents and the question encoder `input_ids` by the
              retriever.
  
              If the model has is not initialized with a `retriever`, `context_input_ids` has to be provided to the
              forward pass. `context_input_ids` are returned by [`~RagRetriever.__call__`].
          doc_scores (`tf.Tensor` of shape `(batch_size, config.n_docs)`):
              Score between each retrieved document embeddings (see `retrieved_doc_embeds`) and
              `question_encoder_last_hidden_state`.
  
              If the model has is not initialized with a `retriever`, `context_input_ids` has to be provided to the
              forward pass. `context_input_ids` are returned by [`~RagRetriever.__call__`].
          max_length (`int`, *optional*, defaults to 20):
              The maximum length of the sequence to be generated.
          min_length (`int`, *optional*, defaults to 10):
              The minimum length of the sequence to be generated.
          early_stopping (`bool`, *optional*, defaults to `False`):
              Whether or not to stop the beam search when at least `num_beams` sentences are finished per batch or
              not.
          use_cache: (`bool`, *optional*, defaults to `True`):
              Whether or not the model should use the past last key/values attentions (if applicable to the model) to
              speed up decoding.
          pad_token_id (`int`, *optional*):
              The id of the *padding* token.
          bos_token_id (`int`, *optional*):
              The id of the *beginning-of-sequence* token.
          eos_token_id (`int`, *optional*):
              The id of the *end-of-sequence* token.
          length_penalty (`float`, *optional*, defaults to 1.0):
              Exponential penalty to the length that is used with beam-based generation. It is applied as an exponent
              to the sequence length, which in turn is used to divide the score of the sequence. Since the score is
              the log likelihood of the sequence (i.e. negative), `length_penalty` > 0.0 promotes longer sequences,
              while `length_penalty` < 0.0 encourages shorter sequences.
          no_repeat_ngram_size (`int`, *optional*, defaults to 0):
              If set to int > 0, all ngrams of that size can only occur once.
          bad_words_ids(`List[int]`, *optional*):
              List of token ids that are not allowed to be generated. In order to get the tokens of the words that
              should not appear in the generated text, use `tokenizer.encode(bad_word, add_prefix_space=True)`.
          num_beams (`int`, *optional*, defaults to 1):
              Number of beams for beam search. 1 means no beam search.
          num_return_sequences(`int`, *optional*, defaults to 1):
              The number of independently computed returned sequences for each element in the batch. Note that this
              is not the value we pass to the `generator`'s `[`~generation_utils.GenerationMixin.generate`] function,
              where we set `num_return_sequences` to `num_beams`. decoder_start_token_id (`int`, *optional*): If an
              encoder-decoder model starts decoding with a different token than *bos*, the id of that token.
          n_docs (`int`, *optional*, defaults to `config.n_docs`)
              Number of documents to retrieve and/or number of documents for which to generate an answer.
          output_attentions (`bool`, *optional*, defaults to `False`):
              Whether or not to return the attentions tensors of all attention layers. See `attentions` under
              returned tensors for more details.
          output_hidden_states (`bool`, *optional*, defaults to `False`):
              Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
              for more details.
          output_scores (`bool`, *optional*, defaults to `False`):
              Whether or not to return the prediction scores. See `scores` under returned tensors for more details.
          return_dict_in_generate (`bool`, *optional*, defaults to `False`):
              Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
          model_specific_kwargs:
              Additional model specific kwargs will be forwarded to the `forward` function of the model.
  
      Return:
          `tf.Tensor` of shape `(batch_size * num_return_sequences, sequence_length)`: The generated sequences. The
          second dimension (sequence_length) is either equal to `max_length` or shorter if all batches finished early
          due to the `eos_token_id`.
      """
      # set default parameters
      n_docs = n_docs if n_docs is not None else self.config.n_docs
      max_length = (
          max_length
          if max_length is not None
          else self.config.max_length
      )
      min_length = (
          min_length
          if min_length is not None
          else self.config.min_length
      )
      early_stopping = (
          early_stopping
          if early_stopping is not None
          else self.config.early_stopping
      )
      use_cache = (
          use_cache if use_cache is not None else self.config.use_cache
      )
      num_beams = (
          num_beams if num_beams is not None else self.config.num_beams
      )
      bos_token_id = (
          bos_token_id
          if bos_token_id is not None
          else self.config.generator.bos_token_id
      )
      pad_token_id = (
          pad_token_id
          if pad_token_id is not None
          else self.config.generator.pad_token_id
      )
      eos_token_id = (
          eos_token_id
          if eos_token_id is not None
          else self.config.generator.eos_token_id
      )
      length_penalty = (
          length_penalty
          if length_penalty is not None
          else self.config.length_penalty
      )
      no_repeat_ngram_size = (
          no_repeat_ngram_size
          if no_repeat_ngram_size is not None
          else self.config.no_repeat_ngram_size
      )
      bad_words_ids = (
          bad_words_ids
          if bad_words_ids is not None
          else self.config.bad_words_ids
      )
      num_return_sequences = (
          num_return_sequences
          if num_return_sequences is not None
          else self.config.num_return_sequences
      )
      decoder_start_token_id = (
          decoder_start_token_id
          if decoder_start_token_id is not None
          else self.config.generator.decoder_start_token_id
      )
  
      output_scores = (
          output_scores
          if output_scores is not None
          else self.config.output_scores
      )
      output_attentions = (
          output_attentions
          if output_attentions is not None
          else self.config.output_attentions
      )
      output_hidden_states = (
          output_hidden_states
          if output_hidden_states is not None
          else self.config.output_hidden_states
      )
      return_dict_in_generate = (
          return_dict_in_generate
          if return_dict_in_generate is not None
          else self.config.return_dict_in_generate
      )
  
      model_kwargs["output_scores"] = output_scores
      model_kwargs["output_attentions"] = output_attentions
      model_kwargs["output_hidden_states"] = output_hidden_states
      model_kwargs["encoder_attentions"] = None
      model_kwargs["encoder_hidden_states"] = None
  
      # retrieve docs
      if self.retriever is not None and context_input_ids is None:
          question_hidden_states = self.question_encoder(
              input_ids, attention_mask=attention_mask
          )[0]
          out = self.retriever(
              input_ids,
              question_hidden_states.numpy().astype(np.float32),
              prefix=self.generator.config.prefix,
              n_docs=n_docs,
              return_tensors="tf",
          )
          (
              context_input_ids,
              context_attention_mask,
              retrieved_doc_embeds,
          ) = (
              out["context_input_ids"],
              out["context_attention_mask"],
              out["retrieved_doc_embeds"],
          )
  
          context_input_ids = tf.cast(context_input_ids, tf.int32)
          context_attention_mask = tf.cast(
              context_attention_mask, tf.int32
          )
          retrieved_doc_embeds = tf.cast(
              retrieved_doc_embeds, tf.float32
          )
  
          # compute doc_scores
          doc_scores = tf.matmul(
              tf.expand_dims(question_hidden_states, axis=1),
              retrieved_doc_embeds,
              transpose_b=True,
          )
          doc_scores = tf.squeeze(doc_scores, axis=1)
  
      assert (context_input_ids.shape[0] % n_docs) == 0, (
          f" The first dimension of `context_input_ids` should be a multiple of `n_docs`={n_docs}, but is"
          f" {context_input_ids.shape[0]}."
      )
  
      batch_size = context_input_ids.shape[0] // n_docs
  
      encoder = self.rag.generator.get_encoder()
      encoder_outputs = encoder(
          input_ids=context_input_ids,
          attention_mask=context_attention_mask,
          output_attentions=output_attentions,
          output_hidden_states=output_hidden_states,
          return_dict=True,
      )
  
      decoder_input_ids = tf.fill(
          (batch_size * num_beams, 1),
          tf.cast(decoder_start_token_id, tf.int32),
      )
      last_hidden_state = encoder_outputs["last_hidden_state"]
  
      def extend_enc_output(tensor, num_beams=None):
          """
          Broadcast tensor with `num_beams` replica, with correct order Input: tensor of shape (batch_size*n_docs ,
          d) Output: tensor of shape (batch_size*num_beams*n_docs , d)
          """
  
          # expand batch_size & num_beam dimensions
          d_shape_list = tensor.shape[1:]
  
          # split n_docs dimensions
          new_shape = (batch_size, 1, n_docs) + d_shape_list
          tensor = tf.reshape(tensor, new_shape)
  
          # repeat same last hidden states over `num_beams` dimension
          new_shape = (batch_size, num_beams, n_docs) + d_shape_list
          tensor = tf.broadcast_to(tensor, new_shape)
  
          # merge `batch_size`, `num_beams`, `num_docs` dims again
          new_shape = (batch_size * num_beams * n_docs,) + d_shape_list
          return tf.reshape(tensor, new_shape)
  
      # correctly extend last_hidden_state and attention mask
      context_attention_mask = extend_enc_output(
          context_attention_mask, num_beams=num_beams
      )
      encoder_outputs["last_hidden_state"] = extend_enc_output(
          last_hidden_state, num_beams=num_beams
      )
  
      doc_scores = tf.repeat(doc_scores, num_beams, axis=0)
  
      # define start_len & additional parameters
      cur_len = 1
      vocab_size = self.config.generator.vocab_size
      model_kwargs["doc_scores"] = doc_scores
      model_kwargs["encoder_outputs"] = encoder_outputs
      model_kwargs["n_docs"] = n_docs
  
      # not needed. TODO(PVP): change after generate refactor
      do_sample = False
      temperature = self.config.temperature
      top_k = self.config.top_k
      top_p = self.config.top_p
      repetition_penalty = self.config.repetition_penalty
  
      if num_beams > 1:
          return self._generate_beam_search(
              decoder_input_ids,
              cur_len=cur_len,
              max_length=max_length,
              min_length=min_length,
              do_sample=do_sample,
              early_stopping=early_stopping,
              temperature=temperature,
              top_k=top_k,
              top_p=top_p,
              repetition_penalty=repetition_penalty,
              no_repeat_ngram_size=no_repeat_ngram_size,
              bad_words_ids=bad_words_ids,
              pad_token_id=pad_token_id,
              eos_token_id=eos_token_id,
              batch_size=batch_size,
              num_return_sequences=num_return_sequences,
              length_penalty=length_penalty,
              num_beams=num_beams,
              vocab_size=vocab_size,
              attention_mask=context_attention_mask,
              use_cache=use_cache,
              forced_bos_token_id=None,
              forced_eos_token_id=None,
              return_dict_in_generate=return_dict_in_generate,
              **model_kwargs,  # encoder_outputs is here as in Pytorch's version
          )
      else:
          pre_processor = self._get_logits_processor(
              repetition_penalty=repetition_penalty,
              no_repeat_ngram_size=no_repeat_ngram_size,
              bad_words_ids=bad_words_ids,
              min_length=min_length,
              max_length=max_length,
              eos_token_id=eos_token_id,
              forced_bos_token_id=None,
              forced_eos_token_id=None,
              input_ids_seq_length=tf.shape(decoder_input_ids)[-1],
          )
          model_kwargs["attention_mask"] = context_attention_mask
  
          if model_kwargs.get("encoder_attentions", None) is None:
              model_kwargs.pop("encoder_attentions", None)
          if model_kwargs.get("encoder_hidden_states", None) is None:
              model_kwargs.pop("encoder_hidden_states", None)
  
          model_kwargs.pop("output_hidden_states", None)
          model_kwargs.pop("output_attentions", None)
          model_kwargs.pop("output_scores", None)
  
          return self.greedy_search(
              input_ids=decoder_input_ids,
              max_length=max_length,
              pad_token_id=pad_token_id,
              eos_token_id=eos_token_id,
              logits_processor=pre_processor,
              output_attentions=output_attentions,
              output_hidden_states=output_hidden_states,
              output_scores=output_scores,
              return_dict_in_generate=return_dict_in_generate,
              **model_kwargs,
          )
  
imports: from dataclasses import dataclass
  from typing import List, Optional, Tuple, Union
  import numpy
  import tensorflow
  from ...configuration_utils import PretrainedConfig
  from ...modeling_tf_utils import TFCausalLanguageModelingLoss, TFModelInputType, TFPreTrainedModel, shape_list, unpack_inputs
  from ...utils import ModelOutput, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_rag import RagConfig
  from .retrieval_rag import RagRetriever
label_desc: Use image node_id 10 for calling the TFRagTokenForGeneration obj's underlying member method code with example usage: obj.generate(input_ids, attention_mask, context_input_ids, context_attention_mask, doc_scores, max_length, min_length, early_stopping, use_cache, num_beams, bos_token_id, pad_token_id, eos_token_id, length_penalty, no_repeat_ngram_size, bad_words_ids, num_return_sequences, decoder_start_token_id, n_docs, output_scores, output_attentions, output_hidden_states, return_dict_in_generate) and returns: tf, self, self