PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Machine Learning/OpenAI

Compute entropy and implement 1-NN

Last updated: May 23, 2026

Quick Overview

This question evaluates skills in probabilistic modeling and numerical methods (entropy computation from logits emphasizing numerical stability and streaming aggregation) as well as vectorized linear-algebra implementation and model interpretation (1-nearest-neighbor using L2/L1 distances and its expression as a neural-network forward pass) within the Machine Learning domain. It is commonly asked to assess a candidate's ability to implement efficient, numerically robust algorithms and to connect practical implementations to neural-network abstractions, testing both practical application and conceptual understanding.

  • medium
  • OpenAI
  • Machine Learning
  • Machine Learning Engineer

Compute entropy and implement 1-NN

Company: OpenAI

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Onsite

You are given two machine-learning coding tasks. 1. Entropy from logits Given a vector of real-valued logits z = [z1, z2, ..., zn], define p = softmax(z). Compute the categorical entropy H(p) = -sum_i p_i log(p_i). Your implementation should be numerically stable and should use the log-sum-exp trick. Then extend the method to the case where the logits arrive as a stream of blocks, so the full vector may not fit in memory. Describe how to compute the same entropy online. 2. Vectorized 1-nearest neighbor and neural-network interpretation Given training examples X_train with shape (n, d), labels y_train with shape (n,), and query examples X_query with shape (m, d), implement 1-nearest-neighbor prediction using L2 distance. Do not use Python loops over examples; use NumPy-style vectorization. Then express L2 1-nearest-neighbor inference as a neural-network forward pass using a linear layer followed by softmax. Finally, explain how the construction changes if the distance metric is L1 instead of L2.

Quick Answer: This question evaluates skills in probabilistic modeling and numerical methods (entropy computation from logits emphasizing numerical stability and streaming aggregation) as well as vectorized linear-algebra implementation and model interpretation (1-nearest-neighbor using L2/L1 distances and its expression as a neural-network forward pass) within the Machine Learning domain. It is commonly asked to assess a candidate's ability to implement efficient, numerically robust algorithms and to connect practical implementations to neural-network abstractions, testing both practical application and conceptual understanding.

Related Interview Questions

  • Implement 1NN with NumPy - OpenAI (medium)
  • Defend a Research Direction and Experiment Design - OpenAI (medium)
  • Debug MiniGPT and Backpropagate Matmul - OpenAI (medium)
  • Filter Bad Human Annotations - OpenAI (medium)
  • Implement Backprop for a Tiny Network - OpenAI (hard)
OpenAI logo
OpenAI
Apr 24, 2026, 12:00 AM
Machine Learning Engineer
Onsite
Machine Learning
3
0

You are given two machine-learning coding tasks.

  1. Entropy from logits Given a vector of real-valued logits z = [z1, z2, ..., zn], define p = softmax(z). Compute the categorical entropy H(p) = -sum_i p_i log(p_i). Your implementation should be numerically stable and should use the log-sum-exp trick. Then extend the method to the case where the logits arrive as a stream of blocks, so the full vector may not fit in memory. Describe how to compute the same entropy online.
  2. Vectorized 1-nearest neighbor and neural-network interpretation Given training examples X_train with shape (n, d), labels y_train with shape (n,), and query examples X_query with shape (m, d), implement 1-nearest-neighbor prediction using L2 distance. Do not use Python loops over examples; use NumPy-style vectorization.

Then express L2 1-nearest-neighbor inference as a neural-network forward pass using a linear layer followed by softmax. Finally, explain how the construction changes if the distance metric is L1 instead of L2.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Machine Learning•More OpenAI•More Machine Learning Engineer•OpenAI Machine Learning Engineer•OpenAI Machine Learning•Machine Learning Engineer Machine Learning
PracHub

Master your tech interviews with 7,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.