I fumbled around for a bit trying to remember how L1 differs from L2 in terms of gradients and what that means for a network you'd actually train.
First, clarify that 1-NN with L1 distance can be implemented by computing pairwise L1 distances between query and support points, then using a softmin or hard argmin to select the nearest neighbor. Then, describe how to construct a neural network that computes L1 distances and performs the selection, possibly using a differentiable relaxation for end-to-end training.
Pro tip: Mention that L1 distance is more robust to outliers than L2, and that using a differentiable softmin (e.g., with a temperature parameter) allows gradient-based learning while approximating hard 1-NN. Also, note that for large datasets, approximate nearest neighbor methods like LSH for L1 may be needed.
State that 1-NN classification assigns the label of the nearest training example under L1 distance. Assume we have a support set of labeled points and a query point, and we want to implement this using a neural network, possibly for end-to-end learning.
For a query x and each support point x_i, compute the L1 distance ||x - x_i||_1. This can be done by broadcasting and summing absolute differences, or by using a network layer that computes absolute differences and sums them.
Use an argmin operation to find the index of the minimum distance. For a differentiable implementation, replace argmin with a softmin (e.g., softmax over negative distances) to get a weighted combination of labels.
If using hard 1-NN, output the label of the nearest neighbor. If using softmin, output a weighted vote of labels, which can be trained end-to-end with backpropagation.
Mention that L1 distance may be preferred for robustness, but computing all pairwise distances is O(ND). For large N, consider approximate methods or metric trees. Also, note that softmin temperature controls the approximation to hard 1-NN.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.