Freshers

AI and ML Engineer | 52 questions | 2026

AI Engineer interview questions for freshers

Questions for freshers, interns and trainees, by topic. Tap a question to see the model answer.

Machine Learning

FresherMost asked
Answer

What is the difference between supervised and unsupervised learning?

Supervised learning trains on labeled data. Each input has a known target. The model learns to predict the target for new inputs. Unsupervised learning uses data with no labels. It finds patterns by itself.

  • Supervised: classification (spam or not spam) and regression (house price). Algorithms: linear and logistic regression, decision trees, SVM, neural networks.
  • Unsupervised: clustering (customer groups), dimensionality reduction (PCA), and anomaly detection. Algorithms: k-means, DBSCAN, PCA.
  • Semi-supervised and self-supervised sit in between. Semi-supervised uses a small labeled set plus lots of unlabeled data. Self-supervised makes labels from the data itself. This is how language models are pretrained.

The real difference is the cost of labels and how you check results. Supervised models have a clear score against the true answers. Unsupervised results need domain judgement or indirect (proxy) metrics.

What they are checking: Clear definitions with one example of each. Also that labels drive cost and how you evaluate.

FresherMost asked
Answer

Explain the bias-variance tradeoff.

Bias is error from assumptions that are too simple. It causes underfitting. Variance is error from being too sensitive to the training data. It causes overfitting. Expected test error is roughly bias squared plus variance plus irreducible noise.

  • High bias: the model is too simple. Error is high on both train and test data (a straight line on curved data).
  • High variance: the model memorizes noise. Train error is low but test error is much higher (a deep tree with no pruning).
  • Tradeoff: a more complex model lowers bias but raises variance. You look for the complexity where total error is lowest.

Ways to fix it: more data and regularization reduce variance. More features or a richer model reduce bias. Ensembles also help: bagging cuts variance and boosting cuts bias.

What they are checking: Whether you can link the idea to checking a model by its train and test error.

FresherMost asked
Answer

What is overfitting and how do you prevent it?

Overfitting is when a model learns the noise and odd details of the training set. It scores well on training data but poorly on new data.

Detect it with the gap between train and validation scores. A learning curve helps too. Validation error goes up while training error keeps going down.

Prevent it with:

  • More (or more varied) training data, and data augmentation
  • A simpler model, pruned trees, or fewer features
  • Regularization (L1, L2, dropout, weight decay)
  • Early stopping on a validation metric
  • Cross validation for honest model selection
  • Ensembling such as bagging

Fix the cause first. If there is data leakage or a tiny dataset, tuning hyperparameters will not help.

What they are checking: A way to find the problem first, then several fixes that match it. Not a memorized list.

FresherMost asked
Answer

What is the difference between L1 and L2 regularization?

Both add a penalty on the size of the weights to the loss. This discourages complex models.

L1 (Lasso)L2 (Ridge)
Penaltysum of absolute weightssum of squared weights
Effectsets some weights to exactly zero (sparse)shrinks all weights smoothly, rarely to zero
Usefeature selection, many useless featurescorrelated features, general shrinking

Elastic Net mixes both. The penalty strength is a hyperparameter. It is alpha in scikit-learn. In logistic regression, C is its inverse. Scale the features first, because the penalty depends on the size of the weights.

What they are checking: Whether you know why L1 gives sparse results (the geometry) and why you must scale features.

FresherMost asked
Answer

Why do we split data into training, validation and test sets?

Each set has its own job. This keeps the performance estimate honest.

  • Training set: fit the model parameters.
  • Validation set: choose hyperparameters and compare models. You look at it many times, so its score becomes a little too optimistic.
  • Test set: use it once at the end. It tells you the expected real-world performance.

Common splits are 70/15/15 or 80/10/10. With small data, use cross validation instead of a fixed validation set. Keep the time order for time series. Stratify for imbalanced classes. Split by group (user, patient) when rows from one entity are related. Otherwise leakage makes the scores too high.

