Generative AI and Large Language Models Questions
The capabilities and behavior of modern generative and large language models. Covers how LLMs are pretrained, in-context learning and few-shot prompting, generative model families (autoregressive, diffusion), context windows, and tokenization and sampling. Emphasizes understanding what generative models can and cannot do and how they differ from discriminative ML.
Explain scaling laws for language models: how do model size, dataset size, and compute budget influence loss and generalization? What are the practical consequences for dataset preparation, model selection, and cost estimates when planning to train an LLM?
Sample Answer
Direct answer
Scaling laws describe how a language model's loss decreases predictably as you increase model size, dataset size, or training compute, following an approximately power-law relationship; the practical consequence is that, for a fixed compute budget, there is a compute-optimal balance between model size and dataset size, and simply making the model as large as possible while using whatever data happens to be available is generally NOT compute-optimal.
Structured elaboration
The basic relationship. Loss L decreases roughly as a power law in each of model parameters N, dataset size D, and compute C, when the other two are not the bottleneck: L(N)∝N−α, and similarly for D and C, with empirically fitted exponents. The key practical insight (established by later scaling-law work, notably Chinchilla) is that model size and dataset size should be scaled together, not independently; a model that is very large but trained on comparatively little data is typically "undertrained" relative to what its parameter count could support, and would have achieved lower loss for the same compute budget with a smaller model trained on proportionally more data.
Compute-optimal training. For a fixed compute budget C≈6ND (a standard approximation for training FLOPs as roughly six times parameters times tokens), there is a specific (N,D) pair that minimizes loss for that budget; empirically, compute-optimal scaling calls for roughly comparable growth in both parameters and training tokens as compute increases (both should grow, not just one), rather than the earlier practice of scaling parameters aggressively while holding dataset size comparatively fixed.
Worked example
Given a fixed compute budget of 6×1023 FLOPs, and using the approximation C≈6ND, a team deciding purely by "make it bigger" might train a 50B-parameter model on 400B tokens: 6×5×1010×4×1011=1.2×1023 FLOPs, well under budget, so they'd push the model size up further, say to 100B parameters on the same 400B tokens: 6×1011×4×1011=2.4×1023 FLOPs, still under the 6×1023 budget, and might keep growing the model to "use up" the compute. A compute-optimal allocation instead grows BOTH: for example, roughly a 25B-parameter model on 4 trillion tokens hits close to the same 6×1023 budget (6×2.5×1010×4×1012=6×1023), and empirical scaling-law findings show configurations closer to this balanced allocation achieve LOWER loss for the identical compute spend than the parameter-heavy, data-light allocation, because the very large, undertrained model in the first scenario was leaving loss improvement on the table that more data would have captured more cheaply than more parameters would.
Trade-offs & pitfalls
Scaling laws give you the compute-optimal TRAINING allocation, but training compute isn't the only cost that matters in production: a smaller model trained compute-optimally on more data is also cheaper to SERVE (lower inference latency and cost per query, which recurs on every single request, unlike training cost which is paid once). This means the genuinely optimal choice for a product often deliberately trains a smaller-than-compute-optimal model on even more data than the pure training-compute-optimal point would suggest, intentionally "overtraining" relative to the scaling-law optimum, because the resulting inference savings over the product's lifetime outweigh the extra training cost. A common mistake is treating the compute-optimal training point as the final answer without separately accounting for this inference-cost dimension, which the classic scaling-law framing (focused purely on training-loss-per-training-FLOP) doesn't include.
At a high level, describe diffusion generative models: what are the forward (noising) and reverse (denoising) processes, how is the model trained, and how does sampling work at generation time? Give an example use case where diffusion is preferred over GANs.
Sample Answer
Direct answer
Diffusion models generate data by learning to reverse a gradual noising process: a fixed forward process progressively adds Gaussian noise to real data over many steps until it becomes indistinguishable from pure noise, and the model learns the reverse process, predicting the noise (or an equivalent quantity) at each step so that starting from pure noise and iteratively denoising produces a realistic sample.
Structured elaboration
Forward (noising) process. Starting from a real data point x0, Gaussian noise is added in small increments over T steps according to a fixed noise schedule βt, producing progressively noisier versions x1,x2,…,xT, until xT is essentially pure noise with no remaining signal from x0. This process has no learned parameters; it's a fixed, known mathematical procedure.
Reverse (denoising) process. The model learns to approximate the reverse: given a noisy xt, predict either the noise that was added to produce it, or directly the mean of the slightly-less-noisy xt−1. At generation time, you start from pure noise xT and repeatedly apply the learned reverse step, T times, gradually removing noise until you arrive at a sample x0 that looks like it came from the real data distribution.
Training objective. The most common formulation trains the model to predict the noise ϵ that was added at a randomly sampled step t, using a simple mean-squared-error loss between the predicted and true noise. This is mathematically equivalent (up to a reweighting) to optimizing a variational lower bound on the data likelihood, but the simplified noise-prediction MSE objective is what's used in practice because it trains more stably and produces better samples than directly optimizing the full likelihood bound.
Why Gaussian noise and reweighted objectives. Gaussian noise is used because it has convenient closed-form properties (you can jump directly from x0 to any noisy xt in one step during training, without simulating all the intermediate steps, since the sum of the individually-added Gaussian noise steps is itself Gaussian). The training objective is typically reweighted across timesteps (rather than using the literal variational-bound weighting) because empirically it puts more training emphasis on the timesteps that matter most for final sample quality, which the raw likelihood bound underweights.
Diffusion versus GANs, an example use case. Diffusion is generally preferred over GANs when sample quality and diversity matter more than generation speed, and when training stability is a priority, e.g., a text-to-image product where users are willing to wait a few seconds for a high-quality, varied image, versus a real-time application (live video style transfer) where a GAN's single-forward-pass speed is the deciding factor even at some cost to quality or diversity.
Trade-offs & pitfalls
The biggest practical cost of the diffusion formulation is sampling speed: generating one sample requires running the learned reverse step many times (historically hundreds to a thousand steps, though modern fast samplers have brought this down substantially), which is fundamentally more expensive at inference time than a GAN's single forward pass. A common misunderstanding is treating the number of diffusion steps as purely a quality knob you can freely increase; beyond a point, more steps mostly add latency without meaningfully improving sample quality, and the practical tuning is finding the fewest steps that preserve acceptable quality for the specific application.
You must choose an approach for a production chatbot: (A) a supervised model fine-tuned on conversation logs, (B) retrieval plus a reranker, or (C) RL fine-tuning with human feedback (RLHF). Compare these on safety, response quality, data requirements, compute cost, and monitoring needs. Which would you choose for a first production release, and why?
Sample Answer
Direct answer
For a first production release of a chatbot, retrieval plus a reranker is generally the strongest starting choice among supervised fine-tuning, retrieval+reranking, and RLHF, because it gets you grounded, auditable answers with the least amount of training risk and the fastest iteration loop, while the other two approaches each carry a cost or risk profile that's harder to justify before you have real production signal.
Structured elaboration
Option A: supervised fine-tuning on conversation logs. Requires a substantial labeled dataset of good conversations, has real training cost and time, and the resulting model's answers come entirely from what it "absorbed" during fine-tuning, with no built-in mechanism to ground responses in a verifiable source, so factual errors are harder to trace and fix (you'd need to retrain rather than update a document). Response quality can be very good if the training data is high quality, but data quality and coverage become the single point of failure.
Option B: retrieval plus a reranker. A frozen (or lightly prompted) base LLM is given retrieved passages relevant to the query and generates its answer grounded in them. This needs no model training at all, just a good retrieval index, so it's fast to build and iterate on, its answers are traceable back to a specific document (which matters for both quality debugging and end-user trust), and updating the knowledge base is as simple as updating the index, no retraining required. The main risk shifts entirely to retrieval quality: if the retriever misses the right passage, the answer will be wrong or unsupported no matter how good the generator is.
Option C: RL fine-tuning with human feedback (RLHF). Requires collecting preference data, training a reward model, and running a genuinely nontrivial RL training pipeline (with real risk of reward hacking or instability). It's the most expensive and highest-risk of the three to build correctly, and mainly earns its cost when you need to shape subtle behavioral qualities (tone, helpfulness, refusal behavior) that are hard to specify any other way, not for injecting or updating factual knowledge, which RLHF is not well suited for at all.
Why B for a first release. Compute and data cost are lowest (no training run needed beyond building a retrieval index), monitoring is more interpretable (you can inspect exactly which passages fed which answer), and safety is easier to reason about because ungrounded claims are visibly rarer when the model is prompted to answer from retrieved evidence, though not eliminated; the model can still ignore or misread retrieved passages.
Worked example
Consider a customer-support chatbot for a software product with a large, frequently-updated help-center. Fine-tuning (Option A) would require re-training every time the help docs change, a maintenance burden that scales badly. RLHF (Option C) doesn't even address the core need, correctly answering factual product questions, since it shapes tone and behavior rather than knowledge. Retrieval plus reranking (Option B) lets the team ship an assistant that answers directly from the current help docs, update the index the moment docs change with zero retraining, and trace every wrong answer back to either a retrieval miss (fix the index or the query) or a generation error (fix the prompt), which is a dramatically faster iteration loop for a first release than either training-based alternative.
Trade-offs & pitfalls
This doesn't mean fine-tuning and RLHF are wrong forever, only that they're premature for a FIRST release. Once the retrieval-based system is live and you've accumulated real usage data (what users actually ask, where the base model's tone or behavior falls short even with good retrieved evidence, where retrieval quality is a bottleneck), a natural evolution is to add lightweight fine-tuning for domain-specific behavior, then RLHF-style preference optimization for tone and helpfulness, on top of the retrieval foundation rather than instead of it. The common mistake is reaching for the most sophisticated technique (RLHF) first, out of a sense that it's the "state of the art" approach, when the actual bottleneck for a first release is almost always factual grounding and iteration speed, which retrieval addresses far more directly.
What is the difference between prompting an LLM and fine-tuning it to change its behavior? In what scenarios is prompting a sufficient first approach, and when does it become insufficient, requiring fine-tuning instead?
Sample Answer
Direct answer
Prompting an LLM means steering its behavior at inference time through instructions and examples in the input, with no change to the model's weights; fine-tuning changes the weights themselves through additional training. Prompting is the right first approach whenever the base model's existing knowledge and capabilities are already sufficient and you just need to steer HOW it uses them; fine-tuning becomes necessary when the required behavior can't reliably be specified through instructions alone, either because it needs knowledge the model doesn't have, or because it needs a level of consistency prompting can't guarantee.
Structured elaboration
What prompting can and can't do. A prompt can specify style, format, persona, and task framing, and can supply new information directly in context (few-shot examples, retrieved documents). What it cannot do is permanently change what the model "knows" or reliably guarantee a specific behavior across every possible input, since prompt-following is itself a learned, imperfect capability; a sufficiently unusual or adversarial input can still cause the model to ignore or misapply prompt instructions.
When prompting suffices. Style and format control ("respond in JSON," "use a formal tone"), task framing for capabilities the base model already broadly has (summarization, translation, general Q&A), and situations where you can supply the needed facts directly in the prompt (via retrieval) rather than needing them baked into the weights.
When it becomes insufficient. Three concrete triggers: (1) the task requires domain knowledge that's absent or too sparse in the model's pre-training data and too voluminous to supply per-request via retrieval or examples; (2) the required consistency is higher than prompting reliably delivers, e.g., a classification task that must NEVER misfire on adversarial inputs; (3) the per-request cost of achieving the behavior via prompting (long instructions, many few-shot examples) becomes larger than the one-time cost of fine-tuning would be, once volume is high enough.
Trade-offs & pitfalls
The common mistake is reaching for fine-tuning as a default "make the model better at X" move before actually testing whether a well-designed prompt (possibly with retrieval or few-shot examples) already solves the problem; fine-tuning has real fixed costs (data collection, training compute, evaluation, and a slower iteration loop since every behavior change requires retraining) that prompting doesn't. The inverse mistake also happens: sticking with an increasingly baroque, ever-longer prompt to force consistent behavior on a task that has clearly outgrown what prompting can reliably deliver, when a modest fine-tuning investment would produce a shorter, cheaper, more reliable system. The practical discipline is to start with prompting, measure where and how often it fails, and let that concrete failure pattern justify the fine-tuning investment rather than assuming it up front.
Compare transformer encoder-only models (e.g., BERT) with decoder-only models (e.g., GPT) at an applied level: how do the pre-training objectives and input handling differ, and which task types fit which architecture? At a high level, why did the transformer architecture displace RNNs and LSTMs for most language tasks?
Sample Answer
Direct answer
Encoder-only transformers (BERT-style) build a bidirectional representation of a fixed input and are trained to predict masked tokens, which makes them strong at understanding tasks like classification and extraction. Decoder-only transformers (GPT-style) are trained causally, left to right, to predict the next token, which makes them naturally suited to open-ended generation. Both architectures displaced RNNs for language because self-attention lets every position attend to every other position in a single parallelizable step, rather than propagating information sequentially through a recurrent state.
Structured elaboration
Architecture differences. An encoder stack has no causal mask, so every token can attend to every other token, including ones that come after it. A decoder stack applies a causal (triangular) mask so a token can only attend to itself and earlier tokens, which is what makes autoregressive generation well-defined: at generation time you only ever have the tokens produced so far.
Pre-training objective follows from the architecture. Encoders are trained with masked language modeling: some tokens are hidden, and the model must reconstruct them using context from both directions. Decoders are trained with causal language modeling (next-token prediction), which matches how they will actually be used at inference: generate one token, feed it back in, generate the next.
Why transformers replaced RNNs/LSTMs. An RNN processes a sequence one token at a time, so training cannot be parallelized across the sequence dimension, and information from early tokens has to survive many sequential updates to influence late tokens (the long-range-dependency problem, and the reason LSTMs added gating in the first place). Self-attention computes a weighted combination over the WHOLE sequence in one step, so training parallelizes across positions on a GPU, and any two tokens are one attention hop apart regardless of distance, which is a much easier path for gradients and for capturing long-range dependencies.
Task fit. Encoder-only models fit classification, extraction, and retrieval-style tasks where you have the whole input up front and just need to understand it. Decoder-only models fit open-ended generation, chat, and completion, where output has to be produced incrementally without seeing the future.
Worked example
Consider fine-tuning for sentiment classification versus building a chat assistant. For sentiment classification you have the entire review text available at once; an encoder-only model can attend bidirectionally over the whole review and produce one classification from a pooled representation, no generation step needed. For a chat assistant, the model has to produce its reply one token at a time without knowing what it will say next, which is exactly the setting causal masking and next-token training were designed for; using an encoder here would require bolting on a separate generation mechanism, which is why decoder-only (or encoder-decoder) architectures dominate generation products.
Trade-offs & pitfalls
Encoder-only models are typically cheaper to run for classification because they need only one forward pass over the whole input, versus a decoder's one forward pass per generated token. Decoder-only models generalize surprisingly well across many tasks (including classification, via prompting) once scaled up, which is a big part of why decoder-only became the dominant architecture for general-purpose LLMs, even though encoder-only models can still win on pure understanding benchmarks per parameter. A common mistake is assuming architecture choice is purely about model quality; it is really about matching the causal structure of training to the causal structure of how the model will be used at inference.
Unlock Full Question Bank
Get access to all 21 Generative AI and Large Language Models interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.