fishy.models.deep.ordinal¶
Classes
- class fishy.models.deep.ordinal.CumulativeLinkLoss(*args: Any, **kwargs: Any)[source]¶
Bases:
Module- forward(cum_logits, y_true)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class fishy.models.deep.ordinal.EarlyStopping(patience=5, verbose=False, delta=0, path='checkpoint.pt', trace_func=<built-in function print>)[source]¶
Bases:
objectEarly stops the training if validation loss doesnât improve after a given patience.
- class fishy.models.deep.ordinal.PositionalEncoding(d_model: int, dropout: float = 0.1, max_len: int = 5000)[source]¶
Bases:
ModuleStandard sinusoidal positional encoding for Transformers.
- __init__(d_model: int, dropout: float = 0.1, max_len: int = 5000) None[source]¶
Initializes the positional encoding.
- Parameters:
d_model (int) â The model dimension.
dropout (float, optional) â Dropout probability. Defaults to 0.1.
max_len (int, optional) â Maximum sequence length. Defaults to 5000.
- class fishy.models.deep.ordinal.TransformerOrdinal(input_features: int, d_model: int, nhead: int, num_encoder_layers: int, dim_feedforward: int, dropout: float, method: str = 'regression', num_classes: int | None = None, batch_first: bool = True)[source]¶
Bases:
ModuleTransformer model specialized for ordinal regression and classification.
- method¶
Task type (âregressionâ, âclassificationâ, âcoralâ, âclmâ).
- Type:
str
- input_embedding¶
Initial linear projection.
- Type:
nn.Linear
- pos_encoder¶
Positional embeddings.
- Type:
- transformer_encoder¶
Transformer backbone.
- Type:
nn.TransformerEncoder
- output_layer¶
Task-specific output head.
- Type:
nn.Linear
- __init__(input_features: int, d_model: int, nhead: int, num_encoder_layers: int, dim_feedforward: int, dropout: float, method: str = 'regression', num_classes: int | None = None, batch_first: bool = True) None[source]¶
Initializes the TransformerOrdinal model.
- Parameters:
input_features (int) â Dimensionality of input features.
d_model (int) â Hidden dimension.
nhead (int) â Number of attention heads.
num_encoder_layers (int) â Number of transformer layers.
dim_feedforward (int) â Intermediate dimension of feed-forward layers.
dropout (float) â Dropout probability.
method (str, optional) â Training mode (âregressionâ, âclassificationâ, âcoralâ, âclmâ). Defaults to âregressionâ.
num_classes (Optional[int], optional) â Number of target classes. Required for non-regression modes. Defaults to None.
batch_first (bool, optional) â If True, input is (B, S, D). Defaults to True.
- forward(src)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
Functions
- fishy.models.deep.ordinal.evaluate(model, data_loader, device, method)[source]¶
Calculates MAE and Balanced Classification Accuracy (BCA).
- fishy.models.deep.ordinal.train(model, optimizer, criterion, train_df, val_df, epochs, device, batch_size, method, num_classes, patience, checkpoint_path, verbose=False)[source]¶
s