What they are checking: Understanding of leakage and why the test set must stay untouched.

FresherMost asked
Answer

What is k-fold cross validation and when would you use it?

K-fold cross validation splits the data into k equal folds. The model trains k times. Each time, it trains on k-1 folds and validates on the one left out. The k scores are then averaged.

Use it when data is limited. It gives a more stable estimate than one split. It is also good for comparing models and tuning hyperparameters. Use StratifiedKFold for imbalanced classification. Use GroupKFold when rows share an entity. Use TimeSeriesSplit for time data. Never mix future data into the past.

from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LogisticRegression
scores = cross_val_score(LogisticRegression(max_iter=1000), X, y, cv=5, scoring='f1')
print(scores.mean(), scores.std())

The cost is k times the training time.

What they are checking: Knowing the variants for imbalance, groups and time. Not only the textbook definition.

FresherMost asked
Answer

Explain precision, recall and F1 score.

For a binary classifier, we count TP (true positives), FP (false positives) and FN (false negatives).

  • Precision = TP / (TP + FP): of the items predicted positive, how many were right.
  • Recall = TP / (TP + FN): of the real positives, how many did we find.
  • F1 = 2 * P * R / (P + R): the harmonic mean. It is low if either one is low.

Choose by the cost of each error. For a spam filter, precision matters (do not put real mail in spam). For cancer screening or fraud detection, recall matters (do not miss cases). Accuracy can mislead on imbalanced data. So report precision, recall and F1 per class. Change the decision threshold to trade one for the other.

What they are checking: Whether you link the metric to the business cost of false positives and false negatives.

FresherMost askedFree with sign-in
Answer

What is the difference between linear regression and logistic regression?

Linear regression predicts a continuous value. It uses a weighted sum of the features and is fit by minimizing squared error. Logistic regression predicts the probability of a class. It applies the sigmoid function to a linear combination of features. It is fit by minimizing log loss (cross-entropy).

FresherMost askedFree with sign-in
Answer

How does a decision tree work, and what are its weaknesses?

A decision tree splits the data again and again. At each step it picks the feature and threshold that best separate the target. For classification it uses a measure like Gini impurity or entropy. For regression it uses variance reduction. The leaves hold the prediction.

FresherMost askedFree with sign-in
Answer

How does gradient descent work, and what are its variants?

Gradient descent reduces a loss by moving the parameters in small steps against the gradient: w = w - lr * dL/dw.

FresherMost askedFree with sign-in
Answer

How does k-means clustering work and how do you choose k?

K-means splits the data into k clusters:

  1. Pick k starting centroids (k-means++ spreads them out).
  2. Assign each point to its nearest centroid.
  3. Recompute each centroid as the mean of its points.
  4. Repeat until the assignments stop changing.
FresherMost askedFree with sign-in
Answer

Explain how a neural network learns (forward pass, loss, backpropagation).

A neural network is made of layers. Each layer does a weighted sum and then a non-linear activation.

FresherMost askedFree with sign-in
Answer

Show how to train and evaluate a classifier with scikit-learn using a pipeline.

Put preprocessing and the model in one Pipeline. Then scaling is fit only on training data.

FresherMost askedFree with sign-in
Answer

How do you handle missing values and categorical features?

Missing values: first understand why they are missing. Your options:

  • Drop rows or columns if only a few are missing.
  • Fill in the mean or median (numeric) or the most frequent value (categorical).
  • Add a flag column that marks missing values.
  • Use models that handle NaN directly (histogram gradient boosting, XGBoost, LightGBM).
FresherMost askedFree with sign-in
Answer

What is PCA and when would you use it?

Principal Component Analysis (PCA) finds directions that are at right angles to each other and capture the most variance in the data. These are the principal components. You project onto the top components. This reduces the number of dimensions and keeps most of the information.

FresherMost askedFree with sign-in
Answer

How do you tune hyperparameters in scikit-learn?

