Tasks¶
Select a task with the learner’s head leaf (learner.params.head.name). The
head maps a representation to predictions and defines the loss and the compatible
metrics. The representation comes directly from a frozen encoder or from a trained
aggregator or decoder; see Modeling
for the paths that produce it.
Task Zoo¶
Config name |
Loss |
Default metrics |
When to use |
|---|---|---|---|
|
Cross-entropy |
|
Two-class labels; see Classification |
|
Cross-entropy |
|
Two or more classes; see Classification
Use
binary_classification when the problem is strictly binary |
|
Cross-entropy |
|
The multiclass head over |
|
MSE |
|
Ordered integer grades; see Classification |
|
MSE |
|
Continuous targets; see Regression |
|
Discrete-time hazard NLL |
|
Time-to-event with right censoring, over time bins; see Survival |
|
Cox partial likelihood |
|
Time-to-event with right censoring, one risk score; see Survival |
|
CE + soft-Dice |
|
Dense per-pixel classification (the |
|
Foreground-weighted MSE |
|
Cell / nucleus point detection (the |
Head dropout¶
The classification, ordinal-classification, regression and survival heads take an
optional dropout probability, applied to the head’s input — the aggregated
bag representation, or the frozen embedding itself when no aggregator leaves the
head as the only trainable component:
learner:
params:
head:
name: binary_classification
params:
dropout: 0.2
The default is 0.0. Aggregator dropout, set in the aggregator leaf’s
params, is independent.
Regression¶
The regression head maps a feature vector to continuous predictions and
trains with MSE. With one output it reads the value target, predicts
predicted_value, and reports mae and r2 by default.
num_outputs: G regresses G values at once, such as a gene panel. The
head then reads the targets value_0 to value_<G-1>, predicts columns of
the same names, and reports mean_pearson: the Pearson correlation of each
output over the samples, averaged over the outputs. The
HEST scores a closed-form Ridge+PCA probe
with the same columns and metric.
- class soma.models.heads.regression.RegressionHead(input_dim, num_outputs=1, metrics=None, dropout=0.0)¶
Bases:
TaskHeadLinear regression head for one or many outputs.
- Parameters:
input_dim (
int) – Dimension of the input representation.num_outputs (
int) – Number of regressed valuesG. With one output the head reads the cohort’svaluetarget and predictspredicted_value; withG > 1it readsvalue_0 .. value_{G-1}and predicts the same-named columns (a gene panel, say), scored bymean_pearson.metrics (
list[str] |None) – Metrics to compute. Empty uses the regression defaults (mae,r2) for one output andmean_pearsonfor several.dropout (
float) – Probability of zeroing an element of the head’s input, applied before the linear layer.0.0(default) builds no dropout module.
Task-head interface¶
soma.components("heads") lists the registered task heads with their params and
defaults. To bring a custom loss, metric reduction or post-processing, subclass a
built-in head and register it; see A custom component through the registry.
- class soma.models.heads.base.TaskHead(*args, **kwargs)¶
Bases:
ABC,ModuleAbstract base class for task heads.
Maps an aggregated slide representation to task-specific predictions.
Subclasses must implement forward, compute_loss, postprocess, compute_metrics, and extract_targets, and should set target_dtypes. Values decided by the cohort (class counts, label maps, survival bins) come from the
inferhook the head is registered with (ADR 0018).prediction_columns/to_columnsdeclare whatsoma.predict()writes; the base implementation covers soma’s set families.The head owns its target contract:
target_dtypesdeclares the keys it consumes (and their tensor dtypes),extract_targetsmaps aSampleRecordto a dict of raw target values, andcompute_loss/compute_metricsreceive adict[str, Tensor]keyed by those names.