This interview guide is for educational and informational purposes only. It is designed to help readers prepare, but it does not guarantee any interview result, hiring decision, offer, or outcome. Interview questions, hiring criteria, and preferred answers can vary by employer, interviewer, industry, location, and time. The examples and explanations reflect the authors' research and judgment, are provided without warranties of any kind, and should not be treated as the only correct approach. Diagrams are simplified illustrations intended to highlight the main components and their interactions; actual systems and implementations may be more complex. Alternative approaches may be equally valid or better suited to a particular question, context, or interviewer. To the fullest extent permitted by applicable law, the author, contributors, and publisher are not liable for decisions made, actions taken, or losses incurred based on this guide.
Identity, Image, and Privacy Notice
To respect individual privacy, some names, profile photographs, avatars, biographical details, and other identifying information displayed in this guide may be replaced with pseudonyms, licensed stock images, illustrative avatars, composite images, or representative descriptions. Unless a person is expressly identified as an actual contributor, a displayed name, image, or profile should not be understood as depicting or identifying a specific candidate, interviewer, employee, or other real individual. These representations are provided for editorial and illustrative purposes only and do not imply endorsement, employment, participation, or affiliation with this guide or any company mentioned in it. Any resemblance to an actual person is coincidental.
Company Notice
This guide is an independent educational resource and is not affiliated with, endorsed by, sponsored by, or approved by the company named in this guide. Company names are used only to identify interview experiences commonly reported by candidates. Interview practices can change without notice, and inclusion of company-specific content does not mean these questions are official, complete, or guaranteed to be asked. To the fullest extent permitted by law, the author, contributors, and publisher are not responsible for outcomes related to use of this material.
Questions or comments?
Contact us for general questions, or share feedback, technical corrections, and comments with the community.
Expected depth includes same-sequence Q/K/V interactions, masking, attention weights, and contextualized token representations.
Short Interview Answer (30-60 seconds)
Self attention lets each token build a new representation using relevant information from allowed tokens in the same sequence. Each token creates a query, key, and value. The query is compared with keys to get scores. A mask can block some positions. Softmax turns the allowed scores into attention weights, and those weights combine the values into a contextualized representation. In causal attention, future tokens receive zero attention weight.
Detailed Explanation
Self attention is a way for each piece of a sentence to use useful clues from other allowed pieces in the same sentence. For example, in "I love NLP !", the piece "love" can use the words around it to understand its role better. The system gives more importance to useful pieces and less importance to others. Some pieces can also be hidden from view. This is important when generating text because the current position must not use words that come later. The result is a richer meaning for every piece.
Useful Questions to Ask the Interviewer
Should I explain causal masking, where a position cannot use future tokens?
Would you like the matrix formula as well as the intuitive explanation?
How to Explain It in an Interview
Self attention starts with the representation of each token in one sequence. Learned linear projections create three vectors for every token: a query Q, a key K, and a value V. The query represents what the current token is looking for. The key represents what a token can match against. The value carries the information that may be passed forward.
For each token, its query is compared with the keys from tokens in the same sequence. The common scaled dot product score is QKᵀ divided by the square root of dₖ, where dₖ is the key vector size. Scaling keeps the scores from becoming too large before softmax.
A mask is applied when some positions must not be used. In causal attention, future positions are blocked. The mask contributes zero to allowed positions and negative infinity to blocked positions before softmax. As a result, blocked positions receive attention weight zero.
Softmax is applied across each row of scores. It converts the allowed scores into attention weights that sum to one. A larger weight means that position contributes more information to the current token.
The model then takes a weighted sum of the value vectors. This produces one contextualized representation for every input token. The sequence length stays the same, but each output representation now contains information gathered from relevant allowed tokens.
Self attention can connect tokens that are far apart in a sequence. Its main practical limitation is cost. The attention matrix grows with the square of the sequence length, so long sequences require more computation and memory.
Technical Approach
Start with the representation of every token in the same sequence.
Apply learned linear projections to create Q, K, and V for every token.
Compute scaled attention scores using QKᵀ divided by the square root of dₖ.
Add a mask when some positions must be blocked. For causal attention, future positions are blocked.
Apply softmax across each row. Allowed positions become attention weights that sum to one, while blocked positions receive weight zero.
Multiply the attention weights by V and sum the value vectors for each row.
Return one contextualized representation for every input token.
Practical Insights
For the attention score and weighted value steps in one attention head, n tokens with vector width d require O(n²d) computation. The attention matrix itself needs O(n²) memory. The learned Q, K, and V projections have their own linear algebra cost. The quadratic attention matrix is the main reason standard self attention becomes expensive for long sequences.
Why Interviewers Ask This
Interviewers ask this to check whether I understand a core Transformer mechanism. They want to see if I can explain how tokens exchange information through queries, keys, values, attention scores, masking, and weighted values. They also want to know whether I understand why causal masking matters and why standard attention becomes more expensive as a sequence grows.
Common interview mistakes
A common mistake is saying that self attention always lets every token use every other token. A mask may block some positions. Another mistake is saying that Q, K, and V come from different sequences. In self attention, they are created from representations of the same sequence. It is also wrong to treat attention weights as fixed values because they depend on the current representations and learned projections. Candidates may also forget that future positions receive zero weight after causal masking or ignore the quadratic growth of the attention matrix.
Interview tip
Explain the flow in order: create Q, K, and V, compare queries with keys, apply the mask, use softmax to get weights, and combine the values. Use the small "I love NLP !" example and mention that causal masking gives future positions zero attention weight.
Interviewer may ask next
What changes when causal masking is applied to self attention?
Causal masking blocks future token positions. The mask adds negative infinity to those score entries before softmax, so their final attention weight becomes zero. This matters during autoregressive generation because the current position must use only information that is already available. The tradeoff is that each position has less visible context than it would have with unrestricted attention.
Why can self attention become expensive for long sequences?
Standard self attention builds a score matrix between token positions. For n tokens, that matrix has n² entries. The score and weighted value steps therefore require about O(n²d) computation for vector width d, and the attention matrix needs O(n²) memory. This matters in production because longer sequences can increase latency and memory use substantially.
12. What is cross-attention?Llm FundamentalsEasy
i Question Details
Ground the definition in queries from one representation attending to keys and values from another representation and where this is used.
Short Interview Answer (30-60 seconds)
Cross attention lets one representation get information from another representation. The queries come from the representation that wants information, while the keys and values come from the representation that provides it. The model compares each query with the keys, converts those scores into weights, and uses the weights to combine the values. A common example is a decoder attending to encoder outputs during translation.
Detailed Explanation
Cross attention is a way for one group of information to look at another group and choose what is useful. Imagine translating a sentence. While producing the next word, one part needs to look back at the original sentence and focus on the most helpful pieces. It can give more importance to useful pieces and less importance to unrelated ones. The same idea can connect words with image information. The important point is that one side asks for information and a different side provides the information that may be useful.
Useful Questions to Ask the Interviewer
Do you want the explanation focused on encoder decoder models or also multimodal models?
Should I include the attention formula and tensor shapes?
How to Explain It in an Interview
Cross attention uses queries from one representation and keys and values from another representation. The query side is the asker. The key and value side is the provider.
For example, in an encoder decoder translation model, decoder hidden states produce the queries. Encoder outputs produce the keys and values. This lets the decoder read relevant parts of the encoded source sentence while generating the target sentence.
The model first creates Q, K, and V with learned linear projections. For each query, it compares that query with every key using a dot product. The scores are divided by the square root of the key dimension. Softmax then turns those scores into attention weights. For one query, those weights sum to one across the available key and value positions. The output for that query is the weighted sum of the values.
In matrix form, the core operation is softmax of Q times K transpose divided by the square root of d k, followed by multiplication by V. If there are n q query positions and n k key positions, the attention weight matrix has shape n q by n k. The output has one result for every query position and value dimension.
Cross attention is useful when information must move between different representations. Common examples include encoder decoder models and multimodal models where text queries attend to image features.
The main limitation is cost. Every query may compare with every allowed key, so longer query and key sequences require more computation and memory. A common mistake is confusing cross attention with self attention. In self attention, queries, keys, and values come from the same representation. In cross attention, the queries come from one representation while the keys and values come from another.
Technical Approach
Start with representation A, which needs information, and representation B, which provides information.
Project representation A into queries Q.
Project representation B into keys K and values V.
Compute a score for every query and key pair using Q times K transpose divided by the square root of d k.
Apply softmax across the key positions for each query. This creates attention weights.
Multiply the attention weights by V. This produces one weighted value result for each query position.
Pass the cross attention output to the next model operation, such as the rest of a decoder block.
Practical Insights
For n q query positions, n k key positions, key dimension d k, and value dimension d v, computing the attention scores takes work proportional to n q times n k times d k. Combining the attention weights with the values takes work proportional to n q times n k times d v. The attention weight matrix uses memory proportional to n q times n k. This is why long query and key sequences can be expensive.
Why Interviewers Ask This
Interviewers ask this to check whether a candidate understands how one set of model states can read useful information from another set. They want to see whether the candidate can distinguish cross attention from self attention, explain the direction of information flow, and connect the mechanism to encoder decoder and multimodal models.
Common interview mistakes
A common mistake is saying that Q, K, and V always come from the same representation. That describes self attention, not cross attention. Another mistake is treating the attention scores as the final output. The scores are first converted into weights with softmax, and those weights are then used to combine V. Candidates may also forget that every query can compare with every allowed key, which affects computation and memory as the two sequence lengths grow.
Interview tip
Start with the source rule: queries come from one representation, while keys and values come from another. Then explain the score, softmax, and weighted value flow. Finish with one concrete example such as decoder queries attending to encoder outputs.
Interviewer may ask next
What happens if the query sequence and key value sequence have different lengths?
That is valid and is common in cross attention. If Q has n q positions and K and V have n k positions, the attention score and weight matrices have shape n q by n k. Each query can still attend across the available key and value positions. The output has n q positions because there is one result for each query. This matters because the two representations do not need to contain the same number of tokens or features.
What is the main performance cost of cross attention with long sequences?
The main cost comes from comparing every query with every key. With n q queries and n k keys, the attention matrix contains n q times n k entries. Computing the scores and combining the values therefore grows with both sequence lengths, and storing the attention weights also uses memory proportional to n q times n k. The tradeoff is that every query gets direct access to information across the other representation, but the operation becomes more expensive as either side grows.
13. What is causal masking?Llm FundamentalsEasy
i Question Details
Define the concept through the triangular visibility constraint, prevention of future-token leakage, and its role during autoregressive training and decoding.
Short Interview Answer (30-60 seconds)
Causal masking makes each token position look only at itself and earlier positions. In self attention, positions to the right are blocked, which creates a lower triangular visibility pattern. This prevents future token leakage during autoregressive training and matches decoding, where the model generates each new token from the tokens already available.
Detailed Explanation
Causal masking is a rule that stops one word position from looking ahead at words that come later. Imagine the sentence "The cat sat on the mat." When working at "sat," the system may use "The," "cat," and "sat," but it must not use "on," "the," or "mat." This matters because it should learn what comes next without secretly seeing future words. The same rule matches generation, because words that have not been produced yet are not available to use.
Useful Questions to Ask the Interviewer
Should I explain both training and decoding?
Would you like me to show the triangular visibility pattern?
How to Explain It in an Interview
Causal masking is used inside self attention. Self attention lets one token position use information from other token positions. The causal mask limits which positions are visible.
For a query at position i, only key and value positions j where j is less than or equal to i are visible. Positions where j is greater than i are blocked. If you draw this rule as a matrix, the allowed cells form a lower triangular shape. The diagonal is allowed because a position may see itself.
The mask is applied to attention scores before softmax. Softmax is the step that turns the usable scores into attention probabilities. Scores for future positions are blocked, so those positions receive no attention probability. This prevents future token leakage.
During autoregressive training, the model can process many sequence positions together, but every position still follows the same visibility rule. The representation at position i uses only tokens from the start of the sequence through position i. Its output is then used to predict the following token. This lets training use complete sequences without allowing a position to see future answers.
During autoregressive decoding, the same rule matches generation. At each step, the model has only the prompt and tokens generated so far. It predicts one new token, adds that token to the sequence, and repeats. A KV cache may store earlier key and value states to reduce repeated computation, but it does not change the causal visibility rule.
The main limitation is that causal masking is intentionally one directional. It is correct for next token generation, but it is not the right attention pattern when every position should use both earlier and later context.
Technical Approach
Take a sequence of token positions in order.
For query position i, allow attention only to key and value positions j where j is less than or equal to i.
Block every position where j is greater than i before softmax.
The allowed cells form a lower triangular visibility pattern.
During autoregressive training, the representation at each position uses only itself and earlier tokens and is used to predict the following token.
During autoregressive decoding, generate one token from the available prefix, append it, and repeat with the same causal rule.
Why Interviewers Ask This
Interviewers ask this to check whether you understand how a language model prevents information from future positions from leaking into the current position. They also want to see whether you can connect the triangular visibility rule inside attention with both autoregressive training and step by step decoding.
Common interview mistakes
A common mistake is saying that causal masking lets a token see only earlier positions and not itself. The diagonal is normally visible, so the current position is included. Another mistake is thinking the mask is only a decoding feature. It is also essential during autoregressive training because it prevents future token leakage when many positions are processed together. A third mistake is confusing causal masking with a KV cache. The mask controls visibility, while the cache stores earlier key and value states to reduce repeated computation during decoding.
Interview tip
Start with the rule that position i can see only positions up to and including i. Then describe the lower triangular mask. Finish by connecting the same rule to prevention of future token leakage during training and step by step generation during decoding.
Interviewer may ask next
What would happen if the causal mask were removed during autoregressive training?
Future token leakage would occur. A position could attend to tokens that come later in the training sequence, including information related to the token it is supposed to predict next. Training would no longer match real decoding, because those future tokens are unavailable during generation. This matters because the model could learn from information that it will not have when it is actually generating text.
How does a KV cache relate to causal masking during decoding?
A KV cache changes efficiency, not visibility. It stores key and value states from earlier tokens so the model does not recompute those states at every decoding step. Causal masking still controls which token positions the current position may attend to. The benefit is less repeated computation during generation, while the main tradeoff is extra memory use for the cached states.
14. What is multi-head attention?Llm FundamentalsEasy
i Question Details
Clarify the relationships among parallel projection subspaces, head concatenation, specialization, and the capacity-versus-cost tradeoff.
Short Interview Answer (30-60 seconds)
Multi head attention lets a Transformer run multiple attention operations in parallel. Each attention head learns its own projection subspace and can capture different token relationships. The outputs from all heads are concatenated and passed through an output projection. We use multiple heads because they provide richer representations, but increasing the number of heads also increases computation and memory cost.
Detailed Explanation
Multi head attention is a method that helps a model understand relationships between words or tokens in a sequence. Instead of looking at the sequence in only one way, the model creates several attention views and combines them. Each view can focus on different patterns in the input.
Useful Questions to Ask the Interviewer
Are we discussing encoder self attention, decoder self attention, or cross attention?
Should I focus more on the architecture explanation or production tradeoffs?
How to Explain It in an Interview
Multi head attention is a core part of Transformer models. The input embeddings are projected into query, key, and value representations for each attention head. Each head performs scaled dot product attention independently. The attention scores determine how much information each token receives from other tokens.
Each head works in a learned projection subspace. This means different heads can capture different relationships or patterns in the sequence. For example, one head may capture nearby token relationships while another may capture longer range dependencies. The model does not manually assign these roles. They are learned during training.
After each head produces an output, the outputs are concatenated. The combined representation is passed through a final linear projection to return to the model dimension.
The main benefit of multiple heads is that the model can learn several views of the same input at the same time. This increases the expressive power of the Transformer. The main tradeoff is cost. More heads require more attention calculations and more memory. In production systems, engineers balance representation quality with latency, memory usage, and serving cost.
Why Interviewers Ask This
Interviewers ask this question to evaluate whether a candidate understands how Transformer models process token relationships. It tests knowledge of attention mechanisms, model architecture, and practical judgment about capacity, computation, and memory tradeoffs.
Common interview mistakes
A common mistake is saying that every attention head has one fixed purpose. Heads can learn different patterns, but their exact specialization is not guaranteed. Another mistake is ignoring the cost tradeoff. More heads can improve model capacity, but they also increase computation and memory requirements.
Interview tip
Start with the main reason: multiple heads allow the Transformer to capture different relationships in parallel. Then explain projections, attention calculation, concatenation, and the capacity versus cost tradeoff.
Interviewer may ask next
Do attention heads always learn fixed roles such as grammar or position?
No. Attention heads do not have guaranteed fixed roles. Each head learns a projection subspace during training and may capture different useful patterns. This matters because engineers should describe heads as learned specializations rather than manually assigned components.
What happens when we increase the number of attention heads?
Increasing the number of heads can provide more ways to represent token relationships, but it also increases computation and memory usage. The tradeoff is higher representation capacity versus higher serving cost and latency.
15. What is a feed-forward network in an LLM?Llm FundamentalsEasy
i Question Details
Ground the definition in the per-token nonlinear transformation, expansion and contraction dimensions, activation, and its placement inside a Transformer block.
Short Interview Answer (30-60 seconds)
Feed Forward Networks are the per token transformation layers inside a Transformer block. They take each token representation, expand it to a larger hidden dimension, apply a nonlinear activation such as GELU, and contract it back. The FFN adds learning capacity after self attention has mixed information between tokens.
Detailed Explanation
A Feed Forward Network in an LLM changes the representation of each token. It helps the model learn more complex patterns after information from other tokens has been combined.
Useful Questions to Ask the Interviewer
Are you asking about the standard FFN structure inside a Transformer block?
Should I focus more on the mathematical flow or production impact?
How to Explain It in an Interview
A Feed Forward Network, also called FFN, is a position wise neural network inside each Transformer block. Position wise means the same FFN weights are applied separately to every token position.
A Transformer block usually has self attention and then an FFN. Self attention allows tokens to share information with other tokens. The FFN then transforms the features of each token independently.
The FFN has three main steps. First, a linear layer expands the token representation from the model dimension to a larger intermediate dimension. Second, an activation function such as GELU adds nonlinear behavior. Third, another linear layer contracts the representation back to the original model dimension.
For example, a model can transform a token vector from 4096 dimensions to 11008 dimensions, apply GELU, and return to 4096 dimensions. Exact values depend on the model design.
The expansion gives the network more space to learn useful intermediate features. The activation allows the model to represent complex relationships that a simple linear transformation cannot capture.
In production, FFN layers contain many parameters and require significant compute and memory. Larger FFN sizes can increase model capacity but also increase inference cost.
A common mistake is saying the FFN mixes tokens. Self attention performs token mixing. The FFN mainly changes each token representation independently.
Why Interviewers Ask This
This question evaluates whether the candidate understands the internal structure of a Transformer block. It checks knowledge of how LLMs transform token representations, how nonlinear layers add model capacity, and how to explain model behavior clearly.
Common interview mistakes
Common mistakes include confusing FFN with self attention, saying FFN stores memories, or saying FFN only increases dimensions. The FFN transforms each token representation independently while attention handles information exchange between tokens.
Interview tip
Start with the main conclusion that FFN is the per token nonlinear transformation inside a Transformer block. Then explain the flow: expand, activate, contract. Mention that attention mixes tokens while FFN transforms features.
Interviewer may ask next
Does a Feed Forward Network process tokens together or separately?
A Feed Forward Network processes each token separately using the same weights. This is called position wise processing. It matters because self attention handles communication between tokens, while the FFN transforms each token representation independently.
Why does the FFN expand the hidden dimension before contracting it?
The FFN expands the hidden dimension to create a larger space for learning intermediate features. The activation adds nonlinear behavior before the representation returns to its original size. The tradeoff is higher model capacity with increased compute and memory cost.
16. What are residual connections?Llm FundamentalsEasy
i Question Details
Ground the definition in residual addition, gradient flow, representation preservation, and pre-norm versus post-norm placement.
Short Interview Answer (30-60 seconds)
Skip connections, also called residual connections, add the input of a Transformer sublayer back to the sublayer output. The model learns the change, called the residual, instead of learning a completely new representation. This creates a shorter path for information and gradients, which helps deep Transformers train more reliably and preserve useful representations.
Detailed Explanation
Skip connections help a Transformer keep useful information while adding new changes. A sublayer such as self attention or a feed forward network receives an input and creates an update. The original input is added back to this update so important information can continue through the model.
Useful Questions to Ask the Interviewer
Are we discussing the original Post Norm Transformer design or a modern Pre Norm LLM design?
Should I focus more on training stability, gradient flow, or Transformer block implementation details?
How to Explain It in an Interview
A Transformer block contains sublayers such as self attention and feed forward networks. Each sublayer produces a new representation from its input. A residual connection adds the original representation back to the sublayer result using element wise addition.
The basic idea is:
Output = Input + Sublayer(Input)
The sublayer learns the useful change from the current representation instead of rebuilding the entire representation. This is called learning a residual.
Residual connections matter because they create shorter paths for gradients during training. Without these paths, very deep networks can become harder to optimize because training signals must pass through many layers. The shortcut path helps gradients move through the network more effectively.
They also help preserve representations. Information that is already useful can pass through the shortcut while the sublayer adds refinements. This allows Transformers to use many layers while maintaining stable information flow.
LayerNorm placement changes the Transformer block design. In Post Norm Transformers, the sublayer output is added to the input and LayerNorm is applied after the residual addition. In Pre Norm Transformers, LayerNorm is applied before the sublayer and the residual addition happens afterward. Modern large language models commonly use Pre Norm because it generally provides more stable training for deep models.
Residual connections do not guarantee that every model will train successfully. They are one architectural mechanism that improves optimization, supports gradient flow, and enables deeper Transformer networks.
Why Interviewers Ask This
Interviewers ask this question to evaluate whether a candidate understands the internal design of Transformer blocks. They want to know if the candidate understands how residual addition helps information flow, how gradients move through deep models, and why normalization placement matters in modern LLM architectures.
Common interview mistakes
Common mistakes include confusing residual connections with attention mechanisms. Residual connections do not retrieve information or create attention scores. They only add the original input back to the sublayer output. Another mistake is saying residual connections completely remove gradient problems. They improve gradient flow but do not guarantee perfect training. Candidates also often confuse Pre Norm and Post Norm placement.
Interview tip
Start with the main idea that residual connections add the input back to the sublayer output. Then explain why they matter: they provide shorter gradient paths, preserve useful representations, and make deep Transformer training more stable. Mention Pre Norm and Post Norm as important design choices.
Interviewer may ask next
What is the difference between Pre Norm and Post Norm residual connections in Transformers?
Pre Norm applies LayerNorm before the sublayer and then performs residual addition. The flow is LayerNorm, sublayer, then add the original input. Post Norm performs the sublayer operation, adds the residual input, and then applies LayerNorm. Pre Norm is commonly used in modern deep LLMs because it usually provides more stable optimization. The tradeoff is that changing normalization placement changes the training behavior and Transformer block structure.
Do residual connections completely solve gradient problems in deep Transformers?
No. Residual connections create shorter paths for gradients and reduce optimization difficulty, but they do not remove all training challenges. Deep Transformers can still depend on other design choices such as normalization, optimization settings, and architecture decisions. The main benefit is improved stability and easier training rather than a guarantee of perfect gradients.
17. What is a context window?Llm FundamentalsEasy
i Question Details
Require a mechanism-level account of the shared input-and-output token budget, truncation and context-selection policy, cost implications, and failure modes when relevant evidence falls outside the window.
Short Interview Answer (30-60 seconds)
The context window is the maximum number of tokens an LLM can process in one request. It contains both input tokens and generated output tokens. It matters because the model can only use information inside this window, so AI systems must select useful context to balance answer quality, cost, and latency.
Detailed Explanation
The context window is the amount of information an LLM can use during one request. A request can include instructions, conversation history, selected document information, and a user question. The input and output share the same token budget.
Useful Questions to Ask the Interviewer
Should the explanation focus on the model limit or the application design used to manage long context?
Does the system need to handle long conversations or large documents?
How to Explain It in an Interview
A context window is a shared token budget that limits what an LLM can see during inference. Tokens are small pieces of text processed by the model. The input tokens and output tokens use the same limit. If the input uses more tokens, fewer tokens remain for the generated answer.
When an application prepares a request, it chooses what information should enter the context window. It usually keeps important instructions, recent conversation, and relevant retrieved information. When the content is too large, the system can remove older content, summarize information, or select the most useful parts.
This matters because the model cannot use information outside the current context window. If important evidence is removed, answers may become incomplete or incorrect. A good context selection policy helps the model receive the information needed for the task.
A larger context window can increase processing cost and latency because the model handles more tokens. Production systems balance accuracy, cost, and speed by controlling which information is included.
Why Interviewers Ask This
Interviewers ask this question to evaluate whether the candidate understands how an LLM receives information during inference. It tests knowledge of token limits, context selection, production tradeoffs, and failure cases caused by missing information.
Common interview mistakes
A common mistake is thinking an LLM automatically remembers all previous conversations. The model only uses information inside the current context window unless an external system provides memory. Another mistake is assuming a larger context window always gives better results. More tokens can increase cost and latency, and unnecessary information can reduce answer quality.
Interview tip
Start with the practical definition: a context window is a shared token budget for input and output. Then explain context selection, what happens when the limit is reached, and why this affects cost and reliability.
Interviewer may ask next
What happens when important information falls outside the LLM context window?
The model cannot access information that is outside the current context window. The application must remove, summarize, or select information before sending the request. This matters because missing evidence can cause incomplete or incorrect answers. The tradeoff is between keeping more information and controlling token usage, cost, and latency.
Does a larger context window always improve an AI application?
No. A larger context window allows more information to be included, but it can increase processing cost and latency. Production systems still need context selection because the most relevant information is usually more useful than sending all available information.
18. What are logits?Llm FundamentalsEasy
i Question Details
The explanation should make unnormalized token scores, softmax conversion, sampling controls, and how logits drive decoding explicit.
Short Interview Answer (30-60 seconds)
Logits are the raw unnormalized scores an LLM produces for every possible next token. The model converts these scores into probabilities using softmax, then decoding controls such as temperature, top k, and top p influence how the next token is selected. The selected token is added back to the context, and the process repeats to generate text.
Detailed Explanation
Logits are numbers produced by an AI model to rank possible next tokens. They show how strongly the model prefers each possible token, but they are not probabilities yet. A larger logit means the model gives that token a higher score compared with other choices.
Useful Questions to Ask the Interviewer
Should I focus on greedy decoding or sampling based decoding for this explanation?
Should I include production decoding controls such as temperature, top k, and top p?
How to Explain It in an Interview
When an LLM generates text, it starts with the current context, such as "The cat". The model produces one logit score for every token in its vocabulary. These scores are unnormalized, which means they cannot be directly interpreted as probabilities.
The logits go through softmax. Softmax converts the scores into probabilities that add up to one. The system can then use decoding methods to choose the next token. Greedy decoding selects the token with the highest probability. Sampling methods choose from the probability distribution to create more variation.
Temperature changes how focused the probability distribution is. A lower temperature makes the output more predictable because high probability tokens become more likely. A higher temperature allows more variation. Top k sampling keeps only a fixed number of highest probability tokens before selecting. Top p sampling keeps the smallest group of tokens whose combined probability reaches a chosen threshold.
After a token is selected, the system appends it to the context and runs the model again. This continues until a stopping condition is reached. Logits are important because they connect the model output to the final generated text.
In production systems, engineers choose decoding settings based on the required balance between consistency, creativity, quality, and user experience. Logits do not contain final answers and do not guarantee that the selected token is correct. They only provide the scores used during decoding.
Why Interviewers Ask This
Interviewers ask this question to check whether a candidate understands the connection between LLM model output and generated text. They evaluate whether the candidate understands raw token scores, probability conversion, decoding choices, and practical inference behavior.
Common interview mistakes
Common mistakes include saying logits are probabilities, skipping the softmax conversion step, or saying the model directly creates the final text. Logits are only raw scores. Another mistake is assuming temperature changes the model knowledge. Temperature only changes how the probability distribution is used during decoding. Engineers should also understand that decoding settings change output behavior but do not retrain the model.
Interview tip
Explain the complete flow in order: input context, logits, softmax probabilities, decoding controls, next token selection, and repeat. Use the example "The cat" to make the process easy to understand.
Interviewer may ask next
What happens when several tokens have similar logits?
When several tokens have similar logits, the model has uncertainty because multiple tokens receive similar scores. Softmax creates a probability distribution where several choices may have meaningful probability. Sampling controls such as temperature, top k, and top p affect how much variation appears in the generated text. The tradeoff is between more diverse output and more predictable output.
Why would a production system use sampling instead of always selecting the highest probability token?
A production system uses sampling when it needs more natural variation in generated text. Greedy decoding always chooses the highest probability token, which is consistent but can produce repetitive responses. Sampling uses the probability distribution created from logits to allow alternative choices. The tradeoff is that more diversity can reduce consistency.
19. What is temperature in an LLM?Llm FundamentalsEasy
i Question Details
Require a mechanism-level account of logit rescaling, entropy of the sampling distribution, determinism, and quality-versus-diversity behavior.
Short Interview Answer (30-60 seconds)
Temperature controls how random an LLM's output is during generation. It changes token probabilities by rescaling logits before softmax. Lower temperature makes the output more focused and predictable, while higher temperature makes the output more diverse and creative. I use lower temperature for tasks that need consistency and higher temperature for tasks that need exploration.
Detailed Explanation
Temperature is a setting that controls how an LLM selects the next token when generating text. It changes whether the model prefers the most likely choices or explores more possible choices.
Useful Questions to Ask the Interviewer
What type of application is this model being used for, such as factual answers, coding, or creative generation?
Are other decoding settings like top p or top k used together with temperature?
How to Explain It in an Interview
An LLM first produces logits. Logits are raw scores that represent how likely each possible next token is before probabilities are created. Temperature changes these scores before softmax converts them into a probability distribution.
The rescaling step is:
z_i(T) = z_i / T
When temperature is below 1, the difference between token scores becomes larger. The probability distribution becomes sharper, so the model is more likely to select high probability tokens. This lowers entropy, which means less randomness and more predictable output.
When temperature is around 1, the original distribution is mostly maintained. This often gives a balance between output quality and diversity.
When temperature is above 1, token score differences become smaller. The distribution becomes flatter, which increases entropy and allows lower probability tokens to be selected more often. This creates more diverse responses but increases the chance of off topic or lower quality output.
Temperature does not change what the model learned. It only changes how the model samples during inference. Lower temperature is useful for factual answers, extraction, and consistent formatting. Higher temperature is useful for brainstorming and creative tasks. A common mistake is thinking temperature improves model knowledge. It only changes the selection behavior among available token choices.
Why Interviewers Ask This
Interviewers ask this question to evaluate whether a candidate understands LLM inference behavior. It tests knowledge of decoding, probability distributions, randomness control, and the production tradeoffs of choosing different generation settings.
Common interview mistakes
Common mistakes include thinking temperature changes the model's knowledge, training data, or intelligence. Temperature only changes decoding behavior during inference. Another mistake is assuming higher temperature always creates better answers. Higher diversity can also increase off topic responses or lower quality outputs.
Interview tip
Explain the practical meaning first: temperature controls randomness during generation. Then explain the mechanism: logits are rescaled before softmax, changing the probability distribution. Finish with the quality versus diversity tradeoff.
Interviewer may ask next
What happens when temperature is set to zero or a very low value?
A very low temperature makes the probability distribution very sharp, so the model usually selects the highest probability token. This makes outputs more deterministic and repeatable. The tradeoff is reduced diversity and a higher chance of repetitive responses.
How would you choose temperature for a production LLM application?
I would choose temperature based on the required balance between consistency and diversity. Lower temperature is better for factual answers, extraction, and structured tasks because predictable output matters more. Higher temperature is better for brainstorming because exploring multiple possibilities matters more. The tradeoff is that more diversity can increase the chance of off topic or lower quality output.
20. What are top-k and top-p sampling?Llm FundamentalsEasy
i Question Details
Trace candidate-set construction, probability-mass cutoff, top-k limits, and interaction with temperature.
Short Interview Answer (30-60 seconds)
Top k and Top p are decoding methods that control which tokens an LLM can choose during generation. Top k keeps a fixed number of highest probability tokens, while Top p keeps the smallest group of tokens whose combined probability reaches a chosen limit. I use them with temperature to control randomness. Top k gives a fixed candidate size, while Top p changes the candidate size based on the probability distribution.
Detailed Explanation
Top k and Top p are ways to control how an LLM chooses the next word. The model first gives probabilities to possible next words. Top k keeps a fixed number of high probability words. Top p keeps enough words to reach a chosen total probability. For example, Top k with k equal to 3 always keeps three words. Top p with p equal to 0.60 keeps the smallest group of words whose total probability is at least 0.60.
Useful Questions to Ask the Interviewer
Which output behavior is more important for this system, accuracy, creativity, or consistency?
Are decoding settings tuned differently for different production use cases?
How to Explain It in an Interview
An LLM generates a probability distribution for possible next tokens. The decoding method decides which tokens remain available before selecting one token.
Top k sampling creates a shortlist with a fixed size. If k is 3, only the three highest probability tokens can be selected. The remaining tokens are removed before sampling. This makes the number of choices predictable.
Top p sampling, also called nucleus sampling, creates a shortlist based on probability mass. The system sorts tokens by probability and keeps the smallest group where the combined probability reaches the chosen value. For example, with p equal to 0.60, tokens are added until their combined probability reaches 0.60. The number of tokens can increase or decrease depending on how the probabilities are distributed.
Temperature changes the probability distribution before Top k or Top p filtering. A lower temperature makes high probability tokens stronger and produces more focused output. A higher temperature makes probabilities more even and can increase variation.
Top k is useful when a fixed number of choices is preferred. Top p is useful when the system needs an adaptive candidate set. Both methods only control token selection during inference. They do not verify facts or guarantee correct answers.
Technical Approach
Generate next token probabilities, sort candidate tokens by probability, apply Top k using a fixed token count or Top p using a cumulative probability threshold, normalize the remaining probabilities, and sample one token.
Practical Insights
The cost depends on the number of token probabilities considered during inference. Candidate filtering requires selecting or sorting possible tokens before sampling.
Why Interviewers Ask This
Interviewers ask this question to evaluate whether a candidate understands how an LLM selects the next token during inference. It tests knowledge of decoding behavior, probability based generation, randomness control, and practical decisions for controlling output quality.
Common interview mistakes
A common mistake is thinking Top k or Top p selects the final answer directly. They only limit the candidate tokens before sampling. Another mistake is thinking Top p always keeps the same number of tokens. The number changes depending on the probability distribution. Temperature does not add knowledge to the model. It only changes randomness during token selection.
Interview tip
Start with the main difference. Explain that Top k uses a fixed number of tokens and Top p uses a probability cutoff. Then explain that temperature changes the distribution before filtering.
Interviewer may ask next
What happens when the Top p value is too low or too high?
A low Top p value keeps a smaller candidate set with mostly high probability tokens. This makes output more focused but can reduce variety. A high Top p value keeps more tokens and increases diversity but may include lower probability choices. The tradeoff is between controlled output and creative variation.
Why might a production system choose Top p instead of Top k?
A production system may choose Top p because it adapts the candidate size to the model confidence. It keeps fewer tokens when the probability distribution is concentrated and more tokens when the distribution is spread out. The tradeoff is adaptive behavior compared with the predictable fixed size of Top k.
More questions load as you scroll
Disclaimer: This interview guide is for educational and informational purposes only. It is designed to help readers prepare, but it does not guarantee any interview result, hiring decision, offer, or outcome. Interview questions, hiring criteria, and preferred answers can vary by employer, interviewer, industry, location, and time. The examples and explanations reflect the authors' research and judgment, are provided without warranties of any kind, and should not be treated as the only correct approach. Diagrams are simplified illustrations intended to highlight the main components and their interactions; actual systems and implementations may be more complex. Alternative approaches may be equally valid or better suited to a particular question, context, or interviewer. To the fullest extent permitted by applicable law, the author, contributors, and publisher are not liable for decisions made, actions taken, or losses incurred based on this guide.