Use a cross validated search over a grid or a distribution of parameters.

FresherMost askedFree with sign-in
Answer

What is feature scaling, and which models need it?

Feature scaling puts features on similar ranges. Standardization subtracts the mean and divides by the standard deviation. Min-max scaling maps values to a fixed range.

FresherMost askedFree with sign-in
Answer

What is feature engineering? Give examples.

Feature engineering means turning raw data into inputs that make patterns easier to learn. It often improves results more than switching algorithms.

FresherMost askedFree with sign-in
Answer

What does a confusion matrix show, and how do you read it?

A confusion matrix is a table of predicted classes against actual classes. For binary classification:

FresherMost askedFree with sign-in
Answer

Explain the difference between parameters and hyperparameters.

Parameters are learned from data during training. Examples are regression coefficients, neural network weights, and tree split points. Hyperparameters are set before training. They control how learning happens. Examples are learning rate, tree depth, number of trees, regularization strength, k in k-NN, and batch size.

FresherMost askedFree with sign-in
Answer

What is the difference between classification and regression, and between binary, multiclass and multilabel?

Classification predicts a discrete label. Regression predicts a continuous number.

FresherMost askedFree with sign-in
Answer

What is transfer learning and when is it useful?

Transfer learning reuses a model that was pretrained on a large dataset. It is the starting point for a related task. You can freeze the pretrained layers and train a new head (feature extraction). Or you can fine-tune some or all layers with a small learning rate.

FresherMost askedFree with sign-in
Answer

Write gradient descent for simple linear regression in Python.

Minimize mean squared error for y = w * x + b.

FresherMost askedFree with sign-in
Answer

When would you use mean absolute error versus mean squared error versus R squared?

  • MAE: the average absolute error. It is in the units of the target, handles outliers well, and is easy to explain.
  • MSE / RMSE: squares the errors, so large mistakes cost more. RMSE brings the value back to the target's units. Use it when big misses are especially costly.
  • R squared: the share of variance explained, compared with predicting the mean. It has no units. It can hide large errors. It also never goes down when you add features (use adjusted R squared).
FresherMost askedFree with sign-in
Answer

Why is a baseline model important, and how do you build one?

A baseline gives you a reference point. It shows whether a complex model adds real value. Without it, 85% accuracy could be worse than always predicting the majority class.

LLM and Generative AI

FresherMost asked
Answer

What is a large language model (LLM) and how does it work at a high level?

An LLM is a neural network, almost always a transformer. It is trained on huge amounts of text to predict the next token from the tokens before it. To do this well, it has to learn grammar, facts, reasoning patterns and code.

How it works:

  • Text is split into tokens, and tokens become embedding vectors (lists of numbers).
  • Stacked transformer layers use attention to mix information across positions.
  • The final layer gives a probability for every token in the vocabulary.
  • A sampling step picks the next token and adds it to the text. Then the process repeats. This is called autoregressive generation.

Training stages: first pretraining on raw text. Then instruction tuning and preference tuning (RLHF or similar), so the model follows instructions and behaves in a helpful and safe way.

What they are checking: A clear picture of next-token prediction and the training stages

FresherMost asked
Answer

Explain the transformer architecture and the attention mechanism.

A transformer reads a whole sequence in parallel using self-attention. It does not process one word at a time like older recurrent models.

In self-attention, each token is turned into a query (Q), a key (K) and a value (V). The score between two tokens is the dot product of Q and K. This score is divided by the square root of the key size. Then softmax turns the scores into weights. The output for a token is the weighted sum of all V vectors: softmax(QK^T / sqrt(d)) V. This lets each token pull in useful context from any position.

Multi-head attention runs several of these in parallel, so different heads can learn different relations. Each block also has a feed-forward network, residual connections and layer normalization. Attention ignores order, so position information (such as rotary embeddings) is added. Decoder-only LLMs use a causal mask. This means a token can only see earlier tokens.

