Intermediate Artificial Intelligence interview questions
150 questions with answers (AIE-151 to AIE-300). Try each one aloud before reading the answer.
Math & Statistics for ML
AIE-151 · Why does gradient descent move in the direction of the negative gradient?
The gradient points in the direction of steepest increase of the loss, so stepping opposite to it decreases the loss fastest locally. The update is θ ← θ − η∇L(θ), with η the learning rate.
AIE-152 · How does maximum likelihood estimation relate to common loss functions?
Minimising MSE equals maximum likelihood under Gaussian noise, and minimising cross-entropy equals maximum likelihood for categorical (or Bernoulli) outputs. Losses are negative log-likelihoods of an assumed noise model.
AIE-153 · What is the bias-variance trade-off?
Expected error = bias² + variance + irreducible noise. Simple models have high bias (underfit); complex models have high variance (overfit). Regularisation, more data and model selection balance the two.
AIE-154 · How does L2 regularisation work, and how is it related to a Gaussian prior?
L2 adds λ‖w‖² to the loss, shrinking weights toward zero and reducing variance. It is equivalent to MAP estimation with a zero-mean Gaussian prior on the weights.
AIE-155 · Why does L1 regularisation produce sparse models?
The L1 penalty λ‖w‖₁ has corners at zero, so optimal solutions often set some weights exactly to zero, performing feature selection. It corresponds to a Laplace prior.
AIE-156 · How is PCA computed?
Centre the data, compute the covariance matrix (or SVD of the data matrix), and take eigenvectors with the largest eigenvalues as principal components. Projecting onto the top k components keeps the most variance.
AIE-157 · What does the singular value decomposition (SVD) tell you about a matrix?
A = UΣVᵀ splits a matrix into orthogonal directions scaled by singular values. It gives rank, low-rank approximations (truncated SVD), PCA and pseudo-inverses.
AIE-158 · How do you interpret a 95% confidence interval for a model's accuracy?
If the evaluation were repeated many times, about 95% of such intervals would contain the true accuracy. With n test samples and accuracy p, an approximate interval is p ± 1.96√(p(1−p)/n).
AIE-159 · What is KL divergence and where is it used?
KL(P‖Q) = Σ P log(P/Q) measures how one distribution differs from another; it is asymmetric and non-negative. It appears in VAEs, knowledge distillation, policy optimisation and cross-entropy loss.
AIE-160 · What is the difference between the frequentist and Bayesian approaches?
Frequentists treat parameters as fixed and probability as long-run frequency; Bayesians treat parameters as random with priors updated by data to posteriors. Bayesian methods give uncertainty estimates but need priors and more computation.
AIE-161 · Why are second-order optimisation methods rarely used for deep networks?
Methods like Newton's need the Hessian, which is huge (n² entries for n parameters) and expensive to invert. Deep learning uses first-order methods with momentum and adaptive learning rates instead.
AIE-162 · How does the central limit theorem justify many statistical tests?
Sums or means of many independent samples tend toward a normal distribution regardless of the original distribution, so tests and confidence intervals based on normality work for averages with enough samples.
AIE-163 · Why does mini-batch SGD work better than full-batch gradient descent for large datasets?
Mini-batches give cheap, noisy gradient estimates allowing many more updates per epoch, use GPU parallelism efficiently, and the noise can help escape sharp minima and improve generalisation.
Classical Machine Learning
AIE-164 · How does a decision tree choose where to split?
It evaluates candidate features and thresholds and chooses the one that maximises impurity reduction, measured by Gini impurity or entropy (information gain) for classification, or variance reduction for regression.
AIE-165 · Why does a random forest reduce overfitting compared with a single tree?
Each tree is trained on a bootstrap sample with random feature subsets at splits, so trees are decorrelated; averaging their predictions reduces variance while keeping bias low.
AIE-166 · How does gradient boosting build a model?
It adds shallow trees one at a time, each fitted to the negative gradient of the loss (the residual errors for squared loss) of the current ensemble, scaled by a learning rate. Libraries like XGBoost, LightGBM and CatBoost add regularisation and efficient split finding.
AIE-167 · How does the kernel trick let an SVM learn non-linear boundaries?
A kernel computes inner products in a high-dimensional feature space without mapping data explicitly, so a linear separator there becomes non-linear in the original space. RBF and polynomial kernels are common.
AIE-168 · What does the C parameter control in an SVM?
C trades off margin width against training errors. A large C penalises misclassification heavily (narrow margin, risk of overfitting); a small C allows more violations for a wider, more general margin.
AIE-169 · How do you choose k in k-means?
Use the elbow method on within-cluster sum of squares, silhouette scores, gap statistics or domain knowledge. Run several initialisations (k-means++) because results depend on starting centroids.
AIE-170 · Why is feature scaling important for k-NN and k-means?
Both rely on distances, so features with larger numeric ranges dominate the distance. Standardising or normalising gives each feature comparable influence.
AIE-171 · How does logistic regression output probabilities?
It computes a linear score z = w·x + b and passes it through the sigmoid σ(z) = 1/(1 + e⁻ᶻ), giving a value between 0 and 1. It is trained by minimising log loss.
AIE-172 · Why is Naive Bayes "naive", and why does it still work?
It assumes features are conditionally independent given the class, which is rarely true. It still classifies well because accurate ranking of class probabilities matters more than exact probabilities, and it is fast with little data.
AIE-173 · What is the difference between hard and soft voting in ensembles?
Hard voting picks the majority predicted class; soft voting averages predicted probabilities and picks the highest, usually performing better when models are well calibrated.
AIE-174 · How does DBSCAN cluster data differently from k-means?
DBSCAN groups points in dense regions defined by eps and min_samples, finds arbitrary-shaped clusters, doesn't need k, and labels sparse points as noise. k-means assumes roughly spherical clusters of similar size.
AIE-175 · What is stacking?
An ensemble where several base models' predictions become inputs to a meta-model that learns how to combine them. Out-of-fold predictions are used to avoid leakage.
AIE-176 · How does ridge regression handle multicollinearity?
Correlated features make ordinary least squares coefficients unstable with high variance. Ridge's L2 penalty shrinks coefficients and stabilises estimates, trading a little bias for much lower variance.
Model Evaluation & Validation
AIE-177 · How do precision and recall trade off, and how do you choose a threshold?
Raising the decision threshold usually increases precision and lowers recall. Choose the threshold based on the cost of false positives versus false negatives, using precision-recall curves or a business cost function.
AIE-178 · What is the F1 score and when is it preferred over accuracy?
F1 = 2·precision·recall/(precision + recall), the harmonic mean. It is preferred for imbalanced classes, where accuracy can be high by always predicting the majority class.
AIE-179 · How does k-fold cross-validation work?
Split data into k folds; train on k − 1 folds and validate on the remaining one, rotating so each fold is used for validation once, then average the scores. It gives a more reliable estimate than a single split.
AIE-180 · Why use stratified k-fold cross-validation?
It keeps the class proportions the same in each fold, which gives stable estimates for imbalanced classification problems.
AIE-181 · What does the area under the ROC curve (AUC) mean?
AUC is the probability that the model ranks a random positive example above a random negative one. 0.5 is random guessing and 1.0 is perfect ranking; it is independent of the decision threshold.
AIE-182 · When is a precision-recall curve more informative than ROC?
With heavy class imbalance, ROC can look good because true negatives dominate the false positive rate. The PR curve focuses on the positive class and shows how precision drops as recall rises.
AIE-183 · How do you validate a model on time-series data?
Use time-based splits (train on the past, test on the future) or rolling/expanding window validation; random shuffling leaks future information into training and overstates performance.
AIE-184 · What is nested cross-validation and why use it?
An inner loop tunes hyperparameters while an outer loop estimates generalisation on data never used for tuning. It avoids the optimistic bias of reporting the score of the same CV used to choose hyperparameters.
AIE-185 · A classifier has TP = 80, FP = 20 and FN = 40. What are its precision, recall and F1?
Precision = 80/(80 + 20) = 0.80; recall = 80/(80 + 40) ≈ 0.67; F1 = 2 × 0.80 × 0.67/(0.80 + 0.67) ≈ 0.73. The model is fairly precise but misses a third of real positives, so if missed positives are costly, lower the threshold to raise recall.
AIE-186 · What is model calibration and how is it measured?
A calibrated model's predicted probabilities match observed frequencies (e.g. 70% predictions are right 70% of the time). It is measured with reliability diagrams and expected calibration error, and fixed with Platt scaling or isotonic regression.
AIE-187 · How do you compare two models fairly?
Use the same data splits and metrics, evaluate on a held-out test set, report confidence intervals or run statistical tests (paired bootstrap, McNemar), and consider cost, latency and robustness, not just a single score.
AIE-188 · What is the difference between macro and micro averaging in multi-class metrics?
Macro averaging computes the metric per class and averages them equally (treating rare classes as important); micro averaging pools all predictions, so it is dominated by frequent classes.
AIE-189 · Why can a model have high accuracy but be useless?
In imbalanced data, predicting the majority class gives high accuracy while missing all minority cases (e.g. 99% accuracy with 1% fraud by predicting "no fraud" always). Use recall, precision, AUC or cost-based metrics.
Feature Engineering & Data Preparation
AIE-190 · How do you encode high-cardinality categorical features?
Use target (mean) encoding with cross-validation or smoothing to avoid leakage, frequency encoding, hashing, or learned embeddings in neural networks. One-hot encoding creates too many sparse columns.
AIE-191 · How should you handle missing values without leaking information?
Fit imputation statistics (mean, median, model-based imputation) on the training data only, then apply them to validation and test data, and consider adding a missing-indicator feature.
AIE-192 · How do you handle class imbalance during training?
Use class weights in the loss, resampling (oversampling such as SMOTE or undersampling) on training data only, threshold tuning, and appropriate metrics. Don't resample the test set.
AIE-193 · Why build preprocessing inside a pipeline?
Pipelines fit transformations only on training folds during cross-validation, preventing leakage, and ensure the same steps are applied identically at inference time.
AIE-194 · How do you create useful features from timestamps?
Extract hour, day of week, month, holidays and elapsed time since events, use cyclical encoding (sine and cosine) for periodic features, and build lag and rolling-window statistics for time series.
AIE-195 · How do you detect and handle multicollinearity?
Compute correlation matrices and variance inflation factors (VIF); drop or combine correlated features, use PCA, or use regularised models that handle correlated inputs.
AIE-196 · How do you choose between normalisation and standardisation for a model?
Standardisation (zero mean, unit variance) suits most linear models, SVMs and neural networks and handles outliers better than min-max scaling. Min-max normalisation to [0, 1] suits bounded inputs like pixel values. Tree models generally don't need scaling.
AIE-197 · How do you perform feature selection with a model-based method?
Use L1-regularised models that zero out weak features, tree-based importance or permutation importance, or recursive feature elimination with cross-validation. Select inside the CV loop to avoid optimistic bias.
AIE-198 · What is target leakage, and how would you detect it?
Leakage occurs when a feature contains information that wouldn't be available at prediction time (e.g. "refund issued" when predicting fraud). Suspiciously high validation scores, features computed after the target event and very high single-feature importance are warning signs.
AIE-199 · How do you engineer features for text data in classical ML?
Use bag-of-words or TF-IDF vectors with n-grams, plus text length, punctuation and domain keywords; reduce dimensionality with feature selection or SVD. Neural approaches use embeddings instead.
AIE-200 · What is TF-IDF?
Term frequency–inverse document frequency weights a word by how often it appears in a document times log(N/df), the inverse of how many documents contain it. Common words get low weights; distinctive words get high weights.
AIE-201 · How does SMOTE create synthetic samples?
For each minority sample, it picks one of its k nearest minority neighbours and creates a new point at a random position along the line between them. Apply it only to training data.
AIE-202 · How do you handle skewed numeric features?
Apply log, square-root or Box-Cox/Yeo-Johnson transforms to reduce skew, which helps linear models and distance-based methods; tree models are mostly unaffected.
Deep Learning Fundamentals
AIE-203 · Why does weight initialisation matter, and what are Xavier and He initialisation?
Poor initialisation makes activations and gradients explode or vanish through layers. Xavier (Glorot) scales weights by fan-in and fan-out for tanh/sigmoid; He initialisation uses variance 2/fan-in for ReLU networks.
AIE-204 · Why does ReLU help train deep networks compared with sigmoid?
ReLU doesn't saturate for positive inputs, so gradients don't shrink toward zero, it is cheap to compute and produces sparse activations. Its weakness is "dying ReLU", addressed by Leaky ReLU or GELU.
AIE-205 · How does batch normalisation help training?
It normalises each layer's inputs over a mini-batch and then rescales with learned parameters, stabilising activation distributions, allowing higher learning rates and providing slight regularisation.
AIE-206 · How does momentum improve SGD?
It accumulates a moving average of past gradients and moves along it, smoothing noisy updates and accelerating progress along consistent directions while damping oscillations.
AIE-207 · How does Adam differ from SGD with momentum?
Adam keeps moving averages of gradients (first moment) and squared gradients (second moment), giving per-parameter adaptive learning rates with bias correction. It converges quickly; well-tuned SGD can generalise slightly better for some vision tasks.
AIE-208 · How does early stopping act as regularisation?
Training stops when validation loss stops improving for a patience period, and the best checkpoint is kept, which prevents the network from fitting noise in later epochs.
AIE-209 · What is a learning-rate schedule, and why use warmup?
Schedules change the learning rate during training (step decay, cosine annealing, one-cycle). Warmup starts with a small rate and increases it, avoiding unstable early updates, especially with large batches or transformers.
AIE-210 · What is the difference between L2 regularisation and weight decay in Adam?
In SGD they are equivalent, but in Adam an L2 term is scaled by the adaptive learning rate. AdamW decouples weight decay from the gradient update, applying it directly to weights, which generalises better.
AIE-211 · How does dropout work at training and inference time?
During training each neuron is zeroed with probability p, so the network can't rely on specific co-adapted units. At inference all neurons are used; with "inverted dropout" activations are scaled by 1/(1 − p) during training so no rescaling is needed at test time.
AIE-212 · Why do residual (skip) connections help very deep networks?
They let a block learn a residual F(x) added to its input (x + F(x)), giving gradients a direct path backward and making identity mappings easy, so networks with hundreds of layers train without degradation.
AIE-213 · How do you diagnose whether a network is overfitting or underfitting from loss curves?
Training and validation loss both high and close together means underfitting (increase capacity or train longer). Low training loss with rising validation loss means overfitting (regularise, augment, get more data).
AIE-214 · What is layer normalisation, and why do transformers use it instead of batch norm?
Layer norm normalises across features within each sample rather than across the batch, so it works with small or variable batch sizes and sequence lengths and behaves the same in training and inference.
AIE-215 · How do you calculate the number of parameters in a fully connected layer with 512 inputs and 256 outputs?
Weights = 512 × 256 = 131,072, plus 256 biases, for 131,328 parameters. Parameter counts drive memory use and overfitting risk.
CNNs & Computer Vision
AIE-216 · How do you calculate the output size of a convolution layer?
Output = ⌊(W − K + 2P)/S⌋ + 1 for input width W, kernel K, padding P and stride S. For a 224 input, 7×7 kernel, padding 3 and stride 2: (224 − 7 + 6)/2 + 1 = 112.
AIE-217 · How many parameters does a 3×3 convolution with 64 input and 128 output channels have?
3 × 3 × 64 × 128 = 73,728 weights plus 128 biases = 73,856. Parameters depend on channels and kernel size, not image size, which is why CNNs are parameter-efficient.
AIE-218 · Why do stacked 3×3 convolutions often replace larger kernels?
Two 3×3 layers have a 5×5 receptive field and three give 7×7, but with fewer parameters and more non-linearities. VGG and later networks use this design.
AIE-219 · What is a 1×1 convolution used for?
It mixes channels at each spatial location, changing channel depth cheaply (bottlenecks in ResNet and Inception) and adding non-linearity without changing spatial size.
AIE-220 · How does transfer learning with a pretrained CNN work in practice?
Load a backbone pretrained on ImageNet, replace the classification head, first train the head with the backbone frozen, then optionally fine-tune deeper layers with a small learning rate. It works well with limited data.
AIE-221 · How does a two-stage detector like Faster R-CNN differ from a one-stage detector like YOLO?
Two-stage detectors propose candidate regions then classify and refine them, giving high accuracy but slower speed; one-stage detectors predict boxes and classes in a single pass, giving real-time speed with competitive accuracy.
AIE-222 · What is non-maximum suppression?
After detection, many overlapping boxes may cover the same object; NMS keeps the highest-scoring box and removes others whose IoU with it exceeds a threshold.
AIE-223 · What is mean average precision (mAP) in object detection?
For each class, average precision is the area under the precision-recall curve at a given IoU threshold; mAP averages AP across classes (and sometimes across IoU thresholds, as in COCO's mAP@[.5:.95]).
AIE-224 · What is semantic segmentation versus instance segmentation?
Semantic segmentation labels every pixel with a class; instance segmentation also separates individual objects of the same class (e.g. each person). Panoptic segmentation combines both.
AIE-225 · How does a U-Net work?
An encoder downsamples to capture context, a decoder upsamples to recover resolution, and skip connections pass fine-grained features from encoder to decoder, giving precise segmentation even with small datasets.
AIE-226 · How does data augmentation improve a vision model, and what must you be careful about?
Random crops, flips, colour jitter, rotation, mixup and cutout create plausible variations so the model learns invariances and overfits less. Augmentations must preserve the label: flipping a "6" or a left-turn road sign can change its meaning.
AIE-227 · Why do CNNs use pooling or strided convolutions?
They reduce spatial resolution, which cuts computation, enlarges the receptive field of later layers and adds some translation invariance. Many modern networks use strided convolutions instead of max pooling.
AIE-228 · How does a Vision Transformer (ViT) process images?
It splits the image into fixed-size patches (e.g. 16×16), flattens and linearly embeds each patch, adds position embeddings and a class token, and processes the sequence with a standard transformer encoder. It needs large datasets or strong augmentation to beat CNNs.
RNNs & Sequence Models
AIE-229 · How do the LSTM gates solve the vanishing gradient problem?
The cell state is updated additively (cₜ = fₜ·cₜ₋₁ + iₜ·c̃ₜ), so with the forget gate near 1, gradients flow back through many steps without repeated multiplication by small weights. Gates learn when to keep, add or expose information.
AIE-230 · How does attention improve a seq2seq encoder-decoder?
Instead of compressing the whole input into one fixed vector, the decoder computes attention weights over all encoder states at each step and uses their weighted sum as context. This fixes the bottleneck for long sentences and gives alignments.
AIE-231 · How do you prepare variable-length sequences for batch training?
Pad sequences to a common length within the batch, use masks so padding doesn't affect loss or attention, and sort or bucket sequences by length to reduce wasted computation.
AIE-232 · How does beam search work in sequence generation?
At each step it keeps the top-k partial sequences by cumulative log-probability instead of only the best one, then picks the highest-scoring complete sequence. Larger beams improve likelihood but can produce generic, repetitive text.
AIE-233 · How do you evaluate machine translation quality?
Automatic metrics such as BLEU (n-gram overlap), chrF and learned metrics like COMET compare outputs with references; human evaluation of adequacy and fluency remains the gold standard.
AIE-234 · How would you forecast demand with an LSTM?
Create sliding windows of past values plus calendar and promotional features, scale inputs, train the LSTM to predict the next step or horizon, validate with time-based splits and compare against simple baselines like seasonal naive and gradient boosting.
AIE-235 · What is the difference between stateful and stateless RNNs?
Stateless RNNs reset the hidden state for each batch; stateful RNNs carry the final state of one batch into the next, useful for very long continuous sequences split into chunks.
AIE-236 · How does a 1D convolution compare with an RNN for sequence data?
1D convolutions process sequences in parallel and capture local patterns efficiently; dilated convolutions (as in WaveNet or TCNs) extend the receptive field. RNNs process step by step and can model longer dependencies but train slower.
AIE-237 · How do Word2Vec's skip-gram and CBOW differ?
Skip-gram predicts surrounding context words from a centre word; CBOW predicts the centre word from its context. Skip-gram works better for rare words; CBOW trains faster.
AIE-238 · What is perplexity?
Perplexity = exp(average negative log-likelihood per token); it measures how well a language model predicts text. Lower perplexity means the model is less "surprised" by the data.
AIE-239 · What is connectionist temporal classification (CTC)?
A loss function that trains sequence models when input and output lengths differ and alignment is unknown, as in speech recognition, by summing over all valid alignments with a blank symbol.
AIE-240 · How do you detect anomalies in sensor time series with sequence models?
Train a model (e.g. LSTM autoencoder or forecaster) on normal data, compute reconstruction or forecast errors on new data, and flag points with errors above a threshold set from validation data.
Transformers & NLP
AIE-241 · How is scaled dot-product attention computed, and why scale by √d?
Attention(Q, K, V) = softmax(QKᵀ/√dₖ)V. Without scaling, dot products grow with dimension dₖ, pushing softmax into saturated regions with tiny gradients; dividing by √dₖ keeps the variance stable.
AIE-242 · Why is self-attention's cost quadratic in sequence length, and why does it matter?
Every token attends to every other token, so compute and memory scale as O(n²) with sequence length n. Long documents become expensive, motivating efficient attention (FlashAttention, sparse or linear attention) and chunking.
AIE-243 · What does a transformer block contain?
Multi-head self-attention and a position-wise feed-forward network, each wrapped with a residual connection and layer normalisation (pre-norm in most modern models), plus dropout during training.
AIE-244 · How does a causal mask work in a decoder?
It sets attention scores to −∞ for future positions before the softmax, so each token can attend only to itself and earlier tokens, which keeps training consistent with left-to-right generation.
AIE-245 · How does byte-pair encoding (BPE) build a vocabulary?
It starts from characters (or bytes) and repeatedly merges the most frequent adjacent pair into a new token until the vocabulary reaches its target size. Rare words are split into known subwords, so there are no out-of-vocabulary tokens.
AIE-246 · How do you fine-tune BERT for text classification?
Add a classification head on the [CLS] representation (or pooled output), train the whole model with a small learning rate (about 2e-5 to 5e-5) for a few epochs, and use early stopping on validation data.
AIE-247 · What is the difference between absolute and rotary position embeddings?
Absolute embeddings add a learned or sinusoidal vector per position; rotary embeddings (RoPE) rotate query and key vectors by position-dependent angles so attention depends on relative distance, which extrapolates better to longer contexts.
AIE-248 · What is the KV cache in transformer inference?
During autoregressive generation, keys and values of previous tokens are stored so each new token only computes attention for itself, avoiding recomputation. It speeds generation but uses memory proportional to sequence length and batch size.
AIE-249 · How do sentence embeddings for semantic search differ from BERT token embeddings?
Sentence-embedding models (e.g. SBERT) are trained with contrastive or siamese objectives so the pooled vector of a whole sentence captures meaning and cosine similarity is meaningful. Raw BERT token outputs aren't trained for that.
AIE-250 · What is the role of the feed-forward network in a transformer block?
After attention mixes information across tokens, the position-wise feed-forward network (two linear layers with a non-linearity, usually 4× wider) transforms each token's representation independently and holds much of the model's parameters and knowledge.
AIE-251 · How do you handle documents longer than a model's context window?
Chunk with overlap and process chunks separately, use hierarchical summarisation, retrieval to select relevant parts, or long-context models with efficient attention.
AIE-252 · What is greedy decoding versus top-k and nucleus (top-p) sampling?
Greedy picks the most likely token each step (deterministic, can repeat); top-k samples from the k most likely tokens; top-p samples from the smallest set whose cumulative probability exceeds p, adapting to how confident the model is.
LLMs, Prompting, RAG & Agents
AIE-253 · How does instruction tuning change a base LLM?
Fine-tuning on many (instruction, response) pairs teaches the model to follow instructions and respond helpfully in a conversational format, rather than just continuing text.
AIE-254 · How does RLHF align an LLM with human preferences?
Humans rank model responses, a reward model is trained on these preferences, then the LLM is optimised (e.g. with PPO) to maximise reward while a KL penalty keeps it close to the original model. DPO achieves similar goals directly from preference pairs.
AIE-255 · How do you chunk documents for a RAG system?
Split by semantic units (sections, paragraphs) at a size that fits the embedding model and keeps context (often a few hundred tokens), with some overlap, and store metadata (title, source, page) for filtering and citation.
AIE-256 · How do you evaluate a RAG system?
Evaluate retrieval (recall@k, MRR: did the right passages come back?) separately from generation (faithfulness to retrieved context, answer correctness, citation accuracy), using a labelled question set plus human or LLM-as-judge reviews checked against human ratings.
AIE-257 · How does LoRA make fine-tuning cheaper?
It freezes the original weights and learns small low-rank matrices A and B so the update ΔW = BA has far fewer parameters. Memory and storage drop dramatically, and many task adapters can share one base model.
AIE-258 · How does tool (function) calling work with an LLM?
The application describes available tools with names and parameter schemas; the model outputs a structured call when needed; the application executes it and returns the result to the model, which uses it to continue the answer.
AIE-259 · How do you reduce hallucinations in an LLM application?
Ground answers with retrieval and require citations, instruct the model to say when information is missing, use lower temperature for factual tasks, validate structured outputs, and evaluate on known-answer test sets.
AIE-260 · What is the difference between prompt tuning, fine-tuning and RAG for adding knowledge?
Prompting supplies instructions and examples at run time; RAG supplies relevant documents at run time and suits changing or private knowledge; fine-tuning changes weights to teach style, format or skills, and is poor at adding facts that change frequently.
AIE-261 · How does hybrid search improve retrieval?
It combines keyword search (BM25), which is good at exact terms, IDs and rare words, with dense vector search, which captures meaning and paraphrases, then merges or reranks results, often with a cross-encoder reranker.
AIE-262 · What is prompt injection and how do you defend against it?
Untrusted text (user input, retrieved web pages, documents) contains instructions that try to override the system's intended behaviour. Defences include separating instructions from data, least-privilege tool access, output validation, human approval for risky actions and treating retrieved content as untrusted.
AIE-263 · How does the ReAct pattern structure an agent?
The model alternates reasoning steps with actions (tool calls) and observations of their results, iterating until it can answer. It makes agent behaviour traceable and grounded in tool outputs.
AIE-264 · How do you estimate the cost and latency of an LLM feature?
Estimate tokens per request (prompt + context + output), multiply by request volume and per-token prices, and measure time-to-first-token and tokens per second; reduce with shorter prompts, caching, smaller models and batching.
Generative Models (GANs, VAEs, Diffusion)
AIE-265 · How is a GAN trained, and why is training unstable?
The discriminator and generator are updated alternately in a minimax game. Instability comes from non-stationary objectives, vanishing gradients when the discriminator becomes too strong, and mode collapse; techniques like WGAN-GP and spectral normalisation help.
AIE-266 · What does the VAE loss consist of?
A reconstruction term (how well the decoder reproduces the input) plus a KL-divergence term that pushes the latent distribution toward a standard normal prior, balancing reconstruction quality with a smooth, sampleable latent space.
AIE-267 · How does a diffusion model generate an image?
Start from random noise and run a learned denoising network many times, each step predicting and removing part of the noise (guided by a text prompt in text-to-image models), until a clean image emerges.
AIE-268 · What is classifier-free guidance?
The model is trained both with and without conditioning; at sampling time, the conditional and unconditional predictions are combined with a guidance scale, strengthening prompt adherence at some cost to diversity.
AIE-269 · What is a latent diffusion model?
Diffusion runs in a compressed latent space produced by an autoencoder rather than on full-resolution pixels, which cuts compute dramatically; Stable Diffusion is an example.
AIE-270 · Why are diffusion models slower at inference than GANs, and how is that improved?
They need many denoising steps; faster samplers (DDIM, DPM-Solver), distillation into few-step models and consistency models reduce the number of steps.
AIE-271 · How do you evaluate generated images beyond FID?
Use precision and recall for generative models (quality versus coverage), CLIP score for text-image alignment, human preference studies, and task-specific checks such as anatomical correctness or text rendering. FID alone can hide poor diversity or prompt adherence.
AIE-272 · What is a conditional GAN, and how is it used for image-to-image translation?
Both generator and discriminator receive a condition (label or input image). Pix2Pix uses paired images to learn mappings like sketches to photos; CycleGAN learns unpaired translation using cycle-consistency loss.
AIE-273 · How does a β-VAE encourage disentangled representations?
It increases the weight β on the KL term, pressuring latent dimensions toward independence so each captures a separate factor of variation, at the cost of blurrier reconstructions.
AIE-274 · What are normalising flows?
Generative models built from invertible transformations with tractable Jacobians, so they compute exact likelihoods and sample efficiently. They are used for density estimation and some audio and image generation.
AIE-275 · How is a diffusion model conditioned on text?
A text encoder (e.g. CLIP or T5) produces embeddings, which the denoising U-Net or transformer attends to through cross-attention layers at each denoising step.
AIE-276 · How can generative models create synthetic training data, and what are the risks?
They can augment rare classes, protect privacy or simulate edge cases, but synthetic data may miss real-world variation, copy training samples, or amplify biases. Validate models on real held-out data.
Reinforcement Learning
AIE-277 · What is the Bellman equation?
It expresses a value recursively: Q(s, a) = E[r + γ·max over a′ of Q(s′, a′)] for the optimal action-value function. Dynamic programming and TD methods use it to update estimates.
AIE-278 · What is the difference between on-policy and off-policy learning?
On-policy methods (SARSA, PPO) learn about the policy currently being followed; off-policy methods (Q-learning, DQN) learn about a target policy from data generated by another policy, enabling experience replay.
AIE-279 · How does experience replay stabilise DQN training?
Storing transitions in a buffer and sampling random mini-batches breaks correlations between consecutive samples and reuses data efficiently, making updates closer to i.i.d. supervised learning.
AIE-280 · Why does DQN use a target network?
Using the same network to compute both predictions and targets makes targets shift with every update, causing instability. A periodically updated copy provides more stable targets.
AIE-281 · How do policy gradient methods work?
They directly adjust policy parameters in the direction that increases expected return, using the gradient E[∇log π(a|s)·G]. Baselines (advantage estimates) reduce the high variance of these gradients.
AIE-282 · What is an actor-critic method?
The actor (policy) chooses actions while the critic (value function) estimates their value; the critic's advantage estimates reduce variance in the actor's policy gradient. A2C and PPO are examples.
AIE-283 · What makes PPO popular?
Proximal Policy Optimisation clips the policy update ratio so each update stays close to the previous policy, giving stable, sample-reasonable learning with simple implementation; it is widely used, including in RLHF.
AIE-284 · What is temporal difference learning?
It updates value estimates from the difference between current estimates and bootstrapped targets (r + γV(s′) − V(s)) after each step, without waiting for the episode to end, unlike Monte Carlo methods.
AIE-285 · How do you handle continuous action spaces in RL?
Use policy gradient or actor-critic methods that output action distributions (Gaussian policies) or deterministic actions (DDPG, TD3, SAC), since Q-learning's max over actions is hard with continuous actions.
AIE-286 · Why is sample efficiency a major issue in RL?
Agents often need millions of interactions to learn, which is cheap in simulators but expensive or unsafe in the real world. Model-based RL, offline RL, imitation learning and transfer from simulation reduce the data needed.
AIE-287 · What is imitation learning?
Learning a policy from expert demonstrations rather than rewards, either by behaviour cloning (supervised mapping from states to actions) or inverse RL (inferring the reward). It is common in robotics and autonomous driving.
AIE-288 · What is the sim-to-real gap, and how is it reduced?
Policies trained in simulation fail on real systems because physics, sensors and visuals differ. Domain randomisation, system identification, realistic simulators and fine-tuning on real data reduce the gap.
MLOps, Deployment & Responsible AI
AIE-289 · How do you detect data drift in production?
Compare live feature distributions with training baselines using statistics such as population stability index, KS tests or Jensen-Shannon divergence over time windows, and alert on significant changes alongside performance metrics when labels arrive.
AIE-290 · What is the difference between shadow deployment, canary release and A/B testing?
Shadow runs the new model on live traffic without affecting users; canary sends a small share of traffic to it and expands if healthy; A/B testing splits users to measure business impact statistically.
AIE-291 · How do you make an ML training pipeline reproducible?
Version code, data and configurations, fix random seeds, record library versions in containers, track experiments and artefacts, and automate the pipeline so a model can be rebuilt from a commit and data snapshot.
AIE-292 · What is a feature store and why is it useful?
A system that manages feature definitions and values for both offline training and online serving, ensuring the same transformations are used in both (avoiding training-serving skew) and allowing features to be reused across teams.
AIE-293 · What is training-serving skew?
A difference between how features are computed or what data looks like in training and in production, causing worse live performance. Shared feature code, feature stores and monitoring prevent it.
AIE-294 · How does SHAP explain a prediction?
It assigns each feature a contribution based on Shapley values from game theory, averaging the feature's marginal effect over feature coalitions. Contributions sum to the difference between the prediction and the baseline.
AIE-295 · How do you measure fairness in a classification model?
Compare metrics across groups: demographic parity (positive rates), equalised odds (TPR and FPR), equal opportunity (TPR) and calibration by group. Different fairness definitions can conflict, so choose based on context and stakeholders.
AIE-296 · How do you optimise a model for low-latency inference?
Quantise, prune or distil the model, use optimised runtimes (ONNX Runtime, TensorRT), batch requests, cache results, choose appropriate hardware, and profile pre- and post-processing too.
AIE-297 · What is knowledge distillation?
A smaller student model is trained to match the softened output probabilities (and sometimes internal features) of a larger teacher, retaining much of its accuracy at lower cost.
AIE-298 · How do you monitor a model when ground-truth labels arrive late?
Monitor input drift, prediction distribution changes, confidence scores and proxy business metrics in real time, and compute true performance once labels arrive.
AIE-299 · What privacy techniques can be used when training on sensitive data?
Anonymisation and pseudonymisation, differential privacy (adding calibrated noise), federated learning (data stays on devices), secure enclaves and strict access controls with data minimisation.
AIE-300 · What should a model governance process include?
Documentation (model cards, data sheets), risk assessment, approval before deployment, monitoring and incident response, audit trails, periodic review and compliance with regulations such as the EU AI Act.
Other levels: Basic · Advanced · Tricky · All Artificial Intelligence questions