So at a high level - what your code is doing is first getting the predicted tensor pred, and then element-wise comparing them to the values in tensor target, setting them to True if the elements match and False if not. And then when you take the sum(), you’re simply summing over the True values, and that gives you the number of correct predictions.