class_docstr: [`TFLogitsWarper`] that performs top-p, i.e. restricting to top tokens summing to <= prob_cut_off.
  
  Args:
      top_p (`float`):
          If set to < 1, only the smallest set of most probable tokens with probabilities that add up to `top_p` or
          higher are kept for generation.
      filter_value (`float`, *optional*, defaults to `-float("Inf")`):
          All filtered values will be set to this float value.
      min_tokens_to_keep (`int`, *optional*, defaults to 1):
          Minimum number of tokens that cannot be filtered.
class_docstr_tok: ["[","`","TFLogitsWarper","`","]","that","performs","top-p",",","i.e",".","restricting","to","top","tokens","summing","to","<","=","prob_cut_off",".","Args",":","top_p","(","`","float","`",")",":","If","set","to","<","1",",","only","the","smallest","set","of","most","probable","tokens","with","probabilities","that","add","up","to","`","top_p","`","or","higher","are","kept","for","generation",".","filter_value","(","`","float","`",",","*","optional","*",",","defaults","to","`","-float","(","``","Inf","''",")","`",")",":","All","filtered","values","will","be","set","to","this","float","value",".","min_tokens_to_keep","(","`","int","`",",","*","optional","*",",","defaults","to","1",")",":","Minimum","number","of","tokens","that","can","not","be","filtered","."]
code: def __call__(
      self, input_ids: tf.Tensor, scores: tf.Tensor, cur_len: int
  ) -> tf.Tensor:
      topk_scores, topk_indices = tf.math.top_k(
          scores, scores.shape[-1]
      )
  
      mask_scores = tf.fill(scores.shape, self.filter_value)
      cumulative_probs = tf.math.cumsum(
          stable_softmax(topk_scores, axis=-1), axis=-1
      )
      score_mask = cumulative_probs < self.top_p
  
      # Also include the token that is higher than top_p (the first false = shift and insert a True on the left)
      score_mask = tf.concat(
          (
              tf.ones([score_mask.shape[0], 1], dtype=tf.bool),
              score_mask[:, :-1],
          ),
          axis=-1,
      )
  
      # Ensure min tokens to keep
      score_mask = tf.concat(
          (
              tf.ones(
                  [score_mask.shape[0], self.min_tokens_to_keep],
                  dtype=tf.bool,
              ),
              score_mask[:, self.min_tokens_to_keep :],
          ),
          axis=-1,
      )
  
      # Mask the values that do not fit the criteria
      topk_next_scores = tf.where(score_mask, topk_scores, mask_scores)
  
      # Undo the topk sorting: converts the 2D matrix of per-row original indices of shape (batch_size, vocab_size)
      # to a 3D tensor of shape (batch_size, vocab_size, 2) containing the original score coordinate, from which we
      # can scatter (i.e. `scatter_indices[row, col, :]` is a tensor containing `[row, topk_indices[row, col]]`)
      scatter_rows = tf.tile(
          tf.expand_dims(tf.range(topk_indices.shape[0]), axis=-1),
          [1, topk_indices.shape[-1]],
      )
      scatter_indices = tf.stack((scatter_rows, topk_indices), axis=-1)
      next_scores = tf.scatter_nd(
          scatter_indices,
          topk_next_scores,
          shape=topk_next_scores.shape,
      )
  
      return next_scores
  
imports: import inspect
  from typing import List, Tuple
  import numpy
  import tensorflow
  from .tf_utils import stable_softmax
  from .utils import add_start_docstrings
  from .utils.logging import get_logger
label_desc: Use image node_id 2 for calling the TFTopPLogitsWarper obj's underlying member method code with example usage: obj.__call__(input_ids, scores, cur_len) and returns: next_scores