KatInterview

Noisy Image Dataset Cleanup and a NumPy Two-Layer Net with Gradient Checks

Machine LearningModel answer
HardModel answerMachine Learninglabel-noiseclass-imbalancebackpropagation

Last updated

Plan a data-quality pipeline for a noisy, imbalanced small-image dataset, then derive and numerically verify backprop for a two-layer softmax network in NumPy.

You have a collection of 32×32 color images spanning 10 to 20 classes. The data is known to be imperfect: roughly 8-15% of labels are wrong, some files are corrupted or of very low quality, and the class frequencies are skewed.

Part 1: Baseline and data-quality plan

Describe how you would build a reliable classifier on this data. Your answer should cover:

  • A baseline model and the metrics you log for every run.
  • How you would build train, validation and test splits that can be trusted, including how you prevent leakage.
  • How you would detect and quantify label noise, and how you would find corrupted or low-quality images.
  • How you would handle class imbalance.
  • A comparison of mitigation strategies, such as pruning samples by model confidence, co-teaching, and strong augmentation like MixUp or CutMix. For each, explain how you would measure its effect on top-1 accuracy, calibration, and the confusion matrix.

Part 2: Backprop from first principles

Using only NumPy-style linear algebra, define a network of the form linear → ReLU → linear → softmax cross-entropy.

  • Write the forward and backward passes and give the analytical gradients for all parameters.
  • Explain how you would validate them with a numerical gradient check.
  • Discuss numerical stability (log-sum-exp), weight initialization, and regularization.
  • Explain how you would extend the approach to a convolutional network for this dataset.

Hints

Hint 1

Fix the evaluation set first: if the test labels are also noisy, you cannot tell whether a mitigation really helped. Think about grouping near-duplicates before splitting and about a small hand-verified subset.

Hint 2

To flag noisy labels you need predictions that were not trained on the sample itself. Out-of-fold probabilities with per-class thresholds expose likely mislabels and which class pairs get confused.

Hint 3

For the gradient at the logits, the softmax plus cross-entropy combination simplifies to (probabilities minus one-hot) divided by the batch size. The ReLU simply masks the upstream gradient where the pre-activation was not positive.

Hint 4

For the gradient check, use centered differences with a small step in float64, compare with a relative error, and turn off anything stochastic. Check a random subset of entries per parameter.