docstr: Filter a distribution of logits using top-k and/or nucleus (top-p) filtering
  Args:
      logits: logits distribution shape (vocabulary size)
      top_k > 0: keep only top k tokens with highest probability (top-k filtering).
      top_p > 0.0: keep the top tokens with cumulative probability >= top_p (nucleus filtering).
          Nucleus filtering is described in Holtzman et al. (http://arxiv.org/abs/1904.09751)
  From: https://gist.github.com/thomwolf/1a5a29f6962089e871b94cbd09daf317
code: def top_k_top_p_filtering(
      logits, top_k=0, top_p=1.0, filter_value=-float("Inf")
  ):
      """Filter a distribution of logits using top-k and/or nucleus (top-p) filtering
      Args:
          logits: logits distribution shape (vocabulary size)
          top_k > 0: keep only top k tokens with highest probability (top-k filtering).
          top_p > 0.0: keep the top tokens with cumulative probability >= top_p (nucleus filtering).
              Nucleus filtering is described in Holtzman et al. (http://arxiv.org/abs/1904.09751)
      From: https://gist.github.com/thomwolf/1a5a29f6962089e871b94cbd09daf317
      """
      top_k = min(top_k, logits.shape[-1])  # Safety check
      logits_np = logits.numpy()
      if top_k > 0:
          # Remove all tokens with a probability less than the last token of the top-k
          indices_to_remove = logits_np < np.sort(logits_np)[-top_k]
          logits_np[indices_to_remove] = filter_value
  
      if top_p < 1.0:
          sorted_logits = paddle.sort(logits, descending=True)
          sorted_indices = paddle.argsort(
              logits, descending=True
          ).numpy()
          cumulative_probs = paddle.cumsum(
              paddle.nn.functional.softmax(sorted_logits, axis=-1),
              axis=-1,
          ).numpy()
  
          # Remove tokens with cumulative probability above the threshold
          sorted_indices_to_remove = cumulative_probs > top_p
          # Shift the indices to the right to keep also the first token above the threshold
          sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[
              ..., :-1
          ]
          sorted_indices_to_remove[..., 0] = 0
  
          indices_to_remove = sorted_indices[sorted_indices_to_remove]
          logits_np[indices_to_remove] = filter_value
  
      return paddle.to_tensor(logits_np)
  
file_path: PaddleHub/modules/text/text_generation/GPT2_Base_CN/module.py
imports: import paddle
  import numpy
  import paddle.nn
  from paddlehub.module.module import moduleinfo, serving
  from paddlenlp.transformers import GPT2ForPretraining, GPT2ChineseTokenizer
label_desc: Use image node_id 3 for calling the GPT2_Base_CN obj's underlying member method code with example usage: obj.top_k_top_p_filtering(logits, top_k, top_p, filter_value) and returns: paddle