PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Machine Learning/Anthropic

Implement and derive backprop from scratch

Last updated: Apr 8, 2026

Quick Overview

This question evaluates understanding and practical implementation of neural network fundamentals, specifically analytic backpropagation and gradient derivation, numerically stable binary cross-entropy computation, parameter initialization, gradient descent updates, and gradient checking.

  • medium
  • Anthropic
  • Machine Learning
  • Software Engineer

Implement and derive backprop from scratch

Company: Anthropic

Role: Software Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Onsite

From first principles, implement a tiny neural network for binary classification with one hidden layer. Write the forward pass, a cross-entropy loss, and the complete backward pass (no autograd). Derive analytic gradients for all parameters, implement gradient descent, and verify correctness with finite-difference gradient checking. Discuss numerical stability (e.g., log-sum-exp), initialization, activation choices, and how batch size affects variance.

Quick Answer: This question evaluates understanding and practical implementation of neural network fundamentals, specifically analytic backpropagation and gradient derivation, numerically stable binary cross-entropy computation, parameter initialization, gradient descent updates, and gradient checking.

Related Interview Questions

  • Design a Double Descent Experiment - Anthropic (medium)
  • Explain batch inference design - Anthropic (medium)
  • Debug a GRPO training loop and explain ratios - Anthropic (medium)
  • Implement and analyze custom attention - Anthropic (hard)
Anthropic logo
Anthropic
Sep 6, 2025, 12:00 AM
Software Engineer
Onsite
Machine Learning
22
0

Tiny Neural Network (From First Principles): Binary Classification

Context

You will implement and analyze a minimal neural network for binary classification with one hidden layer. Assume a dataset with features X ∈ R^{N×D} and labels y ∈ {0,1}^N. The network has:

  • Hidden layer: H units with an activation (ReLU or tanh).
  • Output layer: 1 unit with a sigmoid for P(y=1|x).

Use vectorized NumPy (or similar) without autograd.

Tasks

  1. Forward pass
    • Define shapes: W1 ∈ R^{D×H}, b1 ∈ R^{H}, W2 ∈ R^{H×1}, b2 ∈ R^{1}.
    • Compute z1 = XW1 + b1, a1 = f(z1), z2 = a1W2 + b2, p = σ(z2).
  2. Loss (numerically stable)
    • Implement binary cross-entropy. Use a stable formulation (e.g., softplus: log(1+exp(x)) or log-sum-exp) to avoid overflow/underflow.
  3. Backward pass (analytic gradients; no autograd)
    • Derive and implement gradients for W1, b1, W2, b2.
  4. Optimization
    • Implement gradient descent updates for all parameters.
  5. Gradient checking
    • Verify gradients by finite differences: g_num ≈ (L(θ+ε) − L(θ−ε)) / (2ε). Report relative errors.
  6. Discussion
    • Numerical stability (sigmoid/logistic loss, softplus/log-sum-exp, log1p, expm1, clipping).
    • Initialization (He vs Xavier; biases).
    • Activation choices (ReLU, tanh, sigmoid; pros/cons).
    • Batch size and gradient variance; learning-rate scaling.

Deliverables

  • Clean, vectorized code for forward, loss, backward, training loop, and gradient check.
  • Short written derivations and notes on the topics above.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Machine Learning•More Anthropic•More Software Engineer•Anthropic Software Engineer•Anthropic Machine Learning•Software 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.