neulab/docprompting-conala huggingface dataset:
log_prob(value) [source]
 
Returns the log of the probability density/mass function evaluated at value.  Parameters 
value (Tensor) –
perplexity() [source]
 
Returns perplexity of distribution, batched over batch_shape.  Returns 
Tensor of shape batch_shape.
rsample(sample_shape=torch.Size([])) [source]
 
Generates a sample_shape shaped reparameterized sample or sample_shape shaped batch of reparameterized samples if the distribution parameters are batched.
sample(sample_shape=torch.Size([])) [source]
 
Generates a sample_shape shaped sample or sample_shape shaped batch of samples if the distribution parameters are batched.
sample_n(n) [source]
 
Generates n samples or n batches of samples if the distribution parameters are batched.
static set_default_validate_args(value) [source]
 
Sets whether validation is enabled or disabled. The default behavior mimics Python’s assert statement: validation is on by default, but is disabled if Python is run in optimized mode (via python -O). Validation may be expensive, so you may want to disable it once a model is working.  Parameters 
value (bool) – Whether to enable validation.
class torch.distributions.exponential.Exponential(rate, validate_args=None) [source]
 
Bases: torch.distributions.exp_family.ExponentialFamily Creates a Exponential distribution parameterized by rate. Example: >>> m = Exponential(torch.tensor([1.0]))
>>> m.sample()  # Exponential distributed with rate=1
tensor([ 0.1046])
  Parameters 
rate (float or Tensor) – rate = 1 / scale of the distribution    
arg_constraints = {'rate': GreaterThan(lower_bound=0.0)} 
  
cdf(value) [source]

  
entropy() [source]

  
expand(batch_shape, _instance=None) [source]

  
has_rsample = True 
  
icdf(value) [source]

  
log_prob(value) [source]

  
property mean 
  
rsample(sample_shape=torch.Size([])) [source]

  
property stddev 
  
support = GreaterThan(lower_bound=0.0) 
  
property variance
arg_constraints = {'rate': GreaterThan(lower_bound=0.0)}
class torch.distributions.exp_family.ExponentialFamily(batch_shape=torch.Size([]), event_shape=torch.Size([]), validate_args=None) [source]
 
Bases: torch.distributions.distribution.Distribution ExponentialFamily is the abstract base class for probability distributions belonging to an exponential family, whose probability mass/density function has the form is defined below  pF(x;θ)=exp⁡(⟨t(x),θ⟩−F(θ)+k(x))p_{F}(x; \theta) = \exp(\langle t(x), \theta\rangle - F(\theta) + k(x)) 
where θ\theta  denotes the natural parameters, t(x)t(x)  denotes the sufficient statistic, F(θ)F(\theta)  is the log normalizer function for a given family and k(x)k(x)  is the carrier measure.  Note This class is an intermediary between the Distribution class and distributions which belong to an exponential family mainly to check the correctness of the .entropy() and analytic KL divergence methods. We use this class to compute the entropy and KL divergence using the AD framework and Bregman divergences (courtesy of: Frank Nielsen and Richard Nock, Entropies and Cross-entropies of Exponential Families).   
entropy() [source]
 
Method to compute the entropy using Bregman divergence of the log normalizer.
entropy() [source]
 
Method to compute the entropy using Bregman divergence of the log normalizer.
class torch.distributions.fishersnedecor.FisherSnedecor(df1, df2, validate_args=None) [source]
 
Bases: torch.distributions.distribution.Distribution Creates a Fisher-Snedecor distribution parameterized by df1 and df2. Example: >>> m = FisherSnedecor(torch.tensor([1.0]), torch.tensor([2.0]))
>>> m.sample()  # Fisher-Snedecor-distributed with df1=1 and df2=2
tensor([ 0.2453])
  Parameters 
 
df1 (float or Tensor) – degrees of freedom parameter 1 
df2 (float or Tensor) – degrees of freedom parameter 2     
arg_constraints = {'df1': GreaterThan(lower_bound=0.0), 'df2': GreaterThan(lower_bound=0.0)} 
  
