Skip to content

Interview Prep

AI & Machine Learning Interview Questions

The concepts behind machine learning and applied-AI interview questions, from fundamentals to building with LLMs.

10 of 10 AI & Machine Learning questions shown. Answers are hidden by default — try each one before revealing it.

  1. 1.A model is trained on a dataset of emails, each already labeled 'spam' or 'not spam', to predict the label for new emails. What type of learning is this?

    Easy

    Show answer and explanation

    Supervised learning trains on labeled examples, an input paired with the correct output, and learns to map new inputs to outputs, which is exactly this spam classifier setup. Unsupervised learning finds structure in unlabeled data, such as clustering similar emails without being told which are spam. Reinforcement learning learns from trial-and-error feedback (rewards or penalties) rather than a fixed labeled dataset. Self-supervised learning generates its own labels from the structure of the data itself, such as predicting a masked word, rather than using human-provided labels.

    machine-learningfundamentals

  2. 2.A model reaches 99% accuracy on its training data but only 60% on held-out test data. What does this most likely indicate?

    Easy

    Show answer and explanation

    A large gap between training and test performance, with training performance very high, is the classic signature of overfitting: the model has memorized noise and specifics of the training set rather than learning patterns that generalize. Underfitting would show poor performance on both training and test data. High bias also shows up as poor performance on both sets, since the model is too simple to capture the pattern even in training, which is the opposite of what is described here. A mislabeled test set is possible in principle but is not what this specific symptom points to.

    machine-learningoverfittingfundamentals

  3. 3.In machine learning, what is an embedding?

    Medium

    Show answer and explanation

    An embedding maps an object to a point in a continuous vector space, typically tens to thousands of dimensions, learned so that semantically similar inputs land near each other by some distance measure such as cosine similarity. That is what makes embeddings useful for search, recommendation, and clustering: 'find things similar to this' becomes 'find nearby vectors' rather than requiring exact keyword matches. It has nothing to do with backups, dictionary lookups, or encryption.

    embeddingsllmfundamentals

  4. 4.What problem does Retrieval-Augmented Generation (RAG) primarily address?

    Medium

    Show answer and explanation

    RAG addresses the fact that a model's knowledge is frozen at training time and limited to what fits in its context: it retrieves relevant passages from an external source, often via a vector database doing similarity search over embeddings, and feeds them into the prompt so the model can ground its answer in current, specific, or proprietary information it never saw during training. It does not change the model's weights, which describes fine-tuning rather than RAG, and it typically uses more tokens per request, not fewer, since retrieved context is added to the prompt. It also relies on something like a vector database rather than replacing one.

    ragllmapplied-ai

  5. 5.An LLM has a context window of 128,000 tokens. What does this number limit?

    Medium

    Show answer and explanation

    The context window is the maximum number of tokens, roughly word-fragments, a model can process at once, and it covers everything in that call combined: the system prompt, the conversation so far, any retrieved documents, and the response the model generates. Once a conversation exceeds it, earlier content has to be dropped or summarized for the model to keep working. It is unrelated to request rate limits, vocabulary size (a separate, usually much smaller, fixed count), or parameter count, which is a property of the model's size rather than a per-request limit.

    llmcontext-windowfundamentals

  6. 6.Explain what an embedding is and why it's useful.

    Medium
    Show model answer

    An embedding is a way of turning something that is not naturally a number, such as a word, a sentence, an image, or a product, into a vector: a list of numbers, usually somewhere between a few hundred and a few thousand of them. What makes it useful is not the conversion itself, it is how the vector space is organized: a good embedding model places semantically similar things near each other in that space and dissimilar things far apart, using a distance measure like cosine similarity. That property turns a fuzzy, human notion, such as 'these two things mean roughly the same thing', into a concrete computation: measure the distance between two vectors. That unlocks several practical uses. Semantic search: instead of matching exact keywords, you embed a query and find the nearest document vectors, which surfaces results that are conceptually related even if they do not share vocabulary. Recommendation: embed items and find others nearby. Clustering and deduplication: group similar items without predefined categories. And retrieval-augmented generation: embeddings are how a system finds which chunks of a knowledge base are relevant to a question before handing them to an LLM. Embeddings are typically produced by a model trained so that vector distance corresponds to real-world similarity. For text, models are often trained on tasks like predicting whether two passages appear near each other, so that meaning, not just shared words, drives closeness. The result is that a word like 'queen' ends up near 'king' and 'monarch' in vector space even though none of those words share letters.

    A strong answer touches

    • An embedding is a numeric vector representation of an object
    • The useful property is that similar things are close together in the vector space, by a distance metric like cosine similarity
    • This turns 'is this similar to that' into a computable distance, not a heuristic keyword match
    • Enables semantic search, recommendations, clustering, and retrieval for RAG
    • Embeddings are learned by models trained so vector distance tracks real semantic similarity

    This is one genuine answer, not the only correct one — compare it with your own reasoning rather than matching it word for word.

    embeddingsllmapplied-ai

  7. 7.What is RAG (Retrieval-Augmented Generation), and what problem does it solve?

    Medium
    Show model answer

    RAG is a pattern for building AI applications that combines a retrieval step with a generation step: before asking a language model to answer a question, the system first searches an external knowledge source, commonly a vector database of document embeddings but it can also be a search index, a database, or an API, for content relevant to the question, and inserts that content into the prompt as context. The model then generates its answer grounded in that retrieved material, rather than relying solely on what it learned during training. It solves a few concrete problems. First, a model's training data has a cutoff date and cannot know about anything that happened or changed afterward, so RAG lets it answer using current information without retraining. Second, a model has no visibility into private or proprietary data, such as a company's internal documents or a user's own files, unless that data is retrieved and handed to it at request time. Third, it reduces, though does not eliminate, hallucination: a model asked to answer from provided source text is more likely to stay grounded in that text than when generating purely from its own parameters, and a well-built RAG system can cite which source a claim came from, which makes answers checkable. The trade-offs are real: answer quality depends heavily on retrieval quality, since retrieving the wrong chunks leads the model to confidently answer from the wrong material; it adds latency and infrastructure, such as an embedding step, a vector store, and a retrieval step, compared to a direct prompt; and it consumes more tokens per request since retrieved passages are added to the prompt. RAG is not a substitute for fine-tuning when what is actually needed is a change in the model's behavior or style rather than its knowledge.

    A strong answer touches

    • RAG retrieves relevant external content and inserts it into the prompt before the model generates an answer
    • Solves the training-data cutoff problem by letting the model use current information
    • Solves the private or proprietary data problem, since the model can only use data it is given at request time
    • Reduces, but does not eliminate, hallucination and enables citing sources
    • Trade-offs: answer quality depends on retrieval quality, and it adds latency, infrastructure, and token usage

    This is one genuine answer, not the only correct one — compare it with your own reasoning rather than matching it word for word.

    ragllmapplied-ai

  8. 8.Explain overfitting, and describe one way to reduce it.

    Medium
    Show model answer

    Overfitting happens when a model learns the training data too specifically, including its noise, quirks, and coincidental patterns, rather than the underlying relationship that would generalize to new data. The telltale sign is a gap between training performance and performance on held-out data the model did not train on: training accuracy stays high or keeps improving while validation or test accuracy plateaus and then gets worse, because the model is increasingly fitting noise specific to the training examples rather than signal that transfers. It tends to happen when a model has more capacity, such as parameters, tree depth, or polynomial degree, than the amount and variety of training data can support, so the model has enough freedom to memorize rather than generalize. One common way to reduce it is regularization: adding a penalty for model complexity to the training objective so the model is discouraged from fitting noise just to shave a little more error off the training set. L2 regularization, also called weight decay, penalizes large weight values, which tends to produce smoother, less extreme functions. Other approaches include gathering more or more varied training data, which is harder to memorize than to learn from; dropout in neural networks, which randomly disables units during training so no single pathway becomes over-reliant on specific training examples; early stopping, which halts training once validation performance stops improving rather than continuing to drive down training error; and simply reducing model complexity to match what the data can support. In practice, teams use a validation set specifically to catch overfitting during training, since training metrics alone cannot reveal it.

    A strong answer touches

    • Overfitting means fitting noise or specifics of training data rather than the generalizable pattern
    • Diagnosed by a growing gap between training performance and held-out validation or test performance
    • Happens when model capacity exceeds what the data can support
    • Regularization, such as L2 or weight decay, penalizes complexity to reduce it
    • Other mitigations: more or varied data, dropout, early stopping, reducing model complexity
    • A validation set is what reveals overfitting; training metrics alone cannot

    This is one genuine answer, not the only correct one — compare it with your own reasoning rather than matching it word for word.

    machine-learningoverfittingfundamentals

  9. 9.What are the trade-offs of using a model with a much larger context window?

    Medium
    Show model answer

    A larger context window lets a model take more information into account in a single call, such as a longer document, more conversation history, or more retrieved passages in a RAG system, without having to summarize or truncate. That is a genuine capability gain: it can enable tasks that simply do not fit in a small window, like reasoning across an entire codebase or a long contract at once, and it reduces the engineering burden of carefully chunking and selecting what to include. But it comes with real costs. Cost and latency scale with the number of tokens processed, so a much larger prompt is slower and more expensive to run, whether or not the model actually needed all that context to answer well. There is also a well-documented effect sometimes called 'lost in the middle': models tend to pay more attention to information near the start and end of a long context and are more likely to miss or under-weight something buried in the middle, so simply having a bigger window does not guarantee the model will use everything in it equally well. A large context window can also encourage a lazier design, such as dumping in everything that might be relevant instead of retrieving only what is actually relevant, which can hurt both accuracy and cost even when the window technically has room. In practice, a large context window is a capability to use deliberately, not a default: it is often better to retrieve and include only the most relevant material, which is exactly what RAG is for, than to rely on the model to find a needle in a very large haystack, reserving the full window for cases that genuinely need it.

    A strong answer touches

    • Larger context windows allow more information per call without truncation or heavy summarization
    • Cost and latency scale with tokens processed, regardless of whether all the context was needed
    • Models do not attend uniformly across a long context; content in the middle can be under-weighted
    • A big window can encourage including everything rather than curating what is relevant, hurting accuracy
    • Deliberate retrieval of relevant content is often better than relying on a large window alone

    This is one genuine answer, not the only correct one — compare it with your own reasoning rather than matching it word for word.

    llmcontext-windowapplied-ai

  10. 10.When would you choose to fine-tune a model instead of improving your prompt or adding retrieval (RAG)?

    Hard
    Show model answer

    The three approaches solve different problems, and it helps to be clear about which one actually matches the gap you are seeing before reaching for the most expensive option. Prompt engineering, meaning rewriting instructions, adding few-shot examples, and being more specific about format and constraints, is the cheapest and fastest lever, and it solves problems where the model has the right knowledge and capability but is not being asked clearly enough, or is not shown the output format you want. It is almost always worth exhausting this first. RAG solves a knowledge problem: the model needs facts it does not have, such as private data, current information, or a large reference corpus, and cannot reasonably be expected to have memorized. It does not change how the model behaves or reasons, only what it has available to answer from. Fine-tuning solves a behavior problem: you need the model to reliably follow a specific style, format, or pattern that is hard to fully specify in a prompt, or to perform a narrow task more accurately or more cheaply, since a smaller fine-tuned model can sometimes match a larger general model on one specific task at lower cost and latency, or you have so many few-shot examples that they would bloat every prompt if included directly instead of being baked into the weights once. Fine-tuning is not a good way to teach a model new facts it should look up instead: it is expensive to update, since every new fact means retraining or re-running a fine-tune, and a model fine-tuned on facts will still hallucinate when asked about something outside that fine-tuning set, the same as a base model would. A reasonable default order is to try prompting first, add retrieval if the gap is missing knowledge, and reach for fine-tuning only if there is a persistent behavioral or formatting gap that prompting and examples cannot close, or a clear cost or latency reason to shrink to a specialized smaller model.

    A strong answer touches

    • Prompt engineering is the cheapest fix and solves clarity or instruction problems; try it first
    • RAG solves a knowledge gap: the model needs facts it does not have and cannot memorize
    • Fine-tuning solves a behavior gap: consistent style, format, or narrow-task performance that prompting cannot reliably achieve
    • Fine-tuning is a poor way to teach new facts; it is costly to update and the model can still hallucinate outside the fine-tuned scope
    • A reasonable default order is prompting, then retrieval, then fine-tuning

    This is one genuine answer, not the only correct one — compare it with your own reasoning rather than matching it word for word.

    fine-tuningragapplied-aillm

Put this into practice

Connect the idea to a worked lesson, a practical task or your interview preparation.

← All interview prep categories