MLCrack

    EXPERIMENTATION & A/B TESTING · INTERVIEW QUESTION

    Explain A/B testing and multi-armed bandit approaches for comparing LLM versions or prompts.

    🟡 intermediate · A/B Testing Fundamentals

    Hint: A/B: fixed split. Bandit: adaptive allocation toward better variant.

    Answer

    • Fixed split (e.g., 50/50)
    • Measure metrics: user satisfaction, task completion, error rates
    • Need enough data for statistical significance

    Interview reasoning

    A/B Testing

    Randomize users into groups, each gets a different model/prompt variant:

    Sample size≈2(z1−α/2+z1−β)2σ2δ2\text{Sample size} \approx \frac{2(z_{1-\alpha/2} + z_{1-\beta})^2 \sigma^2}{\delta^2}

    The normal-approximation sample size above is per arm for equal allocation and common variance; z denotes a standard-normal quantile.

    Multi-Armed Bandit

    Adaptive allocation can shift traffic toward better variants while exploring. The following softmax allocation is one possible policy, not the general bandit rule:

    P(armi)=eμ^i/τ∑jeμ^j/τP(\text{arm}_i) = \frac{e^{\hat{\mu}_i / \tau}}{\sum_j e^{\hat{\mu}_j / \tau}}

    A/B TestingBandit
    AllocationFixedAdaptive
    Reward regretDoes not adapt to observed rewardsCan reduce regret with suitable exploration
    InferenceStandard designs with valid monitoringRequires inference valid for adaptive allocation
    Time to decisionDepends on effect and designDepends on objective, exploration and reward delays
    Best forFinal decisionsOngoing optimization
    python
    # Simple epsilon-greedy bandit import numpy as np def select_variant(rewards, epsilon=0.1): if np.random.random() < epsilon: return np.random.choice(len(rewards)) # explore return np.argmax([np.mean(r) for r in rewards]) # exploit

    For LLMs: A/B test prompt styles, model versions, or system prompts; consider bandits for ongoing reward optimization. Low regret does not guarantee fastest confident best-arm identification. Adaptive experiments can support rigorous inference with suitable estimators and stopping rules. Initialize each arm with observations before using the illustrative epsilon-greedy function.

    Bandits adapt traffic to improve cumulative reward and learn action values, whereas a fixed experiment emphasizes a clean policy comparison. Contextual bandits condition choices on user/context features and need correct logged assignment probabilities. Delayed rewards, safety and nonstationarity affect both learning and later off-policy inference.

    Worked example. A prompt bandit can favor better replies while retaining enough safe exploration to learn alternatives. Compare this with a stable user-randomized prompt test whose goal is an unbiased version comparison, particularly when CSAT arrives late.

    This is the opening of a longer walkthrough. Read the full answer in the topic explorer, free.