expand(batch_shape, _instance=None) [source]

  
has_rsample = True 
  
log_prob(value) [source]

  
property mean 
  
rsample(sample_shape=torch.Size([])) [source]

  
support = GreaterThan(lower_bound=0.0) 
  
property variance
arg_constraints = {'df1': GreaterThan(lower_bound=0.0), 'df2': GreaterThan(lower_bound=0.0)}
class torch.distributions.gamma.Gamma(concentration, rate, validate_args=None) [source]
 
Bases: torch.distributions.exp_family.ExponentialFamily Creates a Gamma distribution parameterized by shape concentration and rate. Example: >>> m = Gamma(torch.tensor([1.0]), torch.tensor([1.0]))
>>> m.sample()  # Gamma distributed with concentration=1 and rate=1
tensor([ 0.1046])
  Parameters 
 
concentration (float or Tensor) – shape parameter of the distribution (often referred to as alpha) 
rate (float or Tensor) – rate = 1 / scale of the distribution (often referred to as beta)     
arg_constraints = {'concentration': GreaterThan(lower_bound=0.0), 'rate': GreaterThan(lower_bound=0.0)} 
  
entropy() [source]

  
expand(batch_shape, _instance=None) [source]

  
has_rsample = True 
  
log_prob(value) [source]

  
property mean 
  
rsample(sample_shape=torch.Size([])) [source]

  
support = GreaterThan(lower_bound=0.0) 
  
property variance
arg_constraints = {'concentration': GreaterThan(lower_bound=0.0), 'rate': GreaterThan(lower_bound=0.0)}
class torch.distributions.geometric.Geometric(probs=None, logits=None, validate_args=None) [source]
 
Bases: torch.distributions.distribution.Distribution Creates a Geometric distribution parameterized by probs, where probs is the probability of success of Bernoulli trials. It represents the probability that in k+1k + 1  Bernoulli trials, the first kk  trials failed, before seeing a success. Samples are non-negative integers [0, inf⁡\inf ). Example: >>> m = Geometric(torch.tensor([0.3]))
>>> m.sample()  # underlying Bernoulli has 30% chance 1; 70% chance 0
tensor([ 2.])
  Parameters 
 
probs (Number, Tensor) – the probability of sampling 1. Must be in range (0, 1] 
logits (Number, Tensor) – the log-odds of sampling 1.     
arg_constraints = {'logits': Real(), 'probs': Interval(lower_bound=0.0, upper_bound=1.0)} 
  
entropy() [source]

  
expand(batch_shape, _instance=None) [source]

  
log_prob(value) [source]

  
logits [source]

  
property mean 
  
probs [source]

  
sample(sample_shape=torch.Size([])) [source]

  
support = IntegerGreaterThan(lower_bound=0) 
  
property variance
class torch.distributions.gumbel.Gumbel(loc, scale, validate_args=None) [source]
 
Bases: torch.distributions.transformed_distribution.TransformedDistribution Samples from a Gumbel Distribution. Examples: >>> m = Gumbel(torch.tensor([1.0]), torch.tensor([2.0]))
>>> m.sample()  # sample from Gumbel distribution with loc=1, scale=2
tensor([ 1.0124])
  Parameters 
 
loc (float or Tensor) – Location parameter of the distribution 
scale (float or Tensor) – Scale parameter of the distribution     
arg_constraints: Dict[str, torch.distributions.constraints.Constraint] = {'loc': Real(), 'scale': GreaterThan(lower_bound=0.0)} 
  
entropy() [source]

  
expand(batch_shape, _instance=None) [source]

  
log_prob(value) [source]

  
property mean 
  
property stddev 
  
support = Real() 
  
property variance
arg_constraints: Dict[str, torch.distributions.constraints.Constraint] = {'loc': Real(), 'scale': GreaterThan(lower_bound=0.0)}
class torch.distributions.half_cauchy.HalfCauchy(scale, validate_args=None) [source]
 
Bases: torch.distributions.transformed_distribution.TransformedDistribution Creates a half-Cauchy distribution parameterized by scale where: X ~ Cauchy(0, scale)
Y = |X| ~ HalfCauchy(scale)
 Example: >>> m = HalfCauchy(torch.tensor([1.0]))
