I’m learning to use PyTorch to solve a multi-item, multi-feature, time sequence prediction problem.
In brief, my question is why the size of output and target of crossentropy loss function cannot be the same.
For instance, size of output is (batch_size, num_items), in which each element is a value fitted to the ground true class. Like matrix A:
[[ 0.5 2.1 4.8 3.2 ]
[ 5.0 4.3 2.7 0.2 ]
[ 3.7 0.3 2.0 1.5 ]]
(each row is one batch, and each column is for an item.)
Accordingly, size of the target is also (batch_size, num_items), like matrix B:
[[ 1 0 2 1 ]
[ 0 3 2 1 ]
[ 1 1 1 0 ]]
I suppose the most suitable loss function for my model in pytorch should be crossentropy(one of the pointwise methods?), but if that’s not true, please correct me.
Based on the Doc of pytorch loss functions, Input(output of model): (N, C) where C = number of classes, or (N, C, d_1, d_2, …, d_K) in the case of K-dimensional loss.
Target: (N) where each value is 0:C−1, or (N, d_1, d_2, …, d_K) in the case of K-dimensional loss.
How can I transform or squeeze the shape of my output and target to fit the requirement of crossentropy loss function? Thanks a lot.