nb_samples defines the number of samples we are dealing with.
In your code it would be the batch size, if you apply this code in your training loop, or the length of your dataset, if you collect all predictions and targets during training.
The code first creates a confusion matrix and uses it to compute the TP, TN, FP and FN stats.
Have a look at the Wikipedia info about Confusion Matrix 22 for more information.