What they are checking: Q, K, V idea and why transformers run in parallel better than RNNs

FresherMost asked
Answer

What are tokens, and why do they matter for cost and limits?

Tokens are the units a model reads and writes. A tokenizer (BPE, SentencePiece) splits text into small pieces of words. One token is about three quarters of an English word. Other languages and code often use many more tokens per word.

Tokens matter for three reasons:

  • The context window limit counts input plus output tokens.
  • Pricing is per input token and per output token.
  • Latency grows with output tokens, because they are made one at a time.

Measure with the provider's tokenizer or token-counting endpoint. Do not guess from the number of characters. To save cost, trim prompts, summarize history and do not send context you do not need.

What they are checking: Linking tokens to money, speed and limits

FresherMost asked
Answer

What is a context window, and how do you work around its limit?

The context window is the maximum number of tokens a model can look at in one request. It includes the prompt, the history, retrieved documents and the generated answer.

When the content does not fit:

  • Retrieval (RAG): fetch only the relevant chunks, not the whole corpus.
  • Summarization: compress older chat turns into a running summary.
  • Chunk and map-reduce: process pieces separately, then combine the results.
  • Prune: remove repeated setup text and duplicates.

Even with large windows, quality can drop for facts buried in the middle of a long prompt. Cost and latency also rise with length. So bigger is not always better.

What they are checking: Practical ways to handle the limit, not just a definition

FresherMost asked
Answer

What do temperature, top-p and top-k do?

These settings control how the next token is picked from the model's probabilities.

  • Temperature: divides the logits (raw scores) before softmax. A low value (near 0) makes the output focused and almost the same every time. A high value flattens the probabilities, so there is more variety and more risk.
  • Top-k: pick only from the k most likely tokens.
  • Top-p (nucleus): pick from the smallest set of tokens whose probabilities add up to p.

Guidance: use low temperature for extraction, classification, code and factual answers. Use a medium value for chat. Use a higher value for brainstorming and creative writing. Usually tune temperature or top-p, not both. Even at temperature 0, the output may differ between runs or model versions.

What they are checking: Understanding of sampling, with sensible defaults for each task

FresherMost asked
Answer

What are embeddings and how are they used?

An embedding is a dense vector of numbers that stands for the meaning of text (or an image, audio or code). Similar items sit close together in vector space. Similarity is measured with cosine similarity or dot product.

Uses:

  • Semantic search and RAG retrieval
  • Removing duplicates and clustering
  • Recommendations
  • Features for classification and anomaly detection
import numpy as np
def cosine(a, b):
    a, b = np.array(a), np.array(b)
    return float(a @ b / (np.linalg.norm(a) * np.linalg.norm(b)))

Use the same embedding model for documents and queries. Store the model name with the vectors. If you change models, embed everything again, because vectors from different models cannot be compared.

What they are checking: Practical uses and the same-model rule

FresherMost asked
Answer

Explain zero-shot, few-shot and chain-of-thought prompting.

  • Zero-shot: give only the instruction, with no examples. It works for common tasks.
  • Few-shot: put a few input and output examples in the prompt to show the format and style. Pick examples that are different from each other and typical.
  • Chain-of-thought (CoT): ask the model to think step by step before it answers. This helps on math, logic and multi-step tasks. Many new models have built-in reasoning modes, so explicit CoT matters less. You may not need to show the reasoning to users.

Other good habits:

  • Be specific about the role, task, limits and output format.
  • Mark instructions and data clearly with delimiters.
  • Ask for structured output (JSON).
  • Test prompts on a fixed evaluation set, not on one example.

What they are checking: Knowing when each technique helps

FresherMost asked
Answer

What is prompt engineering, and what makes a good prompt?

