# How to train a TimeSeries transformer with Trainer?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-train-a-timeseries-transformer-with-trainer%2F140081%3E%5C
**Category:** 🤗Transformers\
**Created:** [February 10, 2025, 8:01pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-train-a-timeseries-transformer-with-trainer%2F140081 "2025-02-10T20:01:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zulok33](https://avatars.discourse-cdn.com/v4/letter/z/46a35a/32.png) [@zulok33](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fzulok33)%5C
**Post date:** [February 10, 2025, 8:01pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-train-a-timeseries-transformer-with-trainer%2F140081%2F1 "2025-02-10T20:01:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zulok33](https://avatars.discourse-cdn.com/v4/letter/z/46a35a/32.png) [@zulok33](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fzulok33)%5C
**Post date:** [February 11, 2025, 10:13pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-train-a-timeseries-transformer-with-trainer%2F140081%2F2 "2025-02-11T22:13:33Z")

</div>

Hello,  
I mean something like this:

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

```

Thank you  
David
