The cross-entropy loss for a particular vector of output scores and a target index is the value at that index of the negative log softmax of the vector of scores, so you can run negative log softmax on the whole score tensor, pick out the values you want using gather (advanced indexing was briefly semi-supported for this, and will be fully supported eventually), then sum/average the results