>>> m.sample()  # half-cauchy distributed with scale=1
tensor([ 2.3214])
  Parameters 
scale (float or Tensor) – scale of the full Cauchy distribution    
arg_constraints: Dict[str, torch.distributions.constraints.Constraint] = {'scale': GreaterThan(lower_bound=0.0)} 
  
cdf(value) [source]

  
entropy() [source]

  
expand(batch_shape, _instance=None) [source]

  
has_rsample = True 
  
icdf(prob) [source]

  
log_prob(value) [source]

  
property mean 
  
property scale 
  
support = GreaterThan(lower_bound=0.0) 
  
property variance
arg_constraints: Dict[str, torch.distributions.constraints.Constraint] = {'scale': GreaterThan(lower_bound=0.0)}
class torch.distributions.half_normal.HalfNormal(scale, validate_args=None) [source]
 
Bases: torch.distributions.transformed_distribution.TransformedDistribution Creates a half-normal distribution parameterized by scale where: X ~ Normal(0, scale)
Y = |X| ~ HalfNormal(scale)
 Example: >>> m = HalfNormal(torch.tensor([1.0]))
>>> m.sample()  # half-normal distributed with scale=1
tensor([ 0.1046])
  Parameters 
scale (float or Tensor) – scale of the full Normal distribution    
arg_constraints: Dict[str, torch.distributions.constraints.Constraint] = {'scale': GreaterThan(lower_bound=0.0)} 
  
cdf(value) [source]

  
entropy() [source]

  
expand(batch_shape, _instance=None) [source]

  
has_rsample = True 
  
icdf(prob) [source]

  
log_prob(value) [source]

  
property mean 
  
property scale 
  
support = GreaterThan(lower_bound=0.0) 
  
property variance
class torch.distributions.independent.Independent(base_distribution, reinterpreted_batch_ndims, validate_args=None) [source]
 
Bases: torch.distributions.distribution.Distribution Reinterprets some of the batch dims of a distribution as event dims. This is mainly useful for changing the shape of the result of log_prob(). For example to create a diagonal Normal distribution with the same shape as a Multivariate Normal distribution (so they are interchangeable), you can: >>> loc = torch.zeros(3)
>>> scale = torch.ones(3)
>>> mvn = MultivariateNormal(loc, scale_tril=torch.diag(scale))
>>> [mvn.batch_shape, mvn.event_shape]
[torch.Size(()), torch.Size((3,))]
>>> normal = Normal(loc, scale)
>>> [normal.batch_shape, normal.event_shape]
[torch.Size((3,)), torch.Size(())]
>>> diagn = Independent(normal, 1)
>>> [diagn.batch_shape, diagn.event_shape]
[torch.Size(()), torch.Size((3,))]
  Parameters 
 
base_distribution (torch.distributions.distribution.Distribution) – a base distribution 
reinterpreted_batch_ndims (int) – the number of batch dims to reinterpret as event dims     
arg_constraints: Dict[str, torch.distributions.constraints.Constraint] = {} 
  
entropy() [source]

  
enumerate_support(expand=True) [source]

  
expand(batch_shape, _instance=None) [source]

  
property has_enumerate_support 
  
property has_rsample 
  
log_prob(value) [source]

  
property mean 
  
rsample(sample_shape=torch.Size([])) [source]

  
sample(sample_shape=torch.Size([])) [source]

  
property support 
  
property variance
torch.distributions.kl.kl_divergence(p, q) [source]
 
Compute Kullback-Leibler divergence KL(p∥q)KL(p \| q)  between two distributions.  KL(p∥q)=∫p(x)log⁡p(x)q(x)dxKL(p \| q) = \int p(x) \log\frac {p(x)} {q(x)} \,dx 
 Parameters 
 
p (Distribution) – A Distribution object. 
q (Distribution) – A Distribution object.   Returns 
A batch of KL divergences of shape batch_shape.  Return type 
Tensor  Raises 
NotImplementedError – If the distribution types have not been registered via register_kl().
torch.distributions.kl.register_kl(type_p, type_q) [source]
 
