🤖

Top 88 Machine Learning / AI Interview Questions & Answers (2026)

88 Questions 42 Beginner 30 Intermediate 16 Advanced

About Machine Learning / AI

Top 100 Machine Learning and AI interview questions covering supervised learning, neural networks, deep learning, NLP, and MLOps. Companies hiring for Machine Learning / AI roles test this knowledge at every stage — from first-round screens that check the basics to final-round conversations about real-world trade-offs.

What to Expect in a Machine Learning / AI Interview

Expect a mix of conceptual and practical Machine Learning / AI questions: clear definitions and core-concept checks for junior roles, hands-on scenario questions for mid-level roles, and architecture or trade-off discussions for senior roles. Interviewers usually move from foundational topics toward the kind of problems you'd actually face on the job.

How to Use This Guide

Work through the Machine Learning / AI questions in order — Beginner, then Intermediate, then Advanced — so each concept builds on the last. Every question has its own page; bookmark the ones that trip you up and revisit them the day before your interview.

Curated by Tech Baithak Editorial Team  ·  Last updated: June 2026

Beginner 42 questions

Core concepts every Machine Learning / AI developer must know.

01

What is Machine Learning?

Machine Learning (ML) is a subset of Artificial Intelligence that enables computers to learn from data and improve their performance on tasks without being explicitly programmed. Instead of writing hard-coded rules, you feed examples to a model, and it discovers patterns automatically. ML is broadly categorized into supervised learning, unsupervised learning, and reinforcement learning. Real-world applications include email spam filters, recommendation engines, fraud detection, and image recognition.

Open this question on its own page
02

What is the difference between Artificial Intelligence, Machine Learning, and Deep Learning?

Artificial Intelligence (AI) is the broadest concept — any technique that enables machines to mimic human intelligence. Machine Learning is a subset of AI where systems learn from data rather than following explicit rules. Deep Learning is a subset of ML that uses multi-layered neural networks (deep neural networks) to learn hierarchical representations. Think of it as nested circles: AI ⊃ ML ⊃ Deep Learning. Deep Learning requires more data and compute but achieves state-of-the-art results on tasks like image recognition and NLP.

Open this question on its own page
03

What is supervised learning?

Supervised learning is a type of ML where the model is trained on labeled data — each training example has an input and a known correct output (label). The model learns to map inputs to outputs by minimizing the error between its predictions and the true labels. Common algorithms include linear regression, decision trees, and neural networks. Examples: spam classification (input = email, label = spam/not spam) and house price prediction (input = features, label = price).

Open this question on its own page
04

What is unsupervised learning?

Unsupervised learning involves training on data that has no labels. The model must discover hidden structure or patterns on its own. The two main tasks are clustering (grouping similar data points, e.g., K-Means) and dimensionality reduction (compressing data while preserving structure, e.g., PCA). It is useful when labeling data is expensive or impractical, such as customer segmentation, anomaly detection, and topic modeling.

Open this question on its own page
05

What is a training set, validation set, and test set?

Data is split into three subsets. The training set is used to fit the model parameters. The validation set is used during development to tune hyperparameters and compare models — it gives an unbiased estimate of model performance while you still have the ability to adjust. The test set is held out until the very end and used only once to give a final, unbiased evaluation of the chosen model. A common split ratio is 70/15/15 or 80/10/10.

Open this question on its own page
06

What is overfitting and underfitting?

Overfitting occurs when a model learns the training data too well, including noise and random fluctuations, resulting in high training accuracy but poor generalization to new data. Underfitting occurs when a model is too simple to capture the underlying patterns, performing poorly on both training and test data. Overfitting is combated with regularization, more data, dropout, or simpler models. Underfitting is fixed by increasing model complexity, training longer, or adding more features.

Open this question on its own page
07

What is a feature in machine learning?

A feature (also called a predictor or independent variable) is a measurable property of the data used as input to a model. For a house price prediction model, features might include square footage, number of bedrooms, and location. Feature engineering is the process of selecting, transforming, and creating features to improve model performance. Good features that correlate with the target variable are essential — "garbage in, garbage out" is a fundamental ML principle.

Open this question on its own page
08

What is a label or target variable?

A label (also called the target variable or dependent variable) is the output value that a supervised model is trained to predict. In a classification task, labels are discrete categories (e.g., "cat" or "dog"). In a regression task, labels are continuous values (e.g., house price in dollars). The model learns to map input features to the correct label by minimizing a loss function that measures the difference between predicted and actual labels.

Open this question on its own page
09

What is classification vs regression?

Classification predicts a discrete category or class label — the output is one of a finite set of values. Examples: email is spam or not spam, image is a cat or dog. Common algorithms: logistic regression, decision trees, random forests, SVMs. Regression predicts a continuous numerical value. Examples: house price, stock value, temperature tomorrow. Common algorithms: linear regression, polynomial regression, gradient boosting. The choice of loss function and evaluation metric differs between the two tasks.

Open this question on its own page
10

What is a neural network?

A neural network is a computational model loosely inspired by the structure of biological brains. It consists of layers of interconnected nodes (neurons): an input layer, one or more hidden layers, and an output layer. Each connection has a weight, and each neuron applies an activation function to its weighted inputs. During training, weights are adjusted via backpropagation to minimize prediction error. Neural networks can learn complex non-linear patterns and are the foundation of deep learning.

Open this question on its own page
11

What is gradient descent?

Gradient descent is the primary optimization algorithm used to train ML models. It iteratively updates model parameters (weights) in the direction that minimizes the loss function. The gradient (partial derivatives of the loss) tells us how to move to increase the loss; we move in the opposite direction. The learning rate controls the step size. Variants include Stochastic Gradient Descent (SGD) (one sample per update), Mini-batch GD (subset per update), and advanced optimizers like Adam and RMSProp.

