Code Room
Code reviewMedium
Question
Review this PyTorch validation function.
Validation accuracy is noisy across runs and lower than expected for a model with dropout and batchnorm. What's wrong?
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
import torch def validate(model, val_loader): correct, total = 0, 0 for xb, yb in val_loader: logits = model(xb) # model has Dropout + BatchNorm layers preds = logits.argmax(dim=1) correct += (preds == yb).sum().item() total += yb.size(0) return correct / totalRun or narrate your approach, then ask the coach.