Deep Learning Model Evaluation Questions
Covers evaluation strategies and debugging techniques specific to deep learning models during development and training. Topics include selection and interpretation of evaluation metrics for classification, regression, and generative models (for example Frechet Inception Distance, Inception Score, BLEU), validation strategies and cross validation where applicable, learning curves and validation curves to detect underfitting and overfitting, bias variance tradeoffs, regularization techniques such as dropout, weight decay, early stopping, and data augmentation, and approaches to debug model failures (gradient checking, loss surface inspection, vanishing or exploding gradients, numerical stability). Includes hyperparameter search diagnostics, model interpretability checks, unit tests for model components, sanity checks for data labels and preprocessing, and experiment tracking to reproduce and compare results.
Sample Answer
Sample Answer
Sample Answer
Sample Answer
import numpy as np
from scipy.special import softmax
def ece_multiclass(logits, labels, n_bins=10, binning='equal-mass', per_class=False):
"""
logits: (N, C) numpy
labels: (N,) integer class indices
binning: 'equal-mass' or 'equal-width'
per_class: if True compute classwise ECE dict (average of binary ECEs weighted by support)
Returns: ece (float), bins_summary (list of dicts), class_ece (dict or None)
"""
probs = softmax(logits, axis=1)
conf = probs.max(axis=1)
pred = probs.argmax(axis=1)
N = len(labels)
# Determine bin edges
if binning == 'equal-width':
edges = np.linspace(0.0, 1.0, n_bins+1)
else: # equal-mass quantile bins
quantiles = np.linspace(0, 1, n_bins+1)
edges = np.unique(np.quantile(conf, quantiles))
if len(edges)-1 < n_bins:
# fall back to equal-width if not enough unique edges
edges = np.linspace(0.0, 1.0, n_bins+1)
ece = 0.0
bins_summary = []
for i in range(len(edges)-1):
lo, hi = edges[i], edges[i+1]
# include rightmost edge
if i == len(edges)-2:
mask = (conf >= lo) & (conf <= hi)
else:
mask = (conf >= lo) & (conf < hi)
if not np.any(mask):
bins_summary.append({'count':0,'mean_conf':None,'acc':None,'weight':0.0})
continue
mean_conf = conf[mask].mean()
acc = (pred[mask] == labels[mask]).mean()
weight = mask.sum() / N
ece += weight * abs(mean_conf - acc)
bins_summary.append({'count':int(mask.sum()), 'mean_conf':float(mean_conf), 'acc':float(acc), 'weight':float(weight)})
class_ece = None
if per_class:
class_ece = {}
C = probs.shape[1]
for c in range(C):
# treat class c as positive: confidence = prob[:,c], label_bin = (labels==c)
conf_c = probs[:, c]
label_bin = (labels == c).astype(int)
# reuse equal-mass edges computed on conf_c if desired; here use equal-mass on conf_c
edges_c = np.unique(np.quantile(conf_c, np.linspace(0,1,n_bins+1)))
if len(edges_c)-1 < n_bins:
edges_c = np.linspace(0.0,1.0,n_bins+1)
ece_c = 0.0
for i in range(len(edges_c)-1):
lo, hi = edges_c[i], edges_c[i+1]
if i == len(edges_c)-2:
mask = (conf_c >= lo) & (conf_c <= hi)
else:
mask = (conf_c >= lo) & (conf_c < hi)
if not np.any(mask): continue
mean_conf = conf_c[mask].mean()
acc = label_bin[mask].mean()
ece_c += (mask.sum()/N) * abs(mean_conf - acc)
class_ece[c] = float(ece_c)
# optionally compute macro / weighted aggregate
class_counts = np.bincount(labels, minlength=C)
weighted = sum(class_ece[c]*class_counts[c]/N for c in range(C))
class_ece['macro'] = float(np.mean([class_ece[c] for c in range(C)]))
class_ece['weighted'] = float(weighted)
return float(ece), bins_summary, class_eceSample Answer
Unlock Full Question Bank
Get access to hundreds of Deep Learning Model Evaluation interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.