Skip to content
class

OneHotCategoricalStraightThrough

extendsOneHotCategorical
OneHotCategoricalStraightThrough(probs: Tensor | None = None, logits: Tensor | None = None, validate_args: bool | None = None)

Reparameterisable OneHotCategorical based on the straight-through gradient estimator.

Uses the straight-through estimator (Bengio et al., 2013): the forward pass returns a discrete one-hot sample while the backward pass propagates gradients through probs.

Parameters

probsTensor | None= None
Non-negative probability vector (..., K). Normalised internally. Mutually exclusive with logits.
logitsTensor | None= None
Unnormalised log-probabilities (..., K). Mutually exclusive with probs.
validate_argsbool | None= None
If True, validate parameter constraints at construction time.

Used by 1

Instance methods

2
fn

expand

→Self
expand(batch_shape: Sequence[int], _instance: Self | None = None)

Return a new OneHotCategoricalStraightThrough with batch dimensions expanded.

fn

rsample

→Tensor
rsample(sample_shape: tuple[int, ...] = ())

Draw one-hot samples with straight-through gradients through probs.