Solved by KFrank in post #2 
              
              
                Hello Dongsup! 

Yes, it is (but the requires_grad=True for s is unnecessary, and 
might cause problems). 
Also, note that you can get rid of the loop by using gather() to 
line up the desired elements of y_pred, as specified by classes, 
with y. 
This is illustrated by the following pytorch version…