code: def sample_topk(logits, keep_topk):
      top_values, _ = torch.topk(logits, keep_topk, dim=1)
      kth_best = top_values[:, -1].view([-1, 1])
      kth_best = kth_best.repeat([1, logits.shape[1]]).float()
  
      # Set all logits that are not in the top-k to -10000.
      # This puts the probabilities close to 0.
      ignore = torch.lt(logits, kth_best)
      return logits.masked_fill(ignore, -10000)
  
imports: import torch
  from torch.nn.functional import softmax
  from onmt.translate.decode_strategy import DecodeStrategy
label_desc: Use image node_id 2 for calling a global function with example usage: sample_topk(logits, keep_topk) and returns: logits