Decorator to register a pairwise function with kl_divergence(). Usage: @register_kl(Normal, Normal)
def kl_normal_normal(p, q):
    # insert implementation here
 Lookup returns the most specific (type,type) match ordered by subclass. If the match is ambiguous, a RuntimeWarning is raised. For example to resolve the ambiguous situation: @register_kl(BaseP, DerivedQ)
def kl_version1(p, q): ...
@register_kl(DerivedP, BaseQ)
def kl_version2(p, q): ...
 you should register a third most-specific implementation, e.g.: register_kl(DerivedP, DerivedQ)(kl_version1)  # Break the tie.
  Parameters 
 
type_p (type) – A subclass of Distribution. 
type_q (type) – A subclass of Distribution.
class torch.distributions.kumaraswamy.Kumaraswamy(concentration1, concentration0, validate_args=None) [source]
 
Bases: torch.distributions.transformed_distribution.TransformedDistribution Samples from a Kumaraswamy distribution. Example: >>> m = Kumaraswamy(torch.Tensor([1.0]), torch.Tensor([1.0]))
>>> m.sample()  # sample from a Kumaraswamy distribution with concentration alpha=1 and beta=1
tensor([ 0.1729])
  Parameters 
 
concentration1 (float or Tensor) – 1st concentration parameter of the distribution (often referred to as alpha) 
concentration0 (float or Tensor) – 2nd concentration parameter of the distribution (often referred to as beta)     
arg_constraints: Dict[str, torch.distributions.constraints.Constraint] = {'concentration0': GreaterThan(lower_bound=0.0), 'concentration1': GreaterThan(lower_bound=0.0)} 
  
entropy() [source]

  
expand(batch_shape, _instance=None) [source]

  
has_rsample = True 
  
property mean 
  
support = Interval(lower_bound=0.0, upper_bound=1.0) 
  
property variance
arg_constraints: Dict[str, torch.distributions.constraints.Constraint] = {'concentration0': GreaterThan(lower_bound=0.0), 'concentration1': GreaterThan(lower_bound=0.0)}
class torch.distributions.laplace.Laplace(loc, scale, validate_args=None) [source]
 
Bases: torch.distributions.distribution.Distribution Creates a Laplace distribution parameterized by loc and scale. Example: >>> m = Laplace(torch.tensor([0.0]), torch.tensor([1.0]))
>>> m.sample()  # Laplace distributed with loc=0, scale=1
tensor([ 0.1046])
  Parameters 
 
loc (float or Tensor) – mean of the distribution 
scale (float or Tensor) – scale of the distribution     
arg_constraints = {'loc': Real(), 'scale': GreaterThan(lower_bound=0.0)} 
  
cdf(value) [source]

  
entropy() [source]

  
expand(batch_shape, _instance=None) [source]

  
has_rsample = True 
  
icdf(value) [source]

  
log_prob(value) [source]

  
property mean 
  
rsample(sample_shape=torch.Size([])) [source]

  
property stddev 
  
support = Real() 
  
property variance
class torch.distributions.lkj_cholesky.LKJCholesky(dim, concentration=1.0, validate_args=None) [source]
 
Bases: torch.distributions.distribution.Distribution LKJ distribution for lower Cholesky factor of correlation matrices. The distribution is controlled by concentration parameter η\eta  to make the probability of the correlation matrix MM  generated from a Cholesky factor propotional to det⁡(M)η−1\det(M)^{\eta - 1} . Because of that, when concentration == 1, we have a uniform distribution over Cholesky factors of correlation matrices. Note that this distribution samples the Cholesky factor of correlation matrices and not the correlation matrices themselves and thereby differs slightly from the derivations in [1] for the LKJCorr distribution. For sampling, this uses the Onion method from [1] Section 3. L ~ LKJCholesky(dim, concentration) X = L @ L’ ~ LKJCorr(dim, concentration) Example: >>> l = LKJCholesky(3, 0.5)
>>> l.sample()  # l @ l.T is a sample of a correlation 3x3 matrix
tensor([[ 1.0000,  0.0000,  0.0000],
        [ 0.3516,  0.9361,  0.0000],
        [-0.1899,  0.4748,  0.8593]])
  Parameters 
 
