X in the forward function of your network is a 1-D vector, right? (a vector of shape (1, 2)). So you want to call softmax along that dim, so pass dim=1 in your log_softmax. It’s the index of the dimension along which you want softmax to operate, not the number of values in it.