The exp(x)/sum(exp(x)) defines the softmax.
Since p_i is the target, we avoid storing it in a one-hot encoded format (one 1, everything else zeros) and multiplying with it, as it’s wasteful. Instead we directly index the logit via x[class].