dimension (dim) – dimension of the matrices 
concentration (float or Tensor) – concentration/shape parameter of the distribution (often referred to as eta)    References [1] Generating random correlation matrices based on vines and extended onion method, Daniel Lewandowski, Dorota Kurowicka, Harry Joe.  
arg_constraints = {'concentration': GreaterThan(lower_bound=0.0)} 
  
expand(batch_shape, _instance=None) [source]

  
log_prob(value) [source]

  
sample(sample_shape=torch.Size([])) [source]

  
support = CorrCholesky()
arg_constraints = {'concentration': GreaterThan(lower_bound=0.0)}
class torch.distributions.log_normal.LogNormal(loc, scale, validate_args=None) [source]
 
Bases: torch.distributions.transformed_distribution.TransformedDistribution Creates a log-normal distribution parameterized by loc and scale where: X ~ Normal(loc, scale)
Y = exp(X) ~ LogNormal(loc, scale)
 Example: >>> m = LogNormal(torch.tensor([0.0]), torch.tensor([1.0]))
>>> m.sample()  # log-normal distributed with mean=0 and stddev=1
tensor([ 0.1046])
  Parameters 
 
loc (float or Tensor) – mean of log of distribution 
scale (float or Tensor) – standard deviation of log of the distribution     
arg_constraints: Dict[str, torch.distributions.constraints.Constraint] = {'loc': Real(), 'scale': GreaterThan(lower_bound=0.0)} 
  
entropy() [source]

  
expand(batch_shape, _instance=None) [source]

  
has_rsample = True 
  
property loc 
  
property mean 
  
property scale 
  
support = GreaterThan(lower_bound=0.0) 
  
property variance
class torch.distributions.lowrank_multivariate_normal.LowRankMultivariateNormal(loc, cov_factor, cov_diag, validate_args=None) [source]
 
Bases: torch.distributions.distribution.Distribution Creates a multivariate normal distribution with covariance matrix having a low-rank form parameterized by cov_factor and cov_diag: covariance_matrix = cov_factor @ cov_factor.T + cov_diag
 Example >>> m = LowRankMultivariateNormal(torch.zeros(2), torch.tensor([[1.], [0.]]), torch.ones(2))
>>> m.sample()  # normally distributed with mean=`[0,0]`, cov_factor=`[[1],[0]]`, cov_diag=`[1,1]`
tensor([-0.2102, -0.5429])
  Parameters 
 
loc (Tensor) – mean of the distribution with shape batch_shape + event_shape
 
cov_factor (Tensor) – factor part of low-rank form of covariance matrix with shape batch_shape + event_shape + (rank,)
 
cov_diag (Tensor) – diagonal part of low-rank form of covariance matrix with shape batch_shape + event_shape
     Note The computation for determinant and inverse of covariance matrix is avoided when cov_factor.shape[1] << cov_factor.shape[0] thanks to Woodbury matrix identity and matrix determinant lemma. Thanks to these formulas, we just need to compute the determinant and inverse of the small size “capacitance” matrix: capacitance = I + cov_factor.T @ inv(cov_diag) @ cov_factor
   
arg_constraints = {'cov_diag': IndependentConstraint(GreaterThan(lower_bound=0.0), 1), 'cov_factor': IndependentConstraint(Real(), 2), 'loc': IndependentConstraint(Real(), 1)} 
  
covariance_matrix [source]

  
entropy() [source]

  
expand(batch_shape, _instance=None) [source]

  
has_rsample = True 
  
log_prob(value) [source]

  
property mean 
  
precision_matrix [source]

  
rsample(sample_shape=torch.Size([])) [source]

  
scale_tril [source]

  
support = IndependentConstraint(Real(), 1) 
  