Prompt engineering means designing the instructions and context you give a model, so the output is reliable. A good prompt:

  • States the task and role clearly, and the audience
  • Gives context and limits (length, tone, allowed sources)
  • Says the output format (JSON schema, bullet list)
  • Includes examples for tricky formats
  • Tells the model what to do when unsure (say 'I don't know' instead of guessing)
  • Separates instructions from data with delimiters, which also lowers the risk of prompt injection

Treat prompts like code. Keep versions, test them on an evaluation set, and change one thing at a time.

What they are checking: Prompting that is planned and testable, not tricks

FresherMost askedFree with sign-in
Answer

What is hallucination in LLMs and how do you reduce it?

Hallucination is when a model gives fluent text that is false or has no support. For example, it may invent facts, citations or API names. It happens because the model predicts likely text, not checked truth.

FresherMost askedFree with sign-in
Answer

What does 'function calling' or 'tool use' mean for LLMs?

Tool use lets a model ask your code to run a function. You describe the available tools: name, description and a JSON schema for the arguments. When it helps, the model returns a structured tool call instead of text. Your application runs the tool and sends the result back. Then the model continues to the final answer.

FresherMost askedFree with sign-in
Answer

What is a vector database and why do LLM applications use one?

A vector database stores embeddings. It answers 'find the vectors nearest to this query vector' quickly. It uses approximate nearest neighbour indexes (HNSW, IVF). LLM applications use it to find text with a similar meaning, for RAG, memory and recommendations. Keyword search misses reworded text.

FresherMost askedFree with sign-in
Answer

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

A base model is only pretrained to continue text. If you ask it a question, it may just continue with more questions. An instruction-tuned (chat) model gets more training on instruction and response pairs. Then it is aligned with human or AI preference feedback (RLHF, DPO and similar). So it follows directions, answers helpfully and refuses harmful requests.

FresherMost askedFree with sign-in
Answer

What are system, user and assistant messages in a chat API?

  • System: sets the overall behaviour, role, rules and format for the chat. The developer controls it.
  • User: the input from the end user.
  • Assistant: the model's earlier replies (and tool call requests).
FresherMost askedFree with sign-in
Answer

What is the difference between generative AI and traditional machine learning?

Traditional (discriminative) ML maps inputs to labels or numbers, such as classification, regression and ranking. It is usually trained for one task on labeled data. Generative AI models learn the data distribution and make new content, such as text, images, code or audio. They usually start from a large pretrained foundation model. Then you adapt it with prompting, RAG or fine-tuning.

FresherMost askedFree with sign-in
Answer

What are multimodal models, and what are common use cases?

Multimodal models take in or produce more than text. This can be images, audio, video or documents. Example uses:

  • Getting data from invoices and screenshots
  • Describing images
  • Answering questions about charts
  • Speech transcription and voice assistants
  • Visual UI testing
FresherMost askedFree with sign-in
Answer

What is prompt caching?

Prompt caching lets a provider reuse the processed form of a long prompt prefix that does not change (system prompt, tool definitions, reference documents). Later calls start faster. The cached part costs less.

RAG and AI Agents

FresherMost asked
Answer

What is RAG (Retrieval-Augmented Generation) and why is it used?

RAG finds useful information in an outside knowledge source and adds it to the prompt. The LLM then answers using that information.

Flow has two parts.

  • Index: load documents, split them into chunks, embed the chunks, and store them in a vector index.
  • Query: embed the question and get the top chunks. Build a prompt with the chunks. Generate the answer, and optionally cite sources.

Why use it: the model gets current and private knowledge without retraining. Hallucinations (made-up answers) drop because answers can point to sources. You can apply access control at retrieval time. To update knowledge, you only re-index.

Limits: answer quality depends on retrieval quality. Context length and cost still apply.

What they are checking: Whether you understand the full flow and the reasons to choose RAG

FresherMost asked
Answer

Explain the stages of a RAG pipeline.

  1. Ingestion: load documents (PDF, HTML, databases), clean them and extract the text. Keep metadata (source, date, permissions).
  2. Chunking: split the text into passages of a good size.
  3. Embedding and indexing: turn chunks into vectors and store them in a vector database. Add a keyword index if you use hybrid search.
  4. Retrieval: embed the query and fetch the top-k candidates. You can also filter by metadata.
  5. Reranking: reorder the candidates with a stronger model.
  6. Augmentation: build the prompt with instructions and the best chunks.
  7. Generation: the LLM answers and cites sources.
  8. Evaluation and monitoring: track retrieval quality and answer quality.

Most RAG failures come from steps 1 to 5, not from the LLM.

What they are checking: Whether you can describe the whole pipeline and say where failures start

FresherMost asked
Answer

What is chunking in RAG and why does chunk size matter?

Chunking splits documents into small passages. Each passage is embedded and retrieved on its own.

  • Too small: a chunk loses its context. Retrieval returns fragments that cannot answer the question.
  • Too large: the embedding becomes blurry and noisy. You waste context tokens, and the useful details get buried.

A common start is a few hundred tokens with 10 to 20 percent overlap. Then tune it on your evaluation set. Overlap keeps ideas that sit across a boundary. Split on natural structure (headings, paragraphs, sentences) instead of fixed character counts. Store metadata such as title and section with each chunk.

What they are checking: Whether you know the trade-offs and can tune using retrieval metrics

FresherMost asked
Answer

What is an AI agent, and how is it different from a simple LLM call or a chain?

A simple LLM call maps a prompt to a response. A chain runs a fixed list of steps (for example retrieve, then summarize, then format). An agent lets the model decide what to do next in a loop. It can choose tools, look at the results, update its plan and continue until the task is done or a limit is reached.

Agents give more flexibility for open tasks (research, debugging, multi-step work). But they also add cost, delay, unpredictable results and risk. Prefer a simple workflow when the steps are known in advance. Use an agent only when the path really depends on earlier results.

What they are checking: Whether you can judge when an agent is needed

FresherMost askedFree with sign-in
Answer

What is the difference between semantic search and keyword search?

Keyword search (BM25, SQL LIKE, full-text) matches the actual words in the query. It is exact for specific terms but misses synonyms and paraphrases. Semantic search embeds the query and the documents and finds the closest meaning. So 'cheap flights' can match 'low-cost airfare'. But it can miss exact identifiers and rare terms.

FresherMost askedFree with sign-in
Answer

What distance or similarity metrics are used for vector search?

  • Cosine similarity: compares direction and ignores length. It is the common default for text embeddings.
  • Dot product: the same as cosine if the vectors are normalized (scaled to length 1), and it is faster. Use it if the model was trained for it.
  • Euclidean (L2) distance: straight-line distance.
FresherMost askedFree with sign-in
Answer

What is MCP (Model Context Protocol)?

MCP is an open protocol. It sets one standard way for AI applications to connect to outside tools and data. An MCP server offers tools, resources (data) and prompts. An MCP client lives inside the host application (an assistant, IDE or agent). The client finds the server's tools and calls them over a transport such as stdio or HTTP.

FresherMost askedFree with sign-in
Answer

What are LangChain and LlamaIndex, and when would you use them?

Both are frameworks for building LLM applications.

FresherMost askedFree with sign-in
Answer

Write minimal Python showing the core of a RAG query using embeddings and cosine similarity.

A small example with plain NumPy shows the idea. embed is any function that returns a vector from your embedding model.

FresherMost askedFree with sign-in
Answer

What does top-k mean in retrieval, and how do you choose k?

Top-k is the number of most similar chunks that the index returns for a query. A small k may miss the needed evidence (low recall). A large k adds noise, cost and delay, and can trigger the lost-in-the-middle effect.

FresherMost askedScenarioFree with sign-in
Answer

Live task: write a prompt for a ticket classification task, then implement it in Python so it runs with any LLM provider.

I would write the prompt first, with a clear role, the allowed labels, an output format and one example. Then I would wrap the model call in a small function, so the provider can be swapped.