class_docstr: Autoregressive sequence model utilizing beam search.
  
  * batch_shape -> Given by initializer
  * event_shape -> N x T sequence of choices
  
  Parameters:
      model (AutoregressiveModel): A lazily computed autoregressive model.
      init (tuple of tensors, batch_shape x ...): initial state of autoregressive model.
      n_classes (int): number of classes in each time step
      n_length (int): max length of sequence
class_docstr_tok: ["Autoregressive","sequence","model","utilizing","beam","search",".","*","batch_shape","-",">","Given","by","initializer","*","event_shape","-",">","N","x","T","sequence","of","choices","Parameters",":","model","(","AutoregressiveModel",")",":","A","lazily","computed","autoregressive","model",".","init","(","tuple","of","tensors",",","batch_shape","x","...",")",":","initial","state","of","autoregressive","model",".","n_classes","(","int",")",":","number","of","classes","in","each","time","step","n_length","(","int",")",":","max","length","of","sequence"]
docstr: Compute structured samples from the distribution :math:`z \sim p(z)`.
  
  Parameters:
      sample_shape (torch.Size): number of samples
  
  Returns:
      samples (*sample_shape x batch_shape x event_shape*)
docstr_tok: ["Compute","structured","samples","from","the","distribution",":","math",":","`","z","\\sim","p","(","z",")","`",".","Parameters",":","sample_shape","(","torch.Size",")",":","number","of","samples","Returns",":","samples","(","*","sample_shape","x","batch_shape","x","event_shape","*",")"]
code: def sample(self, sample_shape=torch.Size()):
      r"""
      Compute structured samples from the distribution :math:`z \sim p(z)`.
  
      Parameters:
          sample_shape (torch.Size): number of samples
  
      Returns:
          samples (*sample_shape x batch_shape x event_shape*)
      """
      sample_shape = sample_shape[0]
      state = tuple(
          (
              unwrap(i.unsqueeze(0).expand((sample_shape,) + i.shape))
              for i in self.init
          )
      )
      all_tokens = []
      tokens = (
          torch.zeros((sample_shape * self.batch_shape[0]))
          .long()
          .fill_(self.start_class)
      )
      for t in range(0, self.n_length):
          logits, state = self.model(tokens.unsqueeze(-1), state)
          logits = logits.squeeze(1)
          tokens = torch.distributions.Categorical(
              logits=logits
          ).sample((1,))[0]
          all_tokens.append(tokens)
      v = wrap(torch.stack(all_tokens, dim=1), sample_shape)
      return torch.nn.functional.one_hot(v, self.n_classes)
  
file_path: pytorch-struct/torch_struct/autoregressive.py
imports: import torch
  from .semirings import MaxSemiring, KMaxSemiring, TempMax
  from torch.distributions.distribution import Distribution
label_desc: Use image node_id 9 for calling the Autoregressive obj's underlying member method code with example usage: obj.sample(sample_shape) and returns: torch