Concepts
The questions asked in almost every ML interview, from the basics through to debugging a model that is not working.
Free Machine Learning interview preparation
A focused bank for Machine Learning interviews. Every answer is written for Iterlivo so you can prepare without leaving the page or paying for another interview-prep service.
Work through the sections in order. Open a question when you are ready to practise saying the answer out loud.
120
questions
0
practiced
8
sections
Sections
Jump to a section
Search by question or section, then practise at your pace.
Start at the top and work down. Open each prompt, say your answer before revealing the explanation, then continue.
Section 01 / 08
Answer you can say
Traditional programming gives a computer explicit rules and inputs and asks it to produce an output. Machine learning gives the computer examples of inputs and desired outputs, then learns a function that generalises to new inputs. The important qualification is that the learned function is only useful if the training examples, target definition, and evaluation procedure represent the real decision the system will make.
Answer you can say
Artificial intelligence is the broad goal of building systems that perform tasks associated with intelligent behaviour. Machine learning is a way to achieve that goal by learning patterns from data instead of writing every rule. Deep learning is a family of machine-learning methods built mainly from multi-layer neural networks; it is powerful for unstructured data, but it is not a synonym for all AI or all machine learning.
Answer you can say
Supervised learning estimates a relationship between inputs and a known target. Each training example contains features and a label, such as a transaction and whether it was fraudulent. The model is trained to minimise a loss on those examples, then evaluated on examples whose labels were not used to fit it. Classification and regression are the two common supervised problem types.
Likely follow-ups
Answer you can say
Unsupervised learning works without a supplied target. The model looks for structure in the inputs, such as groups, lower-dimensional representations, or unusual points. Clustering is one example, but dimensionality reduction and anomaly detection are also unsupervised. The output is usually a tool for discovery or downstream decisions, not automatically a ground-truth label.
Answer you can say
Classification predicts a category or a probability of a category. Regression predicts a numeric quantity where differences between values have meaning. A probability-producing classifier may output a number, but its job is still classification because the number is used to rank or threshold classes. The choice affects the target, loss, metrics, and how errors are interpreted.
The target determines the learning problem: category/probability versus numeric quantity.
Answer you can say
Semi-supervised learning combines a small labelled set with a much larger unlabelled set. It is useful when labels are expensive but unlabelled examples are plentiful, provided the unlabelled data comes from the same problem and the assumptions behind the method are reasonable. Common approaches include pseudo-labeling, consistency training, and graph-based methods. You still need a genuinely held-out labelled evaluation set.
Answer you can say
Reinforcement learning learns a policy by interacting with an environment and receiving rewards or penalties. The learner must balance exploring actions it has not tried with exploiting actions that currently look good. Unlike ordinary supervised learning, there is usually no label saying what the correct action was for every state; the feedback can be delayed and depends on the policy's own actions.
Answer you can say
Start with the decision, not the algorithm. Define who or what receives a prediction, the prediction time, the action taken, the outcome window, and the cost of false positives and false negatives. Then choose a target that is observable at the right time, decide what baseline is acceptable, and design an evaluation split that matches how the system will run. Only then choose a model.
A useful framing connects prediction time to action, outcome, and cost.
Answer you can say
A feature is an input available to the model at prediction time. The target is the outcome we want to estimate and use for training or evaluation. A prediction is the model's output for a new example. Keeping these roles separate prevents leakage: a column recorded after the outcome may look predictive in a table but cannot be a valid feature for a real-time decision.
Answer you can say
A baseline is a simple, defensible reference that the new model must beat. It might be the majority class, a historical average, a rule used by the business, or a previous production model. It tells you whether the modelling work creates value and catches evaluation mistakes: a complicated model that barely beats a sensible baseline may not be worth its cost or risk.
Answer you can say
Generalisation is the ability to make useful predictions on new examples drawn from the deployment situation. A model can fit its training data extremely well and still generalise poorly if it memorises noise, exploits leakage, or faces a different population in production. Generalisation is estimated with data and procedures that were not used to make modelling choices.
Answer you can say
Bias is error from a model that is too restrictive to represent the real relationship. Variance is error from a model that changes too much with the particular training sample and chases noise. Increasing flexibility often lowers bias and raises variance, so model selection is about finding a useful balance for the available data and the deployment loss; it is not a rule that every problem must have equal parts of both.
As flexibility grows, bias often falls while variance rises; total error has a useful middle region.
Section 02 / 08
Answer you can say
First determine why values are missing and whether the missingness itself carries signal. Fit imputation using the training data only, choose a strategy appropriate to the feature and model, and add a missingness indicator when the fact that a value was absent may matter. Validate the choice by meaningful slices; an average score can hide that imputation is harming one important group.
Answer you can say
The choice depends on cardinality, ordering, model family, unknown categories, and serving constraints. One-hot encoding is a strong simple default for low-cardinality nominal features. Ordinal encoding is only appropriate when the order is meaningful. For high-cardinality features, hashing, learned embeddings, or carefully cross-fitted target encoding may be useful, but target-derived encodings must be fitted inside each training fold to avoid leakage.
Answer you can say
Scale features when the algorithm uses distances, dot products, gradients, or a weight penalty whose effect should be comparable across columns. It matters for k-nearest neighbours, k-means, support-vector machines, and many linear or neural models. It is usually less important for tree splits. Fit the scaler on training data only, then apply the frozen transform to validation, test, and production.
Answer you can say
Feature engineering turns raw observations into inputs that expose useful, stable information to a model. Examples include time-since-event, ratios with carefully defined denominators, rolling aggregates available at prediction time, text counts, and domain-specific interactions. Good features are not merely correlated with the target; they are computable at serving time, robust to drift, and connected to the decision.
Answer you can say
Leakage is information entering training or evaluation that will not be available at prediction time, or that would not be available for the specific example in production. It includes future columns, fitting preprocessing before a split, using an outcome-derived aggregate, duplicate entities across train and test, and tuning repeatedly on the test set. The fix is to define the prediction timestamp and rebuild every transformation from information available before it.
A safe pipeline splits first, then learns transforms on train and applies them forward.
Answer you can say
Look for an implausibly strong score, a feature whose timestamp is after the target, a large train-to-production drop without a similar validation drop, and transformations that were fitted outside the training fold. Recreate features using an as-of timestamp, inspect the top features, compare performance with deliberately removed suspicious columns, and audit whether duplicates or groups cross the split. A high score is a reason to investigate, not automatically a reason to celebrate.
Answer you can say
Use time order. Train on an earlier window and validate or test on a later window, with a gap when labels or features need time to mature. Random splitting lets the model learn from the future and makes the evaluation too optimistic. If the business retrains on a rolling schedule, the evaluation should reproduce that schedule and feature availability.
For temporal data, the evaluation direction should match production: past to future.
Answer you can say
Start with the decision cost and an evaluation set that preserves production prevalence. Change the metric or threshold before changing the data. If necessary, use class weights or resampling inside the training folds only; never rebalance validation or test data to make the score look better. Check calibration because resampling changes the class prior the model sees.
Section 03 / 08
Answer you can say
Training data fits the model. Validation data supports choices such as the algorithm, hyperparameters, features, and stopping point. The test set is a final estimate after those choices are frozen. If you use the test set to choose between ideas, it becomes another validation set and the final number becomes optimistic.
Train to fit, validate to choose, test once to report.
Answer you can say
Cross-validation divides the training data into folds, trains on all but one fold, evaluates on the held-out fold, and rotates until every fold has been held out once. It gives a distribution of scores instead of relying on one lucky split, which is useful when data is limited. It does not make leakage safe and it does not replace a final untouched test set when you need an unbiased report.
Answer you can say
Stratification keeps approximately the same class proportions in each fold. It is useful for classification, especially when the positive class is uncommon, because a fold with too few positives produces an unstable or meaningless score. It is not appropriate to force class proportions when time, groups, or another dependency requires a different split strategy.
Answer you can say
Use group-aware folds when several rows belong to the same entity, such as a patient, user, or document, and the deployed model must generalise to unseen entities. Use time-based folds when future observations should not influence past predictions. Ordinary random k-fold is invalid when it lets related or future records appear on both sides of a fold.
Answer you can say
Overfitting means the model has captured details of the training sample that do not generalise. The classic signal is low training error and materially worse validation or test error. You should compare learning curves and error by slice, because a small average gap can hide severe overfitting for a rare group or time period.
Training loss can continue falling while validation loss rises after the model begins fitting noise.
Answer you can say
Underfitting is high error on both training and validation data because the representation or model capacity is insufficient. Add informative features, increase model capacity, reduce excessive regularisation, train longer when optimisation has not converged, or revisit the target and label quality. More data alone usually does not solve a model that cannot represent the pattern.
Answer you can say
A parameter is learned from the training data, such as a linear model weight. A hyperparameter is chosen outside the fitting procedure, such as tree depth, regularisation strength, learning rate, or number of neighbours. Hyperparameters can be selected with validation or cross-validation, but the test set should not be used to tune them.
Answer you can say
Keep the test set untouched. Use a training split with cross-validation, and put every learned preprocessing step inside the fold pipeline so it is fitted only on that fold's training portion. Select the configuration using the validation procedure, refit on the full training data, then evaluate once on the test set. For a highly rigorous estimate of the whole tuning procedure, use nested cross-validation.
The preprocessing pipeline belongs inside the cross-validation loop, not before it.
Answer you can say
A confidence interval describes uncertainty in an estimated quantity under a specified sampling procedure. For a model metric, it can be estimated with repeated samples, bootstrap resampling, or fold-level variability, but the method must respect groups and time dependence. It is more informative than reporting a single score when two models are close enough that random variation could explain the difference.
Answer you can say
Correlation describes a relationship between variables; it does not establish that changing one variable will change the other. A third variable, selection bias, reverse causality, or time trends can create correlation. A predictive model can use a correlated feature successfully while still being unable to answer a causal question about an intervention.
Answer you can say
Accuracy is the fraction of all examples classified correctly. It is reasonable when class frequencies are not severely skewed and false positives and false negatives have similar costs. With a rare positive class, a model that always predicts the majority can have excellent accuracy while never finding the event that matters.
Answer you can say
Precision is the fraction of positive predictions that are actually positive: true positives divided by all predicted positives. It answers, “When the system flags something, how often is the flag right?” It matters when false alarms are expensive, such as sending a human reviewer many irrelevant cases or moving legitimate email into spam.
Answer you can say
Recall is the fraction of actual positive cases that the model finds: true positives divided by all actual positives. It answers, “Of the events that mattered, how many did we catch?” High recall is important when missing a positive case is more costly than investigating a false alarm, such as safety screening or disease detection.
Answer you can say
F1 is the harmonic mean of precision and recall. It becomes high only when both are reasonably high, so it is useful when you want one balance point and the two error types have similar importance. It is not automatically the best metric: if the cost of a miss and a false alarm differs, a cost-weighted metric or a metric at a chosen operating point is more honest.
Answer you can say
A binary confusion matrix counts true positives, false positives, true negatives, and false negatives by comparing predicted and actual classes. It lets you derive accuracy, precision, recall, specificity, and related metrics while seeing which type of mistake the model makes. Always state which class is positive before interpreting it.
Rows are actual outcomes; columns are model predictions.
Answer you can say
ROC AUC measures ranking across true-positive and false-positive rates. PR AUC focuses on precision and recall and is usually more informative when the positive class is rare and the work created by false positives matters. Neither metric is enough by itself if the model operates at one threshold; report performance at the actual operating point as well.
Moving a threshold trades recall against precision; choose the operating point from the decision cost.
Answer you can say
A model is calibrated when predictions that say 0.8 are positive about 80 percent of the time over a suitable group of examples. Calibration matters when probabilities are used for risk, prioritisation, pricing, or expected-value decisions. A model can rank cases well and still be poorly calibrated; calibration curves, reliability diagrams, and methods such as isotonic regression or Platt scaling can help.
Answer you can say
Log loss penalises confident wrong probabilities more severely than uncertain ones. It is useful when the probability itself is consumed, because it rewards both discrimination and sensible confidence. A classifier can have strong accuracy or AUC and poor log loss if its probabilities are badly calibrated or aggressively overconfident.
Answer you can say
MAE is easy to interpret in the target's units and is less sensitive to large errors. MSE and RMSE penalise large errors more heavily and can be useful when those errors are disproportionately costly. MAPE can be unstable near zero. I would choose after understanding the business loss, then check residuals and performance by important segments rather than relying on one aggregate number.
Answer you can say
Statistical significance asks whether an observed difference is unlikely under a specified null model. Practical significance asks whether the size of the difference matters for the product, user, or cost. With a huge sample, a tiny improvement can be statistically significant but not worth the added latency, complexity, or maintenance burden.
Section 04 / 08
Answer you can say
Linear regression models the target as a weighted sum of input features plus an intercept. Ordinary least squares chooses weights that minimise squared residuals; other solvers or regularisation can change the optimisation but not the basic interpretation. It is useful as a transparent baseline, especially when residual behaviour and linear assumptions are reasonable.
Answer you can say
The important assumptions concern the residuals and the data-generating process: the conditional relationship is adequately represented by the features, errors are independent for the chosen unit of analysis, variance is reasonably stable when inference depends on it, and severe multicollinearity is avoided. Normal residuals are mainly important for small-sample inference, not for making point predictions by themselves. Check residual plots rather than treating the list as a ritual.
Answer you can say
It models a linear function of the log odds and then maps that value through the sigmoid function to obtain a probability between zero and one. The output can be thresholded into a class, but the underlying model estimates a smooth score or probability. The name refers to the log-odds regression, not to the final decision type.
Answer you can say
The sigmoid maps any real-valued linear score into the interval from zero to one, which can represent a Bernoulli probability. It is monotonic, so larger scores still rank examples as more likely positive. The probability is not automatically a calibrated business decision; the threshold and calibration need to be evaluated for the use case.
Answer you can say
Regularisation adds a complexity penalty to the training objective. It discourages weights or structures that fit idiosyncrasies of a limited sample, often improving performance on unseen data at the cost of some training fit. The strength must be selected using a validation procedure; too little leaves variance, while too much creates bias.
Answer you can say
L1 penalises the absolute value of weights and can drive some weights exactly to zero, producing a sparse model. L2 penalises squared weights and generally shrinks many weights toward zero without selecting an exact subset. L1 can be useful when sparsity is valuable; L2 is often more stable with correlated features. Elastic net combines both behaviours.
L1 tends to switch weights off; L2 tends to share and shrink them.
Answer you can say
For each candidate feature and threshold, the tree evaluates how much the split reduces impurity or loss in the child nodes. Classification trees commonly use Gini impurity or entropy; regression trees use a variance or squared-error reduction. The chosen split is greedy, so later pruning, depth limits, minimum leaf sizes, or ensembles are used to control variance.
A tree repeatedly partitions the feature space into more homogeneous child regions.
Answer you can say
Entropy measures uncertainty in a node's class distribution. A split has high information gain when the weighted uncertainty after splitting is much lower than before. Gini impurity serves a similar purpose with a different formula. In practice, the important points are that the split is evaluated on the training data and that the tree still needs constraints to generalise.
Answer you can say
A random forest trains many trees on bootstrap samples while considering random feature subsets, then averages or votes their predictions. Each tree is noisy, but the errors are less correlated, so averaging reduces variance. The forest is not immune to leakage, poor features, or distribution shift, and its extra trees cost memory and inference time.
Answer you can say
Random-forest trees are usually built independently and then averaged. Gradient boosting builds weak learners sequentially; each new learner focuses on residual error or the negative gradient of the current loss. Boosting can produce excellent accuracy but is sensitive to depth, learning rate, number of trees, noise, and leakage, so regularisation and early stopping matter.
Answer you can say
The learning rate scales each new learner's contribution to the ensemble. A smaller value usually needs more trees but can improve the quality of the path through the function space. The useful tradeoff is between learning rate, number of estimators, tree complexity, and early stopping; lowering the learning rate alone is not automatically better.
Answer you can say
k-nearest neighbours predicts from the labels of the closest training examples under a chosen distance. It is simple and non-parametric, but prediction can be expensive because it searches the training set, and the result is highly sensitive to feature scaling, irrelevant dimensions, the distance metric, and the choice of k. In high dimensions, distances often become less informative.
Answer you can say
As the number of dimensions grows, data becomes sparse relative to the volume of the space. Distances become less contrasted, neighbourhoods contain fewer useful examples, and the amount of data needed to estimate a stable pattern grows rapidly. Feature selection, regularisation, dimensionality reduction, and representations that encode structure can reduce the problem.
Answer you can say
An SVM chooses a decision boundary that maximises the margin between classes, allowing some violations through a penalty controlled by C. Kernels can represent nonlinear boundaries by computing similarities in an implicit feature space. SVMs often need scaled features and can become expensive when the number of training examples is very large.
Answer you can say
The kernel trick lets an algorithm compute inner products in a high-dimensional feature space through a kernel function, without explicitly constructing every transformed feature. In an SVM, this can create nonlinear decision boundaries. The kernel and its parameters still need validation, and a flexible kernel can overfit just like an explicit high-dimensional representation.
Answer you can say
Naive Bayes applies Bayes' rule while assuming features are conditionally independent given the class. That assumption is often false, but the classifier can still rank classes well when the estimated class-conditional evidence is useful and the decision boundaries are adequate. It is fast, works well for some text problems, and needs care with zero or rare likelihoods.
Answer you can say
Bagging trains models in parallel on varied samples and combines them, mainly reducing variance. Boosting trains models sequentially so later models focus on the current ensemble's errors, often reducing bias but increasing sensitivity to noise and tuning. Random forest is a bagging-style method; gradient boosting is a boosting method.
Answer you can say
I would compare the shape of the relationship, data size, missing-value and categorical handling, need for extrapolation, interpretability, latency, and the cost of maintenance. A linear model is a strong, transparent baseline and extrapolates according to its form. Trees capture nonlinear interactions with less manual transformation but can extrapolate poorly and may need more care for stable probabilities.
Answer you can say
Early stopping ends training when performance on a validation signal stops improving, often with patience for small fluctuations. It acts as a form of regularisation by limiting the number of updates or weak learners. The validation signal must be kept separate from the final test estimate, and the chosen checkpoint should be the one selected by the validation procedure.
Answer you can say
The offline data may leak future information, differ from live traffic, have the wrong label window, or optimise a proxy that does not reflect the business outcome. The model may also be too slow, poorly calibrated, unfair for an important group, or brittle under drift. I would compare data, timing, slices, thresholds, latency, and outcome definitions before blaming the algorithm.
Section 05 / 08
Answer you can say
Clustering groups examples so that members of the same group are more similar under a chosen representation and distance or probability model. The groups are not automatically meaningful business segments; they need interpretation, stability checks, and sometimes external validation. The result depends strongly on the representation, scaling, algorithm, and number or definition of clusters.
Answer you can say
K-means chooses k centroids, assigns each point to its nearest centroid, recomputes each centroid as the mean of its assigned points, and repeats until the assignments or objective stabilise. It prefers roughly spherical, similarly scaled clusters and is sensitive to initialisation and outliers. Run multiple initialisations and evaluate whether the clusters are useful, not just whether the objective is small.
K-means alternates between assignment and centroid updates until the partition stabilises.
Answer you can say
Use domain usefulness first, then diagnostics such as an elbow curve, silhouette score, stability under resampling, and sensitivity to initialisation. None of these proves that the world contains k true groups. The best value is the one that yields stable, interpretable groups for the decision the product needs to make.
Answer you can say
Hierarchical clustering builds a tree of nested groups. Agglomerative methods start with each example as its own cluster and repeatedly merge the closest groups according to a linkage rule. The dendrogram can be cut at different levels, which is useful when the number of clusters is not known in advance, but the result is sensitive to the distance and linkage choices.
Answer you can say
DBSCAN is useful when clusters may have irregular shapes and noise points should be marked as outliers. It groups dense regions using a neighbourhood radius and a minimum number of points, so it does not require k in advance. It can struggle when cluster densities vary widely or when the distance is not meaningful in the representation.
Answer you can say
Principal component analysis finds orthogonal directions that explain as much variance as possible, then represents data using the leading directions. It can compress correlated numeric features, denoise some signals, and help visualise high-dimensional data. Components are linear combinations and may not align with causal or business concepts, so fit PCA on training data only and inspect whether the transformed representation serves the task.
PCA rotates the coordinate system toward directions of high variance, then keeps selected components.
Answer you can say
PCA is a linear projection that preserves directions of global variance and can be used as a reproducible feature transform. t-SNE is mainly a visualisation method that tries to preserve local neighbourhood relationships in two or three dimensions; distances between separated groups and the global geometry can be misleading. t-SNE settings and random seed can substantially change the picture.
Answer you can say
First define what an anomaly means operationally: rare, harmful, novel, or simply different from a reference population. Possible methods include robust statistical rules, isolation forests, one-class SVMs, density models, autoencoders, and supervised classification if labels exist. Evaluate with realistic alert volume and review capacity, because an anomaly detector that flags everything is not useful.
Answer you can say
Use internal measures only as diagnostics, not as proof. Check stability under resampling and reasonable perturbations, compare against domain labels or downstream outcomes when available, inspect examples in each cluster, and ask whether the result changes a real decision. For anomaly detection, measure precision at the review budget or the cost of missed events when labels arrive later.
Answer you can say
Representation learning learns a transformation that makes useful structure easier for a downstream task. An embedding can place similar items near one another, while a neural encoder can compress raw input into features used for prediction or retrieval. The representation is only useful relative to the task, data, and evaluation; visually attractive embeddings can still discard the signal a product needs.
Section 06 / 08
Answer you can say
A neural network composes parameterised functions, usually affine transformations followed by nonlinear activations, into layers. During training, it computes a loss, uses backpropagation to obtain gradients, and updates the parameters with an optimiser. Its power comes from learning representations and compositions, but its flexibility makes data quality, regularisation, optimisation, and evaluation especially important.
Each layer transforms the representation before the next layer uses it.
Answer you can say
Without nonlinear activations, composing many linear layers is still just one linear transformation. Activations such as ReLU, GELU, sigmoid, and tanh introduce nonlinear expressiveness. The choice affects gradient flow, saturation, computation, and model behaviour; ReLU-like functions are common in hidden layers, while sigmoid or softmax may be used to parameterise particular outputs.
Answer you can say
Backpropagation applies the chain rule from the loss backward through the computation graph. Each operation receives the gradient of the loss with respect to its output and uses its local derivative to pass a gradient to its inputs. An optimiser then uses those gradients to update parameters. Backpropagation computes gradients; it is not itself the optimiser or the model architecture.
The loss sends gradients backward through the graph; the optimiser updates parameters afterward.
Answer you can say
Gradient descent updates parameters in the direction that reduces the loss: parameter minus learning rate times gradient. Batch gradient descent uses all training examples, stochastic descent uses one, and mini-batch descent uses a small sample. The learning rate controls step size; too large can diverge, too small can be slow, and adaptive optimisers change the per-parameter scaling.
Answer you can say
During backpropagation, gradients are multiplied across layers and time steps. If many factors are smaller than one, the gradient can become tiny, so early layers or long-range dependencies learn very slowly. Saturating activations, poor initialisation, and very deep or recurrent structures make it worse. ReLU-like activations, residual connections, careful initialisation, normalisation, and gated architectures help.
Answer you can say
Gradients can grow rapidly when repeated multiplication amplifies them. Training becomes unstable, parameters can jump far from a useful region, and the loss may become NaN. Gradient clipping limits the update or norm, while better initialisation, normalisation, architecture choices, and a suitable learning rate address the underlying cause.
Answer you can say
Batch normalisation normalises intermediate activations using statistics from a training batch, then learns a scale and shift. It can make optimisation easier and sometimes regularise the model. Training and inference use different statistics, and very small or correlated batches can make the estimate noisy. It is not a substitute for a correct data split or a cure for every training problem.
Answer you can say
Dropout randomly removes units or connections during training, forcing the network to avoid depending on one fragile path. At inference, the full network is used with the corresponding scaling convention. It is a regularisation technique, not the same mechanism as L1 or L2, and its usefulness depends on architecture, data size, and whether the model is already underfitting.
Answer you can say
Start with a tiny dataset and verify that the model can overfit it, which catches broken labels, loss, gradients, and input plumbing. Then inspect input ranges, target encoding, loss-output compatibility, gradient norms, learning rate, parameter updates, and train/evaluation mode. Compare against a simple baseline and add regularisation only after the unregularised training path works.
Answer you can say
Match the loss to the target and the decision. Cross-entropy is common for classification, mean squared or absolute error for regression, and specialised objectives for ranking, contrastive learning, or structured outputs. Check the output activation and target encoding together: for example, logits with a loss that applies the appropriate stable transformation are different from probabilities fed into the wrong loss.
Answer you can say
A convolutional neural network applies local filters across an input so that the same learned detector can recognise a pattern at different positions. Stacking convolutions and downsampling builds increasingly broad and abstract receptive fields. CNNs are useful when locality and translation structure are meaningful, such as images, audio, or some spatial signals.
A convolution reuses the same local filter across positions before later layers combine features.
Answer you can say
Pooling summarises a local region, often with a maximum or average, reducing spatial resolution and computation. It can provide some tolerance to small shifts, but it also discards information and is not always necessary when strided convolutions or modern architectures provide the downsampling. The right choice depends on the task and the resolution the output needs.
Answer you can say
Transfer learning starts with a model or representation learned on one task or dataset and adapts it to another. The source model provides useful low-level or semantic features, so the target task may need less labelled data and compute. You must still check domain mismatch, label leakage, fine-tuning strategy, and whether the transferred representation helps the target metric.
Answer you can say
Fine-tuning continues training a pretrained model on task-specific data, often with a smaller learning rate than training from scratch. You may update all layers, only a head, or selected layers depending on data size, domain shift, and compute. Monitor for catastrophic forgetting, overfitting, and contamination between pretraining, tuning, and evaluation data.
Answer you can say
An embedding is a learned dense vector representation in which useful relationships may be reflected by distance or direction. Text, images, users, and items can all be embedded, but the geometry is meaningful only for the training objective and data distribution that produced it. For retrieval, evaluate nearest-neighbour quality and task outcomes rather than assuming semantic similarity from a visualisation.
Answer you can say
An autoencoder learns an encoder that maps input to a latent representation and a decoder that reconstructs the input. A bottleneck or noise objective can force the representation to retain useful structure. Autoencoder reconstruction quality does not automatically mean the latent space is useful for classification, anomaly detection, or generation; that downstream goal needs its own validation.
Answer you can say
A recurrent neural network processes a sequence while carrying a hidden state from one step to the next. Plain RNNs can struggle with long dependencies because gradients vanish or explode through repeated updates. LSTMs and GRUs add gates that control what to retain, update, and expose, making long-range learning more stable, although transformers are often preferred when parallel attention is practical.
Answer you can say
Attention computes a weighted combination of values, where the weights depend on the compatibility between a query and keys. It lets each position select relevant information rather than compressing the entire sequence into one recurrent state. The representation is powerful, but full self-attention has quadratic cost in sequence length, which motivates sparse, grouped, or approximate variants.
A query scores keys, then mixes the corresponding values into a context-aware representation.
Answer you can say
A transformer is a sequence architecture built around self-attention and position information, usually with feed-forward blocks, residual connections, and normalisation. Encoder-style transformers are common for representations, decoder-style transformers generate autoregressively, and encoder-decoder models transform one sequence into another. They parallelise training well, but attention and context length have compute and memory costs.
Transformer blocks repeatedly mix token representations through self-attention and feed-forward transformations.
Answer you can say
A model can lose performance on an earlier task when it is trained on a new task, because the new updates overwrite parameters or representations useful for the old one. Mitigations include replaying old examples, regularising important parameters, adapters or parameter isolation, and multi-task objectives. The correct solution depends on whether retaining old behaviour is required.
Section 07 / 08
Answer you can say
A large language model is a neural sequence model trained to estimate or generate token sequences, commonly by predicting the next token from context. Scale, data, architecture, and training objective give it broad language capability, but next-token likelihood is not the same as truth, reasoning reliability, or alignment with a user's goal. Those properties need targeted evaluation and safeguards.
Answer you can say
Tokenisation converts text into the discrete units a language model consumes. A token may be a character, word piece, punctuation mark, or whitespace pattern, depending on the tokenizer. Tokenisation affects context length, cost, multilingual behaviour, code handling, and how easily the model can represent rare words.
Answer you can say
Pretraining learns broad language or multimodal patterns from large datasets, usually through a self-supervised objective. Instruction tuning adapts the model to follow examples of tasks and responses. Alignment adds preferences or constraints through methods such as preference optimisation, human feedback, or rule-based evaluation. None of these guarantees factual accuracy for a new domain.
Answer you can say
Temperature rescales the logits before sampling. Lower values make high-probability tokens more dominant and outputs more repeatable; higher values flatten the distribution and increase variation. It does not add knowledge or fix a bad prompt, and for deterministic evaluation you should control the random seed or use a deterministic decoding strategy when the serving stack supports it.
Answer you can say
Greedy decoding selects the highest-probability next token at each step. Beam search keeps several partial sequences and can improve likelihood under some sequence-to-sequence tasks, though it can produce generic text. Sampling draws from a probability distribution and supports diversity through temperature, top-k, or nucleus sampling. The best method depends on whether diversity or exactness is desired.
Answer you can say
Prompt engineering is designing the task instruction, context, examples, output format, and constraints so the model has a better chance of producing a useful response. Good prompts reduce ambiguity and make outputs easier to evaluate, but they do not replace retrieval, fine-tuning, tool checks, or application validation when correctness matters. A prompt should be tested against representative and adversarial cases.
Answer you can say
RAG retrieves relevant documents or records at query time, places their content into the model context, and asks the model to answer using that evidence. It can reduce dependence on memorised knowledge and make updates easier, but retrieval errors, irrelevant context, chunk boundaries, permissions, and unsupported generation still matter. Evaluate retrieval and answer grounding separately.
RAG separates retrieval from generation: retrieve evidence first, then generate within the evidence budget.
Answer you can say
Choose it from document structure, query granularity, embedding quality, context budget, and the amount of context required to answer. Small chunks improve pinpoint retrieval but can remove necessary context; large chunks preserve context but dilute similarity and consume more tokens. Test chunking with a labelled query-evidence set and measure recall of sufficient evidence, not just embedding similarity.
Answer you can say
An embedding model maps a query and candidate documents into vectors, then a similarity function retrieves nearby candidates. It can match meaning beyond exact keywords, but the embedding model and index must reflect the language, domain, and task. Combine semantic retrieval with filters, lexical search, metadata, reranking, and access control when the product needs them.
Answer you can say
A first-stage retriever quickly returns a candidate set using lexical or vector search. A reranker then scores the query-candidate pairs with a more expressive model and reorders a smaller number of candidates. Reranking can improve relevance but adds latency and cost, so measure the gain at the final context budget rather than only at a large candidate count.
Answer you can say
A hallucination is an unsupported or false output presented as if it were a valid answer. Reduce it with better retrieval and grounding, constrained output schemas, tool or database verification, abstention rules, lower ambiguity, targeted fine-tuning where appropriate, and evaluation sets that include unanswerable questions. You cannot solve it by asking the model to “be accurate” alone.
Answer you can say
Evaluate retrieval recall and ranking, answer correctness, evidence relevance, citation faithfulness, refusal behaviour, latency, cost, and security. Use a representative labelled set with answerable and unanswerable questions, plus adversarial cases such as conflicting documents and prompt injection. Human review remains useful, but automated metrics should be validated against the actual product goal.
Answer you can say
Use RAG when the assistant must quote or update external knowledge, respect document permissions, or answer from a changing corpus. Fine-tuning is better for changing behaviour, format, style, or a repeated task pattern, although it can also teach domain language. Many systems use both, but neither removes the need for retrieval, evaluation, and output controls when factual correctness matters.
Answer you can say
Parameter-efficient methods update a small set of additional or selected parameters instead of all base-model weights. Examples include adapters and low-rank updates. They reduce memory, training cost, and storage per task, while preserving a shared base, but they can still overfit, leak sensitive data, or fail under a large domain shift.
Answer you can say
Prompt injection is an attempt to make a model treat untrusted content as instructions or override the application's intended constraints. It can appear in user input, retrieved documents, web pages, tool outputs, or images. Defences include separating data from instructions, least-privilege tools, strict schemas, retrieval filtering, output validation, and assuming that model text alone cannot enforce a security boundary.
Answer you can say
The model can only attend to a bounded number of tokens, and longer context increases memory and latency. Even within the limit, important evidence can be diluted by irrelevant text or lost among many similar passages. Solutions include better retrieval, query-focused summarisation, hierarchical context, structured memory, compression, and measuring answer quality as context grows.
Answer you can say
Measure where the budget goes first: model size, input tokens, output tokens, retrieval, tool calls, and queueing. Then consider a smaller model, caching, shorter or structured context, batching, streaming, quantisation, speculative decoding, routing simple cases to cheaper models, and limiting output length. Quality, safety, and tail latency must be checked at the same workload, not traded away invisibly.
Answer you can say
A benchmark is a fixed set of tasks and metrics used to compare systems. It is useful for a shared reference, but it may not represent the product's users, languages, documents, failure costs, or adversarial inputs. A strong evaluation combines public benchmarks with a private, versioned, representative test set and human or domain review for the behaviours that automated metrics miss.
Answer you can say
Classify the data and define what the application is allowed to send before choosing a model. Apply minimisation, redaction or tokenisation, access controls, tenant isolation, encryption, retention limits, provider configuration, logging review, and output filtering. Treat prompts, retrieved context, tool results, and model responses as sensitive data paths and test for indirect leakage.
Answer you can say
Refuse when the request violates a policy, exceeds the system's authority, or cannot be answered safely from the available evidence. Ask a clarifying question when multiple interpretations would lead to materially different answers or actions. Otherwise, answer with explicit assumptions and uncertainty. The policy should be enforced by application logic and tool permissions, not only by a natural-language instruction.
Section 08 / 08
Answer you can say
Freeze the exact model and compare the training, validation, and production populations. Check feature availability and transformations at the prediction timestamp, label maturity, missingness and category changes, threshold and calibration, segment performance, duplicates, and drift. Reproduce one production prediction offline from logged inputs. Only after the data and contract are verified should you change the model.
Answer you can say
Define readiness against the real decision: offline performance at the operating point, slice and stress-test behaviour, calibration, latency and resource budgets, feature freshness, fallback behaviour, privacy and security checks, monitoring, rollback, and ownership. The model is not ready just because a benchmark improved; the full data-to-decision path needs an explicit contract and an observed failure plan.
Answer you can say
Data drift is a change in the distribution of inputs. Concept drift is a change in the relationship between inputs and the target, so the same features no longer imply the same outcome. Input monitoring can detect data drift quickly, but concept drift often needs delayed labels, outcome monitoring, or carefully designed proxy signals. The fixes differ: a pipeline issue, retraining, feature redesign, or a changed decision may be required.
Answer you can say
Monitor the input schema and distributions, missingness, freshness, prediction distribution, latency, errors, resource use, and segment coverage. When labels arrive, monitor the actual target and model metrics with confidence intervals and compare to the baseline. Alerts should connect to an owner and a runbook; a dashboard full of unowned charts is not monitoring.
Answer you can say
First verify the group definitions, label quality, sample sizes, and whether the comparison is being made at a common operating point. Report multiple relevant metrics and error types, not only an average. Then investigate data and feature causes, threshold or calibration choices, reweighting, constrained training, or separate operational policies, while involving the affected stakeholders because fairness is a deployment requirement and not only a metric.
Answer you can say
Feature importance describes how a fitted model's predictions or loss change under a chosen definition, such as split gain, permutation impact, or a local explanation. It is not automatically causal, stable under correlated features, or proof that removing a feature will have the same effect. Compare explanations across resamples and use domain or intervention evidence when the question is causal.
Answer you can say
Version the data snapshot or query, feature code, labels, environment, dependencies, random seeds, model configuration, evaluation split, and artefacts. Record the exact command and metrics, preserve the test-set policy, and make a run reproducible without relying on a notebook's hidden state. Reproducibility is a prerequisite for knowing whether an improvement is real.
Answer you can say
Use validation data to estimate the tradeoff between actions, then choose the threshold from the cost of false positives and false negatives, capacity, policy, and calibration. The default 0.5 is only meaningful under particular assumptions. Recheck the threshold when prevalence, capacity, or costs change, and report the metric at the chosen operating point.
The threshold is the policy boundary between a model score and an action.
Answer you can say
Use the same prediction population, label definition, split, preprocessing policy, and evaluation window. Compare confidence intervals or paired examples when possible, inspect important slices, and include latency, cost, calibration, and operational failure rates. Do not choose the winner by repeatedly looking at the test set until one number wins.
Answer you can say
State the objective and assumptions, define the data and time of prediction, choose an evaluation that matches deployment, name the main failure modes, and explain the tradeoff in plain language. A strong answer does not jump straight to an algorithm; it says what you would measure, what could leak, what would make the result misleading, and how you would decide whether the model is useful.