Thanks for this.  Take note that since you are using sum to sum over the whole tensor, torch.mean would be superfluous as you’d be taking the mean over a single value.  You can remove the call to torch.mean for the precision and recall and just compute the single values on their own.