Open this question on its own page
12

What is a loss function?

A loss function (also called a cost function or objective function) measures how far the model's predictions are from the true labels. It is the signal that gradient descent minimizes. Common loss functions: Mean Squared Error (MSE) for regression, Cross-Entropy Loss for classification, Mean Absolute Error (MAE) for regression with outliers. Choosing the right loss function is important — MSE penalizes large errors more than MAE because it squares the difference.

Open this question on its own page
13

What is an activation function?

An activation function introduces non-linearity into a neural network, allowing it to learn complex patterns. Without activation functions, a neural network with multiple layers would collapse into a single linear transformation. Common activation functions: ReLU (max(0, x)) — most widely used in hidden layers; Sigmoid (outputs 0–1) — used in binary classification output; Softmax — used in multi-class output layers (outputs probability distribution); Tanh — outputs -1 to 1, used in some RNN architectures.

Open this question on its own page
14

What is cross-validation?

Cross-validation is a technique to estimate model performance more reliably by using the data more efficiently. In k-fold cross-validation, the training data is split into k equal folds. The model is trained k times, each time using k-1 folds for training and 1 fold for validation. The final performance is averaged across all k runs. This reduces variance in performance estimates compared to a single train/val split and helps detect overfitting. A common choice is k=5 or k=10.

Open this question on its own page
15

What is the bias-variance tradeoff?

The bias-variance tradeoff is a fundamental ML concept describing the two sources of prediction error. Bias is error from overly simplistic assumptions — a high-bias model underfits. Variance is error from sensitivity to small fluctuations in training data — a high-variance model overfits. Total expected error = Bias² + Variance + Irreducible Noise. Increasing model complexity reduces bias but increases variance, and vice versa. The goal is to find the sweet spot with low bias and low variance, achieved through regularization, cross-validation, and ensembling.

Open this question on its own page
16

What is logistic regression?

Despite its name, logistic regression is a classification algorithm, not regression. It models the probability that an input belongs to a class using the sigmoid function, which squashes the output to a value between 0 and 1. If the predicted probability > 0.5, the class is 1; otherwise 0. It is trained using cross-entropy loss and gradient descent. Logistic regression is fast, interpretable, and works well for linearly separable data. It can be extended to multi-class problems using softmax regression (multinomial logistic regression).

Open this question on its own page
17

What is linear regression?

Linear regression models the relationship between input features and a continuous target variable as a linear combination: y = w₁x₁ + w₂x₂ + ... + b. The weights (coefficients) and bias are learned by minimizing Mean Squared Error. Key assumptions: linearity, independence of errors, homoscedasticity, and normality of residuals. It is fast, highly interpretable, and serves as a baseline for regression tasks. For non-linear relationships, polynomial regression or more complex models are needed.

Open this question on its own page
18

What is a decision tree?

A decision tree is a tree-structured model that makes predictions by asking a sequence of binary questions about features, splitting the data at each node until reaching a leaf node with a class label or value. Splits are chosen to maximize information gain (using entropy or Gini impurity for classification, or MSE reduction for regression). Decision trees are interpretable and handle both numerical and categorical data, but are prone to overfitting on deep trees. Pruning or ensembling (Random Forests, Gradient Boosting) is used to improve generalization.

Open this question on its own page
19

What is a Random Forest?

A Random Forest is an ensemble method that builds many decision trees during training and aggregates their predictions. Each tree is trained on a random bootstrap sample of the data (bagging), and at each split, only a random subset of features is considered. This introduces diversity among trees, reducing variance while maintaining low bias. For classification, the forest takes a majority vote; for regression, it averages predictions. Random Forests are robust, handle high-dimensional data well, and provide feature importance scores.

Open this question on its own page
20

What is k-Nearest Neighbors (KNN)?

K-Nearest Neighbors (KNN) is a non-parametric, lazy learning algorithm that classifies a new point by finding the k training points closest to it (using Euclidean or other distance metrics) and taking a majority vote. For regression, it averages the neighbors' values. "Lazy" means it stores all training data and does no training — computation happens at prediction time, making inference slow for large datasets. Choosing the right k is important: too small causes overfitting, too large causes underfitting. Feature scaling is essential for KNN.

Open this question on its own page
21

What is a Support Vector Machine (SVM)?

A Support Vector Machine (SVM) finds the hyperplane that maximally separates classes in feature space. The margin is the distance between the hyperplane and the nearest data points (support vectors) of each class. SVM maximizes this margin, leading to better generalization. For non-linearly separable data, the kernel trick (RBF, polynomial kernels) maps data to higher-dimensional space where it becomes separable. SVMs work well in high-dimensional spaces and with small datasets but scale poorly to very large datasets.

Open this question on its own page
22

What is feature scaling and why is it important?

Feature scaling is the process of normalizing the range of independent variables. Many ML algorithms are sensitive to the scale of features — algorithms that use distance metrics (KNN, SVM, K-Means) or gradient descent (neural networks, linear regression) perform poorly when features have very different scales. Min-Max Normalization scales features to [0, 1]; Standardization (Z-score) transforms features to have mean 0 and standard deviation 1. Tree-based models (Random Forest, XGBoost) are generally scale-invariant.

Open this question on its own page
23

What is the difference between parameters and hyperparameters?

Parameters are the internal values learned by the model during training from the data — for example, the weights and biases in a neural network, or the coefficients in linear regression. Hyperparameters are configuration settings set before training that control the learning process — for example, learning rate, number of epochs, number of hidden layers, batch size, regularization strength. Parameters are optimized automatically by the training algorithm; hyperparameters must be tuned manually or via techniques like grid search, random search, or Bayesian optimization.

Open this question on its own page
24

What is regularization?

