class_docstr: ## Nucleus Sampler
class_docstr_tok: ["#","#","Nucleus","Sampler"]
docstr: :param p: is the sum of probabilities of tokens to pick $p$
  :param sampler: is the sampler to use for the selected tokens
docstr_tok: [":","param","p",":","is","the","sum","of","probabilities","of","tokens","to","pick","$","p","$",":","param","sampler",":","is","the","sampler","to","use","for","the","selected","tokens"]
code: def __init__(self, p: float, sampler: Sampler):
      """
      :param p: is the sum of probabilities of tokens to pick $p$
      :param sampler: is the sampler to use for the selected tokens
      """
      self.p = p
      self.sampler = sampler
      # Softmax to compute $P(x_i | x_{1:i-1})$ from the logits
      self.softmax = nn.Softmax(dim=-1)
  
imports: import torch
  from torch import nn
  from labml_nn.sampling import Sampler
label_desc: Use image node_id 1 to create a new NucleusSampler object from inherited base classes: Sampler with example: obj = NucleusSampler(p, sampler)