I don’t know how y and y' are defined, e.g. is y a one-hot encoded target tensor acting as a mask (so alternatively also indexing would work using the class indices directly)?
If so, I guess the class index in w would be missing but you could also compare it to the used formula in nn.CrossEntropyLoss 1 to make sure it’s equivalent.