Regularization is a technique to reduce overfitting by adding a penalty term to the loss function that discourages overly complex models. L1 regularization (Lasso) adds the sum of absolute weights — it can drive weights to exactly zero, performing automatic feature selection. L2 regularization (Ridge) adds the sum of squared weights — it shrinks weights toward zero but rarely makes them exactly zero. Elastic Net combines L1 and L2. The regularization strength λ controls the trade-off between fitting the data and model simplicity.

Open this question on its own page
25

What is a confusion matrix?

A confusion matrix is a table used to evaluate the performance of a classification model. It has four entries: True Positives (TP) — correctly predicted positive, True Negatives (TN) — correctly predicted negative, False Positives (FP) — predicted positive but actually negative (Type I error), and False Negatives (FN) — predicted negative but actually positive (Type II error). From these, we compute metrics like Accuracy, Precision, Recall, F1-Score, and Specificity.

Open this question on its own page
26

What is precision, recall, and F1-score?

Precision = TP / (TP + FP) — of all predicted positives, how many were actually positive. High precision means few false alarms. Recall (Sensitivity) = TP / (TP + FN) — of all actual positives, how many were correctly identified. High recall means few misses. There is a tradeoff: increasing one typically decreases the other. The F1-Score = 2 × (Precision × Recall) / (Precision + Recall) — harmonic mean, balancing both. F1 is preferred over accuracy when classes are imbalanced.

Open this question on its own page
27

What is accuracy and when is it misleading?

Accuracy = (TP + TN) / Total predictions — the fraction of predictions that are correct. It is easy to understand but misleading for imbalanced datasets. For example, if 95% of emails are not spam, a model that always predicts "not spam" achieves 95% accuracy but is useless. In such cases, metrics like Precision, Recall, F1-Score, AUC-ROC, or Matthews Correlation Coefficient (MCC) are more informative because they account for the distribution of classes.

Open this question on its own page
28

What is the ROC curve and AUC?

The ROC (Receiver Operating Characteristic) curve plots the True Positive Rate (Recall) against the False Positive Rate at various classification thresholds. It visualizes the tradeoff between sensitivity and specificity. The AUC (Area Under the Curve) summarizes the ROC curve in a single number: AUC = 1.0 means a perfect classifier; AUC = 0.5 means a random classifier. AUC is threshold-independent and works well for imbalanced classes. A good model typically achieves AUC > 0.8.

Open this question on its own page
29

What is K-Means clustering?

K-Means is an unsupervised clustering algorithm that partitions data into K clusters. The algorithm: 1) Randomly initialize K centroids. 2) Assign each point to the nearest centroid. 3) Update each centroid to the mean of its assigned points. 4) Repeat until convergence. The objective is to minimize within-cluster variance. Limitations: requires choosing K in advance, sensitive to initial centroids and outliers, assumes spherical clusters. The Elbow Method and Silhouette Score help choose optimal K.

Open this question on its own page
30

What is Principal Component Analysis (PCA)?

PCA is a dimensionality reduction technique that transforms data into a new coordinate system where the axes (principal components) are ordered by the amount of variance they explain. The first principal component explains the most variance, the second explains the most remaining variance, and so on. PCA reduces noise, removes correlated features, and speeds up training. It is achieved via eigendecomposition of the covariance matrix. A key decision is how many components to retain — typically chosen to preserve 95% of variance.

Open this question on its own page
31

What is transfer learning?

Transfer learning is the technique of taking a model pre-trained on a large dataset (like ImageNet for images or Wikipedia for text) and fine-tuning it on a smaller, task-specific dataset. The pre-trained model has already learned general features (edges, textures, grammar) that are reusable. This dramatically reduces training time and data requirements. In computer vision, models like ResNet and VGG are commonly fine-tuned. In NLP, BERT and GPT are pre-trained and fine-tuned on downstream tasks.

Open this question on its own page
32

What is data augmentation?

Data augmentation is a technique to artificially expand the training dataset by applying transformations to existing samples. For images: random flips, rotations, crops, color jitter, and adding noise. For text: synonym replacement, back-translation, and random insertion/deletion. For audio: pitch shifting, time stretching, and adding background noise. Augmentation helps prevent overfitting by exposing the model to more varied inputs and acts as a regularizer. It is especially important when labeled data is scarce.

Open this question on its own page
33

What is batch size and how does it affect training?

Batch size is the number of training examples used in one forward/backward pass before updating the model weights. Full-batch gradient descent uses all data — stable but very slow. Stochastic GD (batch size = 1) is noisy but can escape local minima. Mini-batch GD (typical sizes: 32, 64, 128) balances stability and speed, and leverages GPU parallelism efficiently. Larger batches produce smoother gradient estimates but may converge to sharper minima with worse generalization (the "generalization gap" phenomenon).

Open this question on its own page
34

What is an epoch?

An epoch is one complete pass through the entire training dataset during model training. If you have 10,000 samples and a batch size of 100, one epoch consists of 100 weight update steps (iterations). Training usually runs for multiple epochs until the model converges (loss stops decreasing significantly). Too few epochs leads to underfitting; too many leads to overfitting. Early stopping monitors validation loss and halts training when it stops improving, choosing the best epoch automatically.

Open this question on its own page
35

What is the learning rate?

The learning rate (η) controls how large a step gradient descent takes when updating weights. A learning rate too large causes the loss to diverge or oscillate. A learning rate too small leads to very slow convergence and can get stuck in local minima. Finding the right learning rate is crucial. Techniques include learning rate schedules (step decay, cosine annealing), learning rate warmup, and adaptive optimizers like Adam and RMSProp that automatically adjust the effective learning rate per parameter.

Open this question on its own page
36

What is backpropagation?

Backpropagation is the algorithm used to compute gradients of the loss function with respect to each weight in a neural network. It applies the chain rule of calculus to propagate the error signal backward from the output layer through the hidden layers. The forward pass computes activations and the loss; the backward pass computes gradients layer by layer. These gradients are then used by an optimizer (e.g., SGD, Adam) to update weights. Backpropagation is the cornerstone of all gradient-based neural network training.

