TslibBaseModel#

class pytorch_forecasting.models.base._tslib_base_model_v2.TslibBaseModel(loss: Metric, logging_metrics: list[Module] | None = None, optimizer: Optimizer | str | None = 'adam', optimizer_params: dict | None = None, lr_scheduler: str | None = None, lr_scheduler_params: dict | None = None, metadata: dict | None = None)[source]#

Bases: BaseModel

Base class for tslib models.

Parameters:
  • loss (Descendants of pytorch_forecasting.metrics.Metric class) – Loss function to use for training.

  • logging_metrics (Optional[list[nn.Module]], optional) – list of metrics to log during training, validation, and testing.

  • optimizer (Optional[Union[Optimizer, str]], optional) – Optimizer to use for training.

  • optimizer_params (Optional[dict], optional) – Parameters for the optimizer.

  • lr_scheduler (Optional[str], optional) – Learning rate scheduler to use.

  • lr_scheduler_params (Optional[dict], optional) – Parameters for the learning rate scheduler.

  • metadata (Optional[dict], default=None) – Metadata for the model from TslibDataModule.

Methods

forward(x)

Forward pass of the model.

predict_step(batch, batch_idx[, dataloader_idx])

Prediction step for the model.

transform_output(y_hat, target_scale)

Transform the output of the model to the original scale.

forward(x: dict[str, Tensor]) dict[str, Tensor][source]#

Forward pass of the model.

Parameters:

x (dict[str, torch.Tensor]) – Dictionary containing input tensors.

Returns:

Dictionary containing output tensors. These can include - predictions:

Prediction_output of shape (batch_size, prediction_length, target_dim)

  • attention_weights: Optionally, output attention weights

Return type:

dict[str, torch.Tensor]

predict_step(batch: tuple[dict[str, Tensor]], batch_idx: int, dataloader_idx: int = 0) Tensor[source]#

Prediction step for the model.

Parameters:
  • batch (tuple[dict[str, torch.Tensor]]) – Batch of data containing input tensors.

  • batch_idx (int) – Index of the batch.

  • dataloader_idx (int) – Index of the dataloader.

Returns:

Predicted output tensor.

Return type:

torch.Tensor

transform_output(y_hat: Tensor | list[Tensor], target_scale: dict[str, Tensor] | None) Tensor | list[Tensor][source]#

Transform the output of the model to the original scale.

Parameters:
  • y_hat (Union[torch.Tensor, list[torch.Tensor]]) – Dictionary containing the model output.

  • target_scale (Optional[dict[str, torch.Tensor]]) – Dictionary containing the target scale for inverse transformation.

Returns:

Dictionary containing the transformed output.

Return type:

Union[torch.Tensor, list[torch.Tensor]]

Notes

WARNING! : This is a temporary implementation and is meant to be replaced with a more robust scaling and normalization module for v2 of PTF.