The interview problem

Practice prompt

Derive a Gaussian negative log-likelihood loss when prediction noise changes with the input.

Original practice, not a reported company interview. Scenarios and numbers are illustrative. Interview date: not applicable. Sources retrieved October 1, 2026.

1. Scope and worked approach

Assume conditional Gaussian residuals and predict mean mu plus log variance s. Ignoring a constant, loss is one half of s+(y−mu)^2 exp(−s). The residual term discourages overconfidence while the log-variance term penalizes arbitrarily large variance. Evaluate both point error and interval calibration on held-out data; variance describes the model's assumed conditional noise, not every source of uncertainty.

2. Trace the design or derivation

Predict mean and log variance
  → compute residual
  → penalize variance and error
  → check coverage

For a fixed nonzero residual, differentiating with respect to log variance sets the fitted variance to the squared residual in a one-example unconstrained optimum. That is not a sensible per-example generalization guarantee; shared modeling, regularization and held-out coverage are what make variance predictions useful.

3. Calculate the example

For residual 2 and variance 4, the loss excluding the constant is 0.5×(log 4+1), approximately 1.1931. With variance 1 it is 2. Increasing variance can reduce residual penalty but eventually raises the log term.

4. Failure cases and trade-offs

Variance can collapse on perfectly fitted training points or absorb mean-model misspecification. Bounds and regularization need justification. Gaussian tails may understate extremes; alternative likelihoods trade simplicity for robustness. Do not present predicted noise as a complete measure of distribution-shift uncertainty.

5. Validation, follow-ups and self-review

Check gradients and interval coverage by input slice. Follow-up: how would a heavy-tailed likelihood change outlier sensitivity? Self-review: distinguish aleatoric noise, parameter uncertainty and misspecified means.

Sources and related practice

Technical reference: docs.pytorch.org — Gaussian likelihood with predicted variance.

Source publication/update: Not established. Retrieved October 1, 2026. The workflow, calculations and review exercises are original; this reference is not evidence that a company asked this question.

Continue with Regression metrics and asymmetric errors; Serve forecast intervals with coverage monitoring.

Continue your preparation

Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.