Open this question on its own page
37

What are the main types of machine learning algorithms?

ML algorithms are broadly categorized by learning paradigm: Supervised Learning — trains on labeled data (linear/logistic regression, SVM, decision trees, neural networks); Unsupervised Learning — finds structure in unlabeled data (K-Means, PCA, DBSCAN, autoencoders); Semi-Supervised Learning — uses a small amount of labeled data with large amounts of unlabeled data; Reinforcement Learning — an agent learns by interacting with an environment and receiving reward signals (Q-learning, policy gradient methods); Self-Supervised Learning — labels are generated from the data itself (used in BERT, GPT pre-training).

Open this question on its own page
38

What is Naive Bayes?

Naive Bayes is a probabilistic classifier based on Bayes' theorem with the "naive" assumption that features are conditionally independent given the class. Despite this unrealistic assumption, it works surprisingly well in practice, especially for text classification (spam filtering, sentiment analysis). It is extremely fast to train and predict, handles high-dimensional data well, and requires very little data. Variants include Gaussian NB (continuous features), Multinomial NB (word counts), and Bernoulli NB (binary features).

Open this question on its own page
39

What is the curse of dimensionality?

The curse of dimensionality refers to the phenomena that arise when analyzing data in high-dimensional spaces that do not occur in low-dimensional settings. As the number of features grows, the volume of the space increases exponentially, causing data to become increasingly sparse. This means distance metrics become less meaningful (all points appear equidistant), models need exponentially more data to generalize, and computation becomes expensive. Solutions include dimensionality reduction (PCA, t-SNE, UMAP), feature selection, and regularization.

Open this question on its own page
40

What is a hyperparameter search?

Hyperparameter search (or tuning) is the process of finding the optimal hyperparameter configuration for a model. Grid Search exhaustively tests all combinations in a predefined grid — thorough but expensive. Random Search randomly samples combinations — more efficient than grid search for high-dimensional hyperparameter spaces. Bayesian Optimization builds a probabilistic model of the objective function and uses it to select the most promising hyperparameter values, converging faster than random search. Tools: Scikit-learn's GridSearchCV, Optuna, Ray Tune.

Open this question on its own page
41

What is a pipeline in machine learning?

An ML pipeline is a sequence of data processing and modeling steps chained together to automate the end-to-end workflow. A typical pipeline includes: data ingestion → preprocessing (imputation, scaling, encoding) → feature engineering → model training → evaluation → deployment. Pipelines ensure that the same transformations applied to training data are also applied to test/inference data, preventing data leakage. Scikit-learn's Pipeline class is a standard way to bundle preprocessing and modeling steps together.

Open this question on its own page
42

What is data leakage in machine learning?

Data leakage occurs when information from outside the training dataset (specifically from the test set or from the future) is used to build the model, resulting in overly optimistic performance estimates that do not generalize. Common examples: fitting a scaler on the full dataset before splitting, including future information in features (look-ahead bias), or having test samples appear in the training set. Preventing leakage requires performing all preprocessing steps (scaling, imputation, encoding) only on the training set and applying the fitted transformers to validation/test sets.

Open this question on its own page
Intermediate 30 questions

Practical knowledge for developers with hands-on experience.

01

What is a convolutional neural network (CNN)?

A Convolutional Neural Network (CNN) is a deep learning architecture designed for grid-like data such as images. It uses convolutional layers that apply learned filters across the input, detecting local patterns like edges and textures. Pooling layers downsample spatial dimensions, reducing computation and providing translation invariance. Multiple conv+pool blocks are followed by fully connected layers for classification. CNNs automatically learn hierarchical features: edges → textures → parts → objects. Landmark architectures: AlexNet, VGG, ResNet, InceptionNet, EfficientNet.

Open this question on its own page
02

What is a Recurrent Neural Network (RNN)?

An RNN is a neural network architecture designed for sequential data (time series, text, speech). Unlike feedforward networks, RNNs have recurrent connections — the hidden state at time t is a function of the current input and the previous hidden state, creating a form of memory. However, vanilla RNNs suffer from the vanishing gradient problem, making it hard to learn long-range dependencies. This is addressed by LSTM (Long Short-Term Memory) and GRU (Gated Recurrent Unit) architectures that use gating mechanisms to control information flow.

Open this question on its own page
03

What is an LSTM and how does it solve the vanishing gradient problem?

An LSTM (Long Short-Term Memory) network uses gating mechanisms to selectively remember or forget information over long sequences. It has three gates: the forget gate (decides what to erase from cell state), the input gate (decides what new information to add), and the output gate (decides what to output). The cell state acts as a highway that allows gradients to flow with minimal modification, addressing the vanishing gradient problem of vanilla RNNs. LSTMs are used in language modeling, machine translation, speech recognition, and time series forecasting.

Open this question on its own page
04

What is the attention mechanism in neural networks?

The attention mechanism allows a model to focus on the most relevant parts of the input when producing each output token, rather than compressing the entire input into a fixed-size vector. Given a query and a set of key-value pairs, attention computes a weighted sum of values, where weights are determined by the similarity between the query and each key. Self-attention computes attention between elements in the same sequence, enabling each position to attend to all other positions. Attention is the core building block of the Transformer architecture.

Open this question on its own page
05

What is the Transformer architecture?

The Transformer (introduced in "Attention Is All You Need", 2017) is an architecture based entirely on self-attention mechanisms, replacing recurrence and convolution. It consists of an encoder (maps input to context representations) and decoder (generates output). Each encoder/decoder block has multi-head self-attention and feed-forward layers with residual connections and layer normalization. Transformers process all tokens in parallel (unlike RNNs) and capture long-range dependencies efficiently. They are the foundation of BERT, GPT, T5, and virtually all modern NLP models.

