Skip to content

TSPulseClassifier

TSPulseClassifier

class TSPulseClassifier(model_path='ibm-granite/granite-timeseries-tspulse-r1', revision='tspulse-block-dualhead-512-p16-r1', config=None, context_length=512, scaling=True, batch_size=32, epochs=1, learning_rate=0.001, freeze_backbone=True, train_val_split=0.0, device='auto', seed=42)[source]

Time series classifier wrapping IBM TSPulse via granite-tsfm.

Loads a pretrained TSPulse backbone from Hugging Face, freezes most backbone weights, and fine-tunes the classification head and patch-embedding layers on the training data.

Implementation adapted from [1].

Parameters:
model_pathstr, default=”ibm-granite/granite-timeseries-tspulse-r1”

Hugging Face model id or local path.

revisionstr, default=”tspulse-block-dualhead-512-p16-r1”

Model revision on the Hugging Face Hub.

configdict, optional, default=None

Extra keyword arguments forwarded to tsfm_public.models.tspulse.TSPulseForClassification.from_pretrained.

Any key you supply overrides the built-in default for that key, except for the following two keys which are always inferred from the training data:

  • num_input_channels: set to the number of channels in X

  • num_targets: set to the number of distinct labels in y

If config is None, then following default overrides are applied:

  • head_gated_attention_activation="softmax": gated attention activation in the classification head

  • channel_virtual_expand_scale=2: virtual expansion factor for channel mixing in the decoder/head

  • mask_ratio=0.3: fraction of patches masked during training (use 0 to disable)

  • head_reduce_d_model=1: reduction factor for model dimension in the head

  • disable_mask_in_classification_eval=True: disables masking at evaluation/prediction time

  • fft_time_consistent_masking=True: uses masked time-series for FFT during training

  • decoder_mode="mix_channel": decoder channel mixing mode (alternative: "common_channel")

  • head_aggregation_dim="patch": aggregation dimension used by the head

  • head_aggregation=None: use model-default aggregation module

  • loss="cross_entropy": loss for classification fine-tuning

  • ignore_mismatched_sizes=True: allows loading when head shapes differ from the checkpoint

context_lengthint, default=512

Series length passed to the preprocessor and dataset.

scalingbool, default=True

Whether to scale input channels in the preprocessor.

batch_sizeint, default=32

Training batch size.

epochsint, default=1

Number of fine-tuning epochs.

learning_ratefloat, optional, default=1e-3

Optimizer learning rate for fine-tuning.

freeze_backbonebool, default=True

If True, freeze backbone weights except patch-embedding layers.

train_val_splitfloat, default=0.0

Fraction of training data held out for validation during fine-tuning. 0.0 uses all training data.

devicestr, default=”auto”

PyTorch device ("auto", "cpu", "cuda", "mps").

seedint, default=42

Random seed for training.

Attributes:
is_fitted

Whether fit has been called.

References

Examples

>>> from sktime.classification.foundation_models.tspulse import TSPulseClassifier
>>> from sktime.datasets import load_unit_test
>>> X_train, y_train = load_unit_test(split="train", return_type="nested_univ")
>>> X_test, _ = load_unit_test(split="test", return_type="nested_univ")
>>> clf = TSPulseClassifier(epochs=1, batch_size=8)
>>> clf.fit(X_train, y_train)
>>> y_pred = clf.predict(X_test)

Methods

check_is_fitted([method_name])

Check if the estimator has been fitted.

clone()

Obtain a clone of the object with same hyper-parameters and config.

clone_tags(estimator[, tag_names])

Clone tags from another object as dynamic override.

create_test_instance([parameter_set])

Construct an instance of the class, using first test parameter set.

create_test_instances_and_names([parameter_set])

Create list of all test instances and a list of names for them.

fit(X, y)

Fit time series classifier to training data.

fit_predict(X, y[, cv, change_state])

Fit and predict labels for sequences in X.

fit_predict_proba(X, y[, cv, change_state])

Fit and predict labels probabilities for sequences in X.

get_class_tag(tag_name[, tag_value_default])

Get class tag value from class, with tag level inheritance from parents.

get_class_tags()

Get class tags from class, with tag level inheritance from parent classes.

get_config()

Get config flags for self.

get_fitted_params([deep])

Get fitted parameters.

get_param_defaults()

Get object's parameter defaults.

get_param_names([sort])

Get object's parameter names.

get_params([deep])

Get a dict of parameters values for this object.

get_tag(tag_name[, tag_value_default, ...])

Get tag value from instance, with tag level inheritance and overrides.

get_tags()

Get tags from instance, with tag level inheritance and overrides.

get_test_params([parameter_set])

Return testing parameter settings for the estimator.

is_composite()

Check if the object is composed of other BaseObjects.

load_from_path(serial)

Load object from file location.

load_from_serial(serial)

Load object from serialized memory container.

predict(X)

Predicts labels for sequences in X.

predict_proba(X)

Predicts labels probabilities for sequences in X.

reset()

Reset the object to a clean post-init state.

save([path, serialization_format])

Save serialized self to bytes-like object or to (.zip) file.

score(X, y)

Scores predicted labels against ground truth labels on X.

set_config(**config_dict)

Set config flags to given values.

set_params(**params)

Set the parameters of this object.

set_random_state([random_state, deep, ...])

Set random_state pseudo-random seed parameters for self.

set_tags(**tag_dict)

Set instance level tag overrides to given values.