Excuse me, I have one experiment named “opinion and aspect co-extraction” which judges whether the word in a sentence is opinion and aspect or not, and labels them as follows:

0：the background word
1：the begin of an aspect word
2:   the include of an aspect word
3：the begin of an opinion word
4：the include of an opinion word

Therefore, there are five classes for each word in a sentence.And the example of input_x(after word to index) and output(after logsoftmax) and y(gold label) of one batch of sentences like that:

input_x: batch_size x sentence_length
output: batch_size x sentence_length x class_possibility
y: batch_size x sentence_length

After I input the input_x and train one epoch and get the output, i use the nn.NLLLoss to compute the loss between output and y,but it occured some error. The next I will use some code simulate the situation.
# the output of one batch of 10 sentences, every sentence has 78 words, and every word has a score after logsoftmax
p = torch.rand(10,78,5)
# the gold label of one batch of 10 sentences, every sentence has 78 words, and each word have one index of 0~4 which indicate its property, the detail meaning as above 
y = torch.ones(10,78).long()
# use the NLLLoss function
loss = nn.NLLLoss()
# get the loss value
r = loss(p,y)

and it report such error:

ValueError: Expected target size (10, 5), got torch.Size([10, 78])

so, i want to how can i cmpute the loss between the output and gold label of a batch?