Open this question on its own page
06

What is BERT and how is it pre-trained?

BERT (Bidirectional Encoder Representations from Transformers) is a pre-trained Transformer encoder model that learns deep bidirectional representations by conditioning on both left and right context simultaneously. Pre-training uses two tasks: Masked Language Modeling (MLM) — 15% of input tokens are masked and the model predicts them; and Next Sentence Prediction (NSP) — predicts whether two sentences are consecutive. After pre-training on large corpora, BERT is fine-tuned on specific NLP tasks (question answering, classification, NER) by adding a small task-specific head.

Open this question on its own page
07

What is GPT and how does it differ from BERT?

GPT (Generative Pre-trained Transformer) is a decoder-only Transformer pre-trained with autoregressive language modeling — predicting the next token given all previous tokens (left-to-right). BERT is an encoder-only model using bidirectional context (sees both left and right). GPT excels at generative tasks (text completion, summarization, code generation); BERT excels at discriminative tasks (classification, NER, QA). GPT-2, GPT-3, and GPT-4 scaled this architecture massively, showing emergent capabilities with scale.

Open this question on its own page
08

What is word embedding and what is Word2Vec?

Word embeddings are dense vector representations of words in a continuous vector space, where semantically similar words are close together. Unlike one-hot encoding (sparse, no semantic meaning), embeddings capture relationships: king - man + woman ≈ queen. Word2Vec (Google, 2013) learns embeddings using two architectures: CBOW (predicts a word from its context) and Skip-gram (predicts context from a word). Other popular embeddings: GloVe (uses global co-occurrence statistics) and FastText (uses character n-grams, handles unknown words).

Open this question on its own page
09

What is a Generative Adversarial Network (GAN)?

A GAN consists of two neural networks trained in a minimax game: the Generator (G) tries to create realistic fake data to fool the discriminator; the Discriminator (D) tries to distinguish real data from fake. G and D are trained alternately — as D gets better at detecting fakes, G improves at generating realistic samples. GANs can generate photorealistic images (StyleGAN), create deepfakes, perform image-to-image translation (Pix2Pix, CycleGAN), and super-resolution. Training challenges include mode collapse and training instability.

Open this question on its own page
10

What is reinforcement learning?

Reinforcement Learning (RL) is a paradigm where an agent learns to make decisions by interacting with an environment. At each step, the agent observes the state, takes an action, and receives a reward. The goal is to learn a policy (a mapping from states to actions) that maximizes cumulative reward. Key concepts: the exploration vs. exploitation tradeoff, Markov Decision Processes, Q-learning (value-based), and Policy Gradient methods. RL has achieved superhuman performance in games (AlphaGo, OpenAI Five) and is used in robotics, recommendation systems, and RLHF for LLM alignment.

Open this question on its own page
11

What is an autoencoder?

An autoencoder is an unsupervised neural network trained to reconstruct its input at the output. It has an encoder that compresses input to a lower-dimensional latent space (bottleneck), and a decoder that reconstructs the original input from the latent representation. The bottleneck forces the network to learn a compact representation capturing the most important information. Use cases: dimensionality reduction, anomaly detection (high reconstruction error = anomaly), denoising (trained to reconstruct clean input from noisy input), and generative modeling (Variational Autoencoders - VAEs).

Open this question on its own page
12

What is dropout regularization?

Dropout is a regularization technique for neural networks where, during training, each neuron is randomly deactivated (set to zero) with probability p (typically 0.2–0.5) at each forward pass. This prevents neurons from co-adapting too strongly and forces the network to learn redundant representations. It can be interpreted as training an ensemble of 2ⁿ different network architectures simultaneously. At inference time, dropout is disabled and weights are scaled by (1-p). Dropout is one of the most effective regularization techniques for large neural networks, introduced by Hinton et al. (2012).

Open this question on its own page
13

What is batch normalization?

Batch Normalization (BatchNorm) normalizes the activations of each layer to have zero mean and unit variance, computed over the mini-batch, then scales and shifts with learnable parameters γ and β. Benefits: accelerates training by allowing higher learning rates, reduces sensitivity to weight initialization, acts as a regularizer (reduces need for dropout), and mitigates the internal covariate shift problem (distribution of layer inputs changing during training). It is placed after the linear transformation and before the activation function in practice.

Open this question on its own page
14

What is gradient vanishing and exploding?

During backpropagation, gradients are multiplied together as they flow back through layers. In deep networks, if weights have values < 1, gradients become exponentially smaller (vanishing gradients) — early layers learn very slowly. If weights > 1, gradients explode (exploding gradients) — training becomes unstable. Solutions: better activation functions (ReLU instead of Sigmoid/Tanh), careful weight initialization (He init, Xavier init), batch normalization, residual connections (skip connections in ResNet), and gradient clipping for exploding gradients.

Open this question on its own page
15

What is an ensemble method?

Ensemble methods combine multiple models to produce a stronger predictor. Key techniques: Bagging (Bootstrap Aggregating) — train multiple models on bootstrap samples and average predictions (e.g., Random Forest); reduces variance. Boosting — train models sequentially, each correcting the errors of the previous (e.g., AdaBoost, Gradient Boosting, XGBoost); reduces bias and variance. Stacking — train multiple base models and a meta-model to combine their predictions. Ensembles consistently win data science competitions and are a reliable way to improve model performance.

Open this question on its own page
16

What is XGBoost and why is it popular?

XGBoost (Extreme Gradient Boosting) is an optimized gradient boosting framework known for speed, performance, and winning countless Kaggle competitions. It builds an ensemble of decision trees sequentially, with each tree correcting the residuals of the previous. Key advantages: regularization (L1/L2 built-in), sparsity-awareness (handles missing values natively), parallelized tree building, tree pruning (depth-first then prunes), and support for custom loss functions. It works excellently on structured/tabular data and is often the baseline before trying neural networks.

