How to train a TimeSeries transformer with Trainer?

Hello,

I would like to use Trainer with a TimeSeries transformer and evaluate certain custom metrics in the training and prediction process. I would like to use Trainer instead of a custom loop to benefit from all the optimizations of this class.

However, for the evaluation of the metrics Trainer requires that in the signature of the forward() method ‘labels’ is one of the parameters but it is actually not. The closest parameter to ‘labels’ seems to be ‘future_values’.

How could this be achieved? Should I subclass TimeSeriesTransformerForPrediction and modify the forward() method signature to receive labels and then copy them to future_values? Is there any other approach?

Thank you
David

1 Like

Hello,
I mean something like this:

class TSTForPredictionMod(TimeSeriesTransformerForPrediction):
    def forward(self, labels: Optional[torch.Tensor] = None, **kwargs) -> 
           Union[Seq2SeqTSModelOutput, Tuple]:
        super.forward(future_values=labels, **kwargs)

Thank you
David

1 Like