SoftmaxCategoricalConverter#

class sdm.prior.SoftmaxCategoricalConverter(output_mode: str | HP[str], sample_categories: bool | HP[bool] = True, temperature: HP[float] | Correlated[float] | float | None = None, argmax_prob: float = 0.0, argmax_bias_floor: HP[float] | Correlated[float] | None = None, *, root_sampler: RootSampler | None = None, random_fn: RandomFunction | None = None)#

Bases: CategoricalConverter

Convert latent channels to category indices with softmax or argmax.

Each channel is standardized over rows, scaled, and given a random category bias. Categories are sampled from softmax probabilities or selected by argmax.

Parameters:
  • output_mode (str | HP[str]) – Representation passed to child nodes. "identity" keeps input slices, "index" repeats category indices across channels, and "embedding" supplies random category embeddings.

  • sample_categories (bool | HP[bool]) – Whether to sample categories rather than take the argmax.

  • temperature (HP[float] | Correlated[float] | float | None) – Logit multiplier. Defaults to Correlated(LogUniform(0.1, 10.0)).

  • argmax_prob (float) – Probability of overriding sample_categories with argmax using category biases floored at -argmax_bias_floor.

  • argmax_bias_floor (HP[float] | Correlated[float] | None) – Sampler for the magnitude of the negative bias floor. Defaults to Correlated(LogUniform(0.5, 6.0)).

  • root_sampler (RootSampler | None) – Initial values for category embeddings. Required for "embedding" output mode.

  • random_fn (RandomFunction | None) – Random function applied to category embeddings. Required for "embedding" output mode.

forward(slices: Tensor, generator: Generator | None = None) → tuple[Tensor, Tensor]#

Return category indices and slices passed to child nodes.

Parameters:
  • slices (Tensor) – Node-channel slices per column with shape [C, K, R] for columns, categories, and rows. The category count K may be ragged across columns.

  • generator (Generator | None) – Pseudorandom generator.

Returns:

Category indices with shape [C, R] and updated node-channel slices with the input shape for use by child nodes.

Return type:

tuple[Tensor, Tensor]