class_docstr: Base structured distribution class.
  
  Dynamic distribution for length N of structures :math:`p(z)`.
  
  Implemented based on gradient identities from:
  
  * Inside-outside and forward-backward algorithms are just backprop :cite:`eisner2016inside`
  * Semiring Parsing :cite:`goodman1999semiring`
  * First-and second-order expectation semirings with applications to minimum-risk training on translation forests :cite:`li2009first`
  
  Parameters:
      log_potentials (tensor, batch_shape x event_shape) :  log-potentials :math:`\phi`
      lengths (long tensor, batch_shape) : integers for length masking
docstr: Compute structured samples from the distribution :math:`z \sim p(z)`.
  
  Parameters:
      sample_shape (int): 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","(","int",")",":","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 (int): number of samples
  
      Returns:
          samples (*sample_shape x batch_shape x event_shape*)
      """
      assert len(sample_shape) == 1
      nsamples = sample_shape[0]
      samples = []
      for k in range(nsamples):
          if k % 10 == 0:
              sample = self._struct(MultiSampledSemiring).marginals(
                  self.log_potentials, lengths=self.lengths
              )
              sample = sample.detach()
          tmp_sample = MultiSampledSemiring.to_discrete(
              sample, (k % 10) + 1
          )
          samples.append(tmp_sample)
      return torch.stack(samples)
  
imports: import torch
  from torch.distributions import constraints
  from torch.distributions.distribution import Distribution
  from torch.distributions.utils import lazy_property
  from .linearchain import LinearChain
  from .cky import CKY
  from .semimarkov import SemiMarkov
  from .alignment import Alignment
  from .deptree import DepTree, deptree_nonproj, deptree_part
  from .cky_crf import CKY_CRF
  from .semirings import LogSemiring, MaxSemiring, EntropySemiring, CrossEntropySemiring, KLDivergenceSemiring, MultiSampledSemiring, KMaxSemiring, StdSemiring, GumbelCRFSemiring
label_desc: Use image node_id 16 for calling the StructDistribution obj's underlying member method code with example usage: obj.sample(sample_shape) and returns: torch