Implement a small machine learning inference pipeline.
Part A: Implement batch 1-nearest-neighbor classification. Given a training feature matrix X_train with shape (N, D), training labels y_train with shape (N,), and a query feature matrix X_query with shape (M, D), compute the squared Euclidean distance from each query row to each training row and return one predicted label per query. If there is a distance tie, choose the smallest training index. State the shape of each intermediate tensor.
Part B: Implement a dense neural network forward pass. Given input X with shape (B, D0) and a list of layers [(W1, b1), ..., (WL, bL)], where Wi has shape (D_{i-1}, D_i) and bi has shape (D_i,), apply XW + b at each layer. Apply ReLU after every hidden layer and no activation after the final layer. Return the final output and, if useful, the intermediate activations. Validate all dimensions.
Part C: Combine the two parts. Transform both training inputs and query inputs through the same neural network to produce embeddings, then perform 1-nearest-neighbor classification in that embedding space.