variance [source]
arg_constraints = {'cov_diag': IndependentConstraint(GreaterThan(lower_bound=0.0), 1), 'cov_factor': IndependentConstraint(Real(), 2), 'loc': IndependentConstraint(Real(), 1)}
class torch.distributions.mixture_same_family.MixtureSameFamily(mixture_distribution, component_distribution, validate_args=None) [source]
 
Bases: torch.distributions.distribution.Distribution The MixtureSameFamily distribution implements a (batch of) mixture distribution where all component are from different parameterizations of the same distribution type. It is parameterized by a Categorical “selecting distribution” (over k component) and a component distribution, i.e., a Distribution with a rightmost batch shape (equal to [k]) which indexes each (batch of) component. Examples: # Construct Gaussian Mixture Model in 1D consisting of 5 equally
# weighted normal distributions
>>> mix = D.Categorical(torch.ones(5,))
>>> comp = D.Normal(torch.randn(5,), torch.rand(5,))
>>> gmm = MixtureSameFamily(mix, comp)

# Construct Gaussian Mixture Modle in 2D consisting of 5 equally
# weighted bivariate normal distributions
>>> mix = D.Categorical(torch.ones(5,))
>>> comp = D.Independent(D.Normal(
             torch.randn(5,2), torch.rand(5,2)), 1)
>>> gmm = MixtureSameFamily(mix, comp)

# Construct a batch of 3 Gaussian Mixture Models in 2D each
# consisting of 5 random weighted bivariate normal distributions
>>> mix = D.Categorical(torch.rand(3,5))
>>> comp = D.Independent(D.Normal(
            torch.randn(3,5,2), torch.rand(3,5,2)), 1)
>>> gmm = MixtureSameFamily(mix, comp)
  Parameters 
 
mixture_distribution – torch.distributions.Categorical-like instance. Manages the probability of selecting component. The number of categories must match the rightmost batch dimension of the component_distribution. Must have either scalar batch_shape or batch_shape matching component_distribution.batch_shape[:-1]
 
component_distribution – torch.distributions.Distribution-like instance. Right-most batch dimension indexes component.     
arg_constraints: Dict[str, torch.distributions.constraints.Constraint] = {} 
  
cdf(x) [source]

  
property component_distribution 
  
expand(batch_shape, _instance=None) [source]

  
has_rsample = False 
  
log_prob(x) [source]

  
property mean 
  
property mixture_distribution 
  
sample(sample_shape=torch.Size([])) [source]

  
property support 
  
property variance
class torch.distributions.multinomial.Multinomial(total_count=1, probs=None, logits=None, validate_args=None) [source]
 
Bases: torch.distributions.distribution.Distribution Creates a Multinomial distribution parameterized by total_count and either probs or logits (but not both). The innermost dimension of probs indexes over categories. All other dimensions index over batches. Note that total_count need not be specified if only log_prob() is called (see example below)  Note The probs argument must be non-negative, finite and have a non-zero sum, and it will be normalized to sum to 1 along the last dimension. attr:probs will return this normalized value. The logits argument will be interpreted as unnormalized log probabilities and can therefore be any real number. It will likewise be normalized so that the resulting probabilities sum to 1 along the last dimension. attr:logits will return this normalized value.   
sample() requires a single shared total_count for all parameters and samples. 
log_prob() allows different total_count for each parameter and sample.  Example: >>> m = Multinomial(100, torch.tensor([ 1., 1., 1., 1.]))
>>> x = m.sample()  # equal probability of 0, 1, 2, 3
tensor([ 21.,  24.,  30.,  25.])

>>> Multinomial(probs=torch.tensor([1., 1., 1., 1.])).log_prob(x)
tensor([-4.1338])
  Parameters 
 
total_count (int) – number of trials 
probs (Tensor) – event probabilities 
logits (Tensor) – event log probabilities (unnormalized)     
arg_constraints = {'logits': IndependentConstraint(Real(), 1), 'probs': Simplex()} 
  
expand(batch_shape, _instance=None) [source]

  
log_prob(value) [source]

  
property logits 
  
property mean 
  
property param_shape 
  
property probs 
  
sample(sample_shape=torch.Size([])) [source]

  
property support 
  
total_count: int = None 
  
property variance