PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Machine Learning/Meta

Implement 1NN Embeddings and Forward Pass

Last updated: Jun 5, 2026

Quick Overview

This question evaluates implementation skills in machine learning inference, specifically batch 1-nearest-neighbor classification, dense neural network forward propagation, embedding generation, and precise tensor shape reasoning within numerical linear algebra.

  • hard
  • Meta
  • Machine Learning
  • Machine Learning Engineer

Implement 1NN Embeddings and Forward Pass

Company: Meta

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: hard

Interview Round: Technical Screen

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.

Quick Answer: This question evaluates implementation skills in machine learning inference, specifically batch 1-nearest-neighbor classification, dense neural network forward propagation, embedding generation, and precise tensor shape reasoning within numerical linear algebra.

Related Interview Questions

  • Design and evaluate an ads ranking algorithm - Meta (easy)
  • How would you design a Shop Ads ranking algorithm? - Meta (easy)
  • Derive Linear Regression Solution - Meta (medium)
  • Explain key ML metrics and techniques - Meta (medium)
  • Design an ad recommendation ranking approach - Meta (easy)
Meta logo
Meta
May 19, 2026, 12:00 AM
Machine Learning Engineer
Technical Screen
Machine Learning
1
0

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.

Solution

Show

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Machine Learning•More Meta•More Machine Learning Engineer•Meta Machine Learning Engineer•Meta Machine Learning•Machine Learning Engineer Machine Learning
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.