Open this question on its own page
17

What is natural language processing (NLP)?

Natural Language Processing (NLP) is the subfield of AI focused on enabling computers to understand, generate, and interact with human language. Core tasks: text classification (sentiment analysis, spam detection), named entity recognition (NER), machine translation, question answering, text summarization, information extraction, and speech recognition. Traditional NLP used bag-of-words and n-grams; modern NLP is dominated by Transformer-based pre-trained models (BERT, GPT, T5, LLaMA) that achieve human-level performance on many benchmarks.

Open this question on its own page
18

What is semantic segmentation vs object detection?

Object detection identifies the location (bounding boxes) and class of each object in an image. Models: YOLO (real-time), Faster R-CNN, SSD. Semantic segmentation assigns a class label to every pixel in the image but does not distinguish between instances of the same class (all cars are one "car" region). Instance segmentation (e.g., Mask R-CNN) combines both — it detects individual objects AND segments each at the pixel level. Panoptic segmentation is the most comprehensive, covering both "things" (countable objects) and "stuff" (background regions like sky, road).

Open this question on its own page
19

What is the difference between classification and clustering?

Classification is a supervised learning task — the model is trained on labeled data where each example has a known class, and it learns to assign classes to new examples. Clustering is an unsupervised learning task — the model discovers natural groupings in unlabeled data based on similarity, without any predefined class labels. In classification, the number and nature of classes is known in advance. In clustering, the number of groups may itself be a hyperparameter to determine. The same algorithm (e.g., neural network) can be adapted for both paradigms.

Open this question on its own page
20

What is the softmax function?

The softmax function converts a vector of raw scores (logits) into a probability distribution where all values are between 0 and 1 and sum to 1. For input vector z, softmax(zᵢ) = e^zᵢ / Σe^zⱼ. It amplifies differences between values — the largest logit gets the highest probability. Used in the output layer of multi-class classifiers, combined with categorical cross-entropy loss. The temperature parameter τ in softmax(z/τ) controls distribution sharpness: low τ → more peaked, high τ → more uniform (used in knowledge distillation and language model sampling).

Open this question on its own page
21

What is a ResNet (Residual Network)?

ResNet (He et al., 2015) introduced skip connections (residual connections) that bypass one or more layers: output = F(x) + x. This solves the degradation problem — adding more layers to very deep networks was causing performance to decrease. With skip connections, gradients can flow directly through the shortcut path, enabling training of networks with 50, 100, or even 1000+ layers. ResNet won the 2015 ImageNet competition and is still widely used today as a backbone for many vision tasks. Variants: ResNet-18, ResNet-50, ResNet-101, ResNeXt, Wide ResNet.

Open this question on its own page
22

What is fine-tuning a pre-trained model?

Fine-tuning is the process of taking a model pre-trained on a large dataset and continuing training on a smaller, task-specific dataset. Instead of training from scratch, you initialize the model with pre-trained weights (which encode general knowledge) and run a few more epochs with a low learning rate to adapt to the new task. Common strategies: full fine-tuning (update all weights), feature extraction (freeze pre-trained layers, only train the new head), and layer-wise learning rate decay (lower LR for earlier layers). For LLMs, LoRA (Low-Rank Adaptation) enables efficient fine-tuning with few trainable parameters.

Open this question on its own page
23

What is the difference between parametric and non-parametric models?

Parametric models have a fixed number of parameters regardless of training data size. After training, the data is no longer needed — the model is summarized by its parameters. Examples: linear regression, logistic regression, neural networks. They are faster at inference and require less memory but make stronger assumptions. Non-parametric models grow in complexity with the data — the "parameters" are effectively the training data itself. Examples: KNN, Kernel SVM, Gaussian Processes. They are more flexible and make fewer assumptions but require storing all training data and are slower at inference.

Open this question on its own page
24

What is DBSCAN clustering?

DBSCAN (Density-Based Spatial Clustering of Applications with Noise) clusters data based on density. It defines clusters as dense regions of points separated by low-density regions. Two hyperparameters: epsilon (ε) — the radius of a neighborhood, and min_samples — minimum number of points to form a dense region. Points are classified as core points, border points, or outliers (noise). Advantages over K-Means: discovers arbitrarily shaped clusters, automatically determines the number of clusters, and identifies outliers. It fails with clusters of varying density.

Open this question on its own page
25

What is class imbalance and how do you handle it?

Class imbalance occurs when one class has significantly more samples than others — common in fraud detection, medical diagnosis, and anomaly detection. Strategies: Resampling — over-sample the minority class (SMOTE creates synthetic examples) or under-sample the majority class. Class weights — give higher loss penalty to minority class mistakes. Threshold tuning — adjust the decision threshold for the positive class. Specialized metrics — use F1, AUC-PR (Precision-Recall AUC), or MCC instead of accuracy. Ensemble methods — BalancedRandomForest, EasyEnsemble.

Open this question on its own page
26

What is a recommendation system?

A recommendation system predicts user preferences to suggest relevant items. Main approaches: Collaborative Filtering (CF) — uses patterns from many users' behavior; user-based CF finds similar users, item-based CF finds similar items, Matrix Factorization (SVD, ALS) decomposes the user-item matrix. Content-Based Filtering — recommends items similar to what the user liked based on item features. Hybrid systems combine both. Deep learning-based systems use embeddings and two-tower models. Challenges: the cold start problem (new users/items), sparsity, and scalability.

Open this question on its own page
27

What is t-SNE?

