ECOC#

class sdm.models.ECOC(max_classes: int)#

Bases: Module

Extend a classifier with error-correcting output codes.

For more than max_classes classes, this uses the approach from TabPFN Extensions: batched tasks each separate max_classes - 1 classes and merge the rest. Scores average log probabilities over tasks where each class is separate. Apply softmax to normalize them.

Parameters:

max_classes (int) – Number of classes supported by the model.

forward(model: Module, x: Tensor, y: Tensor, *, num_classes: int, num_members: int = 1, cache: Cache | None = None, generator: Generator | None = None, **kwargs: Any) → Tensor#

Predict scores over the original classes.

Parameters:
  • model (Module) – Classifier accepting model(x, y, **kwargs) with leading batch dimensions and returning [..., R_query, max_classes] logits. Must accept cache when caching is used.

  • x (Tensor) – Context then query features of shape [..., R, C], for R rows and C columns.

  • y (Tensor) – Integer context labels in [0, num_classes), of shape [..., R_context].

  • num_classes (int) – Total number of target classes K, including those absent from the context.

  • num_members (int) – Number of ensemble members stacked along the first dimension of x and y. Each member draws its own codebook, in member order, as separate calls would.

  • cache (Cache | None) – Cache for model state and the codebook. On replay, pass query-only x, an empty context axis in y, and the same num_classes.

  • generator (Generator | None) – Codebook sampling generator on x.device. Ignored on cache replay.

  • kwargs (Any) – Model arguments. Tensors must broadcast over the leading task dimension.

Returns:

model logits within class capacity, otherwise averaged log probabilities.

Return type:

Scores of shape [..., R_query, K] for the query rows