ValueError when using PatchTSTForClassification

I’m attempting to adapt the PatchTST blog post (Patch Time Series Transformer in Hugging Face) to use PatchTSTForClassification. I’m getting the following error:

ValueError: The model did not return a loss from the inputs, only the following keys: prediction_logits. For reference, the inputs it received are past_values.

I know that it should be receiving past_values and target_values during training which doesn’t seem to be happening. In addition, I’m not sure how to get it to return loss? Any help is much appreciated.

Does this example help, PatchTST?

from transformers import PatchTSTConfig, PatchTSTForClassification

# classification task with two input channel2 and 3 classes
config = PatchTSTConfig(
    num_input_channels=2,
    num_targets=3,
    context_length=512,
    patch_length=12,
    stride=12,
    use_cls_token=True,
)
model = PatchTSTForClassification(config=config)

# during inference, one only provides past values
past_values = torch.randn(20, 512, 2)
outputs = model(past_values=past_values)
labels = outputs.prediction_logits

You need to get prediction_logits from output.