t-SNE (t-distributed Stochastic Neighbor Embedding) is a non-linear dimensionality reduction technique used primarily for visualization of high-dimensional data in 2D or 3D. It models pairwise similarities between points in high-dimensional space using a Gaussian distribution, and in the low-dimensional space using a Student t-distribution (heavy tails prevent crowding). t-SNE preserves local structure and reveals clusters visually. Limitations: non-deterministic, computationally expensive for large datasets (O(n²)), hyperparameter-sensitive (perplexity matters), and distances between clusters are not meaningful. UMAP is a faster, more scalable alternative.

Open this question on its own page
28

What is the difference between discriminative and generative models?

Discriminative models learn the decision boundary between classes — they model P(y|x), the probability of the label given the input. Examples: logistic regression, SVM, neural network classifiers. They focus on what makes inputs different. Generative models learn the joint distribution P(x, y) or P(x) — they can generate new data points similar to the training data. Examples: Naive Bayes, GANs, VAEs, diffusion models. Discriminative models generally achieve better classification accuracy; generative models are richer (handle missing data, generate samples) but harder to train.

Open this question on its own page
29

What is Bayesian inference in machine learning?

Bayesian inference treats model parameters as random variables with prior distributions (beliefs before seeing data). After observing data, we update to the posterior distribution using Bayes' theorem: P(θ|data) ∝ P(data|θ) × P(θ). Instead of a single point estimate for parameters, Bayesian methods provide a full distribution, quantifying uncertainty. This is valuable in low-data regimes and for safety-critical applications where knowing model uncertainty matters. Challenges: computing the posterior is often intractable, requiring approximate methods like MCMC or Variational Inference.

Open this question on its own page
30

What is MLOps?

MLOps (Machine Learning Operations) is the practice of applying DevOps principles to the ML lifecycle to deploy and maintain ML models reliably and efficiently. It covers: experiment tracking (MLflow, Weights & Biases), data versioning (DVC), model versioning, CI/CD for ML (automated retraining pipelines), model serving (TorchServe, TF Serving, Triton), monitoring (detecting data drift, model degradation), and feature stores (Feast). MLOps bridges the gap between ML research and production deployment, addressing challenges like training-serving skew and concept drift.

Open this question on its own page
Advanced 16 questions

Deep expertise questions for senior and lead roles.

01

What is the Transformer self-attention mechanism in detail?

Self-attention computes attention within a single sequence. Each token is projected into three vectors: Query (Q), Key (K), and Value (V). Attention scores are computed as softmax(QKᵀ / √d_k) × V, where d_k is the key dimension (the scaling prevents vanishing gradients from large dot products). Multi-head attention runs h parallel attention functions with different learned projections, then concatenates and projects the results, allowing the model to attend to information from different representation subspaces simultaneously. This is why Transformers outperform RNNs on long sequences.

Open this question on its own page
02

What is RLHF (Reinforcement Learning from Human Feedback)?

RLHF is the technique used to align LLMs with human preferences. Phase 1: Supervised Fine-Tuning (SFT) — fine-tune on high-quality demonstrations. Phase 2: Reward Model Training — human annotators rank multiple model outputs; a reward model is trained to predict human preferences. Phase 3: RL Fine-Tuning — use Proximal Policy Optimization (PPO) to optimize the policy (the LLM) to maximize the reward model's score while penalizing deviation from the SFT model (KL divergence constraint). RLHF is central to ChatGPT, InstructGPT, and Claude's training.

Open this question on its own page
03

What is the difference between model parallelism and data parallelism?

Data parallelism splits the training data across multiple GPUs; each GPU holds a full copy of the model and processes a mini-batch. Gradients are aggregated across GPUs (all-reduce). Works well when the model fits on a single GPU. Model parallelism splits the model itself across multiple GPUs — different layers or parts of the model run on different devices. Needed when the model is too large for a single GPU. Tensor parallelism splits individual matrices across GPUs (used in Megatron-LM). Pipeline parallelism assigns sequential model stages to different GPUs. Modern LLM training uses 3D parallelism: data + tensor + pipeline in combination.

Open this question on its own page
04

What is a diffusion model?

A diffusion model is a generative model that learns to reverse a gradual noising process. The forward process progressively adds Gaussian noise to data over T timesteps until the signal is pure noise. The reverse process trains a neural network (typically a U-Net) to predict and remove the noise at each step, learning the score function ∇log p(x). At inference, you start from pure noise and iteratively denoise to generate samples. Diffusion models power Stable Diffusion, DALL-E 2, Imagen, and achieve state-of-the-art image generation quality, outperforming GANs in diversity and stability.

Open this question on its own page
05

What is LoRA (Low-Rank Adaptation)?

LoRA is a parameter-efficient fine-tuning (PEFT) technique that freezes the pre-trained model weights and injects trainable low-rank decomposition matrices into Transformer layers. Instead of updating the full weight matrix W ∈ ℝ^{d×k}, LoRA approximates the update as ΔW = BA where B ∈ ℝ^{d×r} and A ∈ ℝ^{r×k}, with rank r ≪ min(d,k). This reduces trainable parameters by orders of magnitude (e.g., 10,000× for large models) with minimal performance loss. LoRA is widely used for fine-tuning LLMs on consumer hardware. Variants: QLoRA (quantized LoRA), AdaLoRA (adaptive rank).

Open this question on its own page
06

What is knowledge distillation?

Knowledge distillation trains a small student model to mimic a large, pre-trained teacher model. Instead of training on hard labels (one-hot), the student learns from the teacher's soft labels (probability distributions over all classes), which contain richer information — the teacher's uncertainty and inter-class similarities. The student loss = αL_CE(hard labels) + (1-α)L_KL(soft labels). A temperature parameter T softens the teacher's distribution to amplify small probabilities. Applications: model compression (BERT → DistilBERT), on-device inference, and multi-teacher distillation for NLP.

Open this question on its own page
07

What is neural architecture search (NAS)?

