KatInterview

Build and Serve a Domain-Adapted LLM Without Hallucinating

Machine LearningModel answer
HardModel answerMachine Learningtransformersllmfine-tuning

Last updated

Design, fine-tune, and operate a Transformer-based LLM on a specialized corpus while preserving general capabilities and controlling hallucinations in production.

Scenario

Your team is deploying a large language model to answer natural-language queries over a proprietary document corpus — think legal contracts, clinical notes, or financial filings. The system will serve real users, where a confidently wrong answer is worse than no answer at all.

You have access to a pretrained open-weight decoder-only LLM (7B–70B parameters) and roughly 5 billion tokens of domain text plus a few thousand curated question-answer pairs.

What you are expected to cover

Part 1 — Architecture. Walk through how a modern decoder-only Transformer is structured. What are its core components, and how do the design choices (normalization placement, positional encoding, attention variant, MLP activation) affect capability and efficiency?

Part 2 — Long-range dependencies. Explain mechanically how self-attention lets a model relate tokens that are thousands of positions apart. Compare this to recurrent models and be honest about the costs and failure modes.

Part 3 — Domain adaptation without catastrophic forgetting. Describe the full pipeline from raw domain data to a production-ready checkpoint. What techniques prevent the model from losing its general capabilities during fine-tuning? What should you gate on before shipping?

Part 4 — Hallucination: evaluation, monitoring, and mitigation. Define the types of hallucination relevant to a grounded QA system. Sketch the serving architecture. Explain how you measure faithfulness before launch, how you track it on live traffic, and what operational levers reduce hallucination rate over time.

What a strong answer looks like

  • States concrete assumptions (parameter count, QPS, latency budget, risk tolerance) before diving in.
  • Gives specific numbers: memory costs, learning rates, sample sizes, metric thresholds.
  • Names trade-offs explicitly rather than listing techniques as universally good.
  • Identifies what can go wrong at each stage and how you would catch it.

Hints

Hint 1

Start by fixing your assumptions out loud: model size, serving load, and what 'wrong answer' costs in your domain. These choices cascade into every subsequent decision.

Hint 2

For the attention section, think about what property makes O(1) path length between tokens meaningful — and then name at least one reason the model might still fail on long documents in practice.

Hint 3

Catastrophic forgetting has more than one cause. Separate the 'weights drift' problem from the 'training distribution shift' problem — they call for different fixes.