Back to models
Classifier

ConvTranClassifierTorch

ConvTran classifier in PyTorch.

Quickstart

python
from sktime.classification.deep_learning.convtran import ConvTranClassifierTorch

estimator = ConvTranClassifierTorch(net_type: str='C-T', activation: str | None | Callable=None, activation_hidden: str | None | Callable='relu', emb_size: int=16, dim_ff: int=256, num_heads: int=8, dropout: float=0.01, use_abs_pos_encoding: bool=True, use_rel_pos_encoding: bool=True, abs_pos_encoding_scheme: str | None='tAPE', rel_pos_encoding_scheme: str | None='erpe', num_epochs: int=100, batch_size: int=1, optimizer: str | None | Callable='RMSprop', criterion: str | None | Callable='CrossEntropyLoss', callbacks: None | str | tuple [str, ... ]='ReduceLROnPlateau', optimizer_kwargs: dict | None=None, criterion_kwargs: dict | None=None, callback_kwargs: dict | None=None, lr: float=0.001, verbose: bool=False, random_state: int=0)

Parameters(22)

net_typestr, default=”C-T”
Network type to use. Should be one of “T” (Transformer), “C-T” (ConvTran) or “C-CT” (Causal ConvTran).
activationstr, Callable, or None, default=None

Activation applied to the output layer.

Permitted values:

  • None: no activation is applied to the output layer and the network returns raw outputs (logits). This is typically required when using CrossEntropyLoss, which expects logits as input.

  • str: name of a class in torch.nn. Case-sensitive names are recommended and must match PyTorch (e.g., "ReLU", "LeakyReLU"). Lowercase aliases for common activations are also accepted (e.g., "relu" is resolved to "ReLU"). The class is instantiated with default constructor arguments. Must be a valid torch.nn activation; see https://pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearity

  • torch.nn.Module: an instance of a torch.nn.Module subclass, for example torch.nn.ReLU(). Arbitrary callables are not supported.

activation_hiddenstr, Callable, or None, default=”relu”

Activation applied to the hidden layers.

Permitted values:

  • None: no activation is applied to the hidden layers.

  • str: name of a class in torch.nn. Case-sensitive names are recommended and must match PyTorch (e.g., "ReLU", "LeakyReLU"). Lowercase aliases for common activations are also accepted (e.g., "relu" is resolved to "ReLU"). The class is instantiated with default constructor arguments. Must be a valid torch.nn activation; see https://pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearity

  • torch.nn.Module: an instance of a torch.nn.Module subclass, for example torch.nn.ReLU(). Arbitrary callables are not supported.

emb_sizeint, default=16
Embedding dimension used in attention and feed-forward blocks.
dim_ffint, default=256
Hidden dimension of the feed-forward block.
num_headsint, default=8
Number of attention heads.
dropoutfloat, default=0.01
Dropout rate applied in attention and feed-forward blocks.
use_abs_pos_encodingbool, default=True
Whether to apply absolute positional encoding.
use_rel_pos_encodingbool, default=True
Whether to apply relative positional encoding.
abs_pos_encoding_schemestr or None, default=”tAPE”
Absolute positional encoding scheme. Supported values: “tAPE”, “sin”, “learn”, or None.
rel_pos_encoding_schemestr or None, default=”erpe”
Relative positional encoding scheme. Supported values: “erpe”, “vector”, or None.
num_epochsint, default = 100
The number of epochs to train the model.
batch_sizeint, default = 1
The size of each mini-batch during training.
optimizerstr or None or an instance of optimizers

defined in torch.optim, default = “RMSprop” The optimizer to use for training the model. List of available optimizers: https://pytorch.org/docs/stable/optim.html#algorithms

criterionstr or None or an instance of a loss function

defined in PyTorch, default = “CrossEntropyLoss” The loss function to be used in training the neural network. List of available loss functions: https://pytorch.org/docs/stable/nn.html#loss-functions

callbacksNone or str or a tuple of str, default = “ReduceLROnPlateau”

Learning rate schedulers applied during training. Currently only learning rate schedulers are supported as callbacks. If more than one scheduler is passed, they are applied sequentially in the order they are passed. If None, then no learning rate scheduler is used. Note: Since PyTorch learning rate schedulers need to be initialized with the optimizer object, we only accept the class name (str) of the scheduler here and do not accept an instance of the scheduler. As that can lead to errors and unexpected behavior. List of available learning rate schedulers: https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate

optimizer_kwargsdict or None, default = None
Additional keyword arguments to pass to the optimizer.
criterion_kwargsdict or None, default = None
Additional keyword arguments to pass to the loss function.
callback_kwargsdict or None, default = None
The keyword arguments to be passed to the callbacks.
lrfloat, default = 0.001
The learning rate to use for the optimizer.
verbosebool, default = False
Whether to print progress information during training.
random_stateint, default = 0
Seed to ensure reproducibility.

Examples

>>> from sktime.classification.deep_learning.convtran import ConvTranClassifierTorch
>>> from sktime.datasets import load_unit_test
>>> X_train, y_train = load_unit_test (split = "train")
>>> X_test, y_test = load_unit_test (split = "test")
>>> clf = ConvTranClassifierTorch (num_epochs = 20, batch_size = 4)
>>> clf. fit (X_train, y_train) ConvTranClassifierTorch(
... )