Distribution#

StructuredDistribution#

class supar.structs.dist.StructuredDistribution(scores: torch.Tensor, **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)\).

property mode#

Returns the mode of the distribution.

kmax(k: int) torch.Tensor[source]#

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

topk(k: int) Union[torch.Tensor, Iterable][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: StructuredDistribution) torch.Tensor[source]#

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

Parameters

other (StructuredDistribution) – Comparison distribution.

kl(other: StructuredDistribution) torch.Tensor[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: torch.LongTensor, *args, **kwargs) torch.Tensor[source]#

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