Johannes_L:

The CrossEntropyLoss wants the output as (NxC) and the target as (N).


This would be the expected shapes for the “standard” multi-class classification use case, but as described in the docs 34 the expected tensor can have additional dimensions (d1, d2, ... , dk).
For your use case you could thus use the model output as [batch_size, nb_classes, seq_len] and the target as [batch_size, seq_len].