Distribution

StructuredDistribution

class supar.structs.dist.StructuredDistribution(scores, **kwargs)[source]

Base class for structured distribution \(p(y)\) [Eisner 2016, Goodman 1999, Li & Eisner 2009].

Parameters

scores (torch.Tensor) – Log potentials, also for high-order cases.

property log_partition

Computes the log partition function of the distribution \(p(y)\).

property marginals

Computes marginal probabilities of the distribution \(p(y)\).

property max

Computes the max score of the distribution \(p(y)\).

property argmax

Computes \(\arg\max_y p(y)\) of the distribution \(p(y)\).

kmax(k)[source]

Computes the k-max of the distribution \(p(y)\).

topk(k)[source]

Computes the k-argmax of the distribution \(p(y)\).

sample()[source]

Obtains a structured sample from the distribution \(y \sim p(y)\). TODO: multi-sampling.

property entropy

Computes entropy \(H[p]\) of the distribution \(p(y)\).

cross_entropy(other)[source]

Computes cross-entropy \(H[p,q]\) of self and another distribution.

Parameters

other (StructuredDistribution) – Comparison distribution.

kl(other)[source]

Computes KL-divergence \(KL[p \parallel q]=H[p,q]-H[p]\) of self and another distribution.

Parameters

other (StructuredDistribution) – Comparison distribution.

log_prob(value, **kwargs)[source]

Computes log probability over values \(p(y)\).