ailearnist Loading…
Interview Prep

LLM Interview Questions

How large language models work — tokens, context windows, sampling and why they hallucinate.

14
Beginner

What is a token and why does it matter?

A token is a chunk of text (often part of a word) the model reads and writes. Pricing, context limits and latency are all measured in tokens.

Key Points:

  • Roughly 4 characters or ¾ of a word per token in English.
  • Non-English text often uses more tokens.
15
Beginner

What does temperature control?

Temperature scales how random sampling is. Low values give predictable output (good for extraction, JSON); higher values give more varied output (good for brainstorming).

Key Points:

  • Temperature 0 is near-deterministic, not guaranteed identical.
16
Intermediate

Why do LLMs hallucinate?

LLMs predict likely next tokens, not verified facts. Without grounding they can produce fluent but false answers. Retrieval, citations, constrained output and evals reduce it.

Key Points:

  • Ask for sources and allow "I don't know".
17
Intermediate

What is the transformer architecture?

The transformer is the neural network design behind modern LLMs. It processes all tokens in a sequence in parallel and uses self-attention to let each token weigh how relevant every other token is. Stacks of attention and feed-forward layers build up rich representations of the text.

Key Points:

  • Introduced in the 2017 paper 'Attention Is All You Need'.
  • Parallel processing made training on huge datasets practical, unlike older RNNs.
  • Most LLMs use a decoder-only transformer that predicts the next token.
18
Expert

How does self-attention work?

Each token is projected into a query, a key and a value vector. A token's query is compared with every token's key to produce attention scores, which are normalised with softmax and used to take a weighted sum of the values. The result is a new representation of the token informed by the context it cares about.

Key Points:

  • Multi-head attention runs several attention patterns in parallel to capture different relationships.
  • Causal masking stops a token attending to future tokens in decoder models.
  • Attention cost grows quadratically with sequence length — a key reason context windows are expensive.
19
Beginner

What is a context window?

The context window is the maximum number of tokens a model can consider at once — the prompt, any documents or history you include, and the response it generates. Anything outside the window is invisible to the model.

Key Points:

  • Long conversations must be trimmed or summarised to fit.
  • Bigger windows cost more and models can still miss details buried in the middle of very long inputs.
20
Intermediate

What is the difference between pre-training, fine-tuning and RLHF?

Pre-training teaches a model general language by predicting the next token over massive text. Fine-tuning continues training on a smaller curated dataset to teach a task or format, such as following instructions. RLHF (reinforcement learning from human feedback) then optimises the model toward responses humans prefer.

Key Points:

  • Pre-training is by far the most expensive stage.
  • Alternatives to RLHF include DPO, which learns directly from preference pairs.
  • These stages turn a raw text predictor into a helpful assistant.
21
Intermediate

What is top-p (nucleus) sampling?

Top-p sampling picks the next token only from the smallest set of tokens whose combined probability reaches p (for example 0.9), then samples within that set. It cuts off the long tail of unlikely tokens while still allowing variety.

Key Points:

  • Top-k instead keeps a fixed number of candidate tokens.
  • Usually tune either temperature or top-p, not both aggressively at once.
22
Intermediate

What is the difference between a base model and an instruction-tuned model?

A base model has only been pre-trained, so it continues text rather than following requests. An instruction-tuned (chat) model has been further trained to follow instructions, hold conversations and refuse harmful requests.

Key Points:

  • Base models are useful as a starting point for your own fine-tuning.
  • Use instruction-tuned models for almost all application work.
23
Beginner

What is the difference between open-weight and closed models?

Open-weight models publish their trained weights so you can download, run and fine-tune them yourself. Closed models are accessed only through the provider's API or app. The choice trades control and data residency against convenience and, often, top-end capability.

Key Points:

  • Open-weight suits on-premise, strict privacy or heavy customisation needs.
  • Closed APIs remove infrastructure work and usually get updates first.
  • Open weights is not the same as open source — training data and code may stay private.
24
Expert

What is LoRA?

LoRA (Low-Rank Adaptation) is a parameter-efficient fine-tuning method. It freezes the original model weights and trains small low-rank matrices added to certain layers, so only a tiny fraction of parameters change.

Key Points:

  • Far less GPU memory and storage than full fine-tuning.
  • Adapters can be swapped per task on top of one base model.
  • QLoRA combines LoRA with a quantised base model to fine-tune on a single GPU.
25
Expert

What is quantization and why does it matter?

Quantization stores model weights (and sometimes activations) at lower numeric precision, such as 8-bit or 4-bit integers instead of 16-bit floats. This shrinks memory use and speeds up inference, at the cost of a small, usually acceptable, drop in quality.

Key Points:

  • Makes it possible to run larger models on smaller GPUs or laptops.
  • Always re-check quality on your own tasks after quantizing.
26
Expert

How do you reduce LLM latency and cost?

Use the smallest model that meets the quality bar, keep prompts short, cap output length, cache repeated prompt prefixes and responses, stream tokens to the user, and batch offline work. Route easy requests to cheaper models and reserve large models for hard ones.

Key Points:

  • Output tokens are usually slower and pricier than input tokens.
  • Prompt caching and the model's KV cache avoid recomputing shared context.
  • Measure cost and latency per feature, not just overall.