Neural Architecture Search (NAS) automates the design of neural network architectures. Instead of hand-designing networks, NAS uses algorithms to search over a design space of possible architectures to find the optimal one for a given task and resource budget. Approaches: Reinforcement Learning (train an RL controller to generate architectures), Evolutionary algorithms, and Differentiable NAS (DARTS) (relaxes the discrete architecture space to be continuous, enabling gradient-based optimization). NAS discovered EfficientNet and NASNet architectures that outperformed hand-designed networks. Main challenge: computational cost.

Open this question on its own page
08

What is contrastive learning and what is SimCLR?

Contrastive learning is a self-supervised learning paradigm that trains representations by comparing similar and dissimilar pairs. The objective: push representations of similar samples (positive pairs) close together and push dissimilar samples (negative pairs) apart in embedding space. SimCLR creates positive pairs by applying two random augmentations to the same image and treats all other images in the batch as negatives. It uses a projection head (MLP) on top of the encoder during training (discarded at fine-tuning time). SimCLR achieves strong performance on downstream tasks without any labels. Related: MoCo, BYOL (no negative pairs), SimSiam.

Open this question on its own page
09

What is quantization in deep learning?

Quantization reduces the precision of model weights and/or activations from 32-bit floating point (FP32) to lower-precision formats (INT8, INT4, FP16). This reduces model size (4× for INT8 vs FP32) and speeds up inference significantly on hardware with integer arithmetic support. Post-Training Quantization (PTQ) quantizes a trained model with minimal calibration data. Quantization-Aware Training (QAT) simulates quantization during training, producing models that are more robust to precision reduction. GPTQ and bitsandbytes enable 4-bit quantization of LLMs for deployment on consumer GPUs.

Open this question on its own page
10

What is the concept of model interpretability and explainability?

Interpretability refers to how understandable a model's mechanics are to a human. Explainability refers to post-hoc methods to explain individual predictions. Key techniques: SHAP (SHapley Additive exPlanations) — assigns each feature a Shapley value representing its contribution to the prediction; model-agnostic and theoretically grounded. LIME (Local Interpretable Model-agnostic Explanations) — fits a simple linear model locally around a prediction. Grad-CAM — produces class activation maps for CNN predictions. Attention visualization — visualizes attention weights in Transformers. Interpretability is critical in healthcare, finance, and regulated industries.

Open this question on its own page
11

What is federated learning?

Federated learning trains ML models across decentralized devices (e.g., mobile phones) without sharing raw data. Each device trains locally on its data and sends only model updates (gradients) to a central server, which aggregates them (typically via FedAvg — federated averaging of weights). This preserves privacy since raw data never leaves the device. Challenges: non-IID data (each device has different data distributions), communication efficiency (compressing gradient updates), and security against adversarial clients. Used by Google for keyboard prediction (Gboard) and healthcare (training on hospital data without sharing patient records).

Open this question on its own page
12

What is concept drift and how is it handled?

Concept drift occurs when the statistical properties of the target variable (the concept being predicted) change over time, causing a deployed model to degrade. Types: Gradual drift (slow change over time), Sudden drift (abrupt change, e.g., COVID-19 changing user behavior), Recurring drift (cyclical patterns). Detection methods: monitoring model performance metrics, population stability index (PSI), ADWIN, and Page-Hinkley test. Mitigation: periodic retraining, sliding window approaches, ensemble methods that weight recent data, and continuous learning/online learning systems.

Open this question on its own page
13

What are graph neural networks (GNNs)?

Graph Neural Networks generalize neural networks to graph-structured data where nodes have features and edges represent relationships. They work via message passing: each node aggregates (e.g., sums or averages) feature vectors from its neighbors and updates its own representation. Multiple rounds of message passing allow nodes to incorporate information from multi-hop neighborhoods. Types: GCN (Graph Convolutional Networks), GraphSAGE, GAT (Graph Attention Networks). Applications: molecular property prediction (drug discovery), social network analysis, recommendation systems, and knowledge graph completion.

Open this question on its own page
14

What is the mixture of experts (MoE) architecture?

A Mixture of Experts (MoE) model consists of multiple "expert" sub-networks and a router (gating network) that selects which experts process each input token. Only a small subset of experts (e.g., 2 out of 64) are activated per token — this is conditional computation. MoE allows dramatic scaling of model capacity without proportional increases in computation. Switch Transformer (Google) demonstrated that sparse MoE Transformers can be more efficient than dense models. Mixtral 8x7B and rumored GPT-4 architecture use MoE. Challenges: load balancing (ensuring all experts are used), training instability, and communication overhead in distributed settings.

Open this question on its own page
15

What is position encoding in Transformers?

Unlike RNNs, Transformers process all tokens in parallel and have no inherent notion of position. Positional encoding injects position information into token embeddings. The original Transformer used fixed sinusoidal encodings of varying frequencies, allowing generalization to longer sequences. Learned absolute position embeddings (GPT-2, BERT) are trainable but do not generalize beyond training length. Relative position encodings (T5, Transformer-XL) encode relative distances between tokens. RoPE (Rotary Position Embedding) encodes positions by rotating query/key vectors — used in LLaMA, Mistral, and most modern LLMs for its ability to extrapolate to longer contexts.

Open this question on its own page
16

What is the role of the KV cache in LLM inference?

During autoregressive generation, each new token must attend to all previous tokens. Recomputing key (K) and value (V) matrices for all past tokens at each step would be O(n²) computation. The KV cache stores the K and V matrices of all previously processed tokens, so only the new token's K/V need to be computed at each step. This reduces generation from O(n²) to O(n). KV cache memory grows linearly with sequence length and batch size, and is a primary bottleneck for LLM serving. Techniques like multi-query attention (MQA), grouped-query attention (GQA), and PagedAttention (vLLM) reduce KV cache memory requirements.

Open this question on its own page
Back to All Topics 88 questions total