KatInterview

Designing a Repeat-and-Aggregate Pipeline for Noisy LLM Scores

Machine LearningModel answer
MediumModel answerMachine Learningllm-inferenceconfidence-intervalssample-size

Last updated

Design a latency-bounded pipeline that averages repeated LLM sentiment scores, measures run-to-run stability, and computes how many samples a 95% error target needs.

Context

Your team serves an LLM that reads unstructured financial text and returns a numeric sentiment score (for example in [-1, 1]). The model is sampled stochastically, so calling it several times on the same text gives different numbers. A downstream consumer needs a steady, trustworthy value for each input.

Questions

  1. Architecture. Propose a way to make the served score stable. How would you choose the number of repeated calls, n, so that variance falls without breaking the latency limit?
  2. Measuring stability. You have 100 past inferences collected over a set of inputs. Which statistical measures would you compute to quantify how stable the outputs are?
  3. Sample size. A stakeholder wants the averaged score to land within a margin e of the true mean with 95% confidence. For a brand-new input, how do you derive the n required?

Requirements

  • Give pseudo-code or workflow logic for orchestrating the repeated calls.
  • Discuss the trade-off between sampling temperature and the number of repeats.
  • Explain how you would check, using a correlation measure such as Pearson against a benchmark or expert labels, that the stabilization step has not introduced bias.
  • Numbers to work with: each model call takes about 200 ms, and the whole inference process must finish within 1 second.

Hints

Hint 1

Treat each model call as a draw from a distribution. The spread of the mean shrinks like sigma divided by the square root of n, so the sample size follows from the margin you need.

Hint 2

Sequential calls only fit about four in a second. Think about firing calls concurrently in a small first wave, estimating the spread from it, and then deciding whether a second wave is affordable.

Hint 3

A stable answer is not necessarily a correct one. Plan a separate comparison against expert labels, and consider lowering temperature or reading token probabilities to cut variance per call.