Q1
How do ChatGPT/OpenAI models handle longer context and older messages?
What happens once a conversation grows past the model's context window
Common follow-up

ChatGPT models have a fixed context window — they can only process a limited number of tokens at a time (a token is a small chunk of text: a word, part of a word, or punctuation). When a conversation is short, the model sees every message directly. Once the conversation gets very long, it's no longer practical to include every old message in full — so older history gets represented in a compressed form instead.

In short: recent messages are kept in high detail, older messages may be summarized, and long-term memory may store stable facts or preferences that are useful across conversations.
Semantic summarization, not exact compression

This is usually not exact compression like ZIP, where the original text can be perfectly restored. Instead, it is closer to semantic summarization. The system tries to preserve the important meaning — decisions, user preferences, project context, constraints, and repeated facts — while dropping low-value details such as typos, casual comments, repeated back-and-forth, or outdated intermediate decisions.

Worked example

If a user had a long conversation about building a website called Nextforay, GitHub Pages, private repositories, Cloudflare Pages, DNS, and branding, the older history might be compressed into a short summary like:

"The user is building Nextforay, a learning and interview preparation site. They are using GitHub Pages or Cloudflare Pages, want to keep the source repository private, avoid content leaks, and prefer a minimal professional design."

This summary is much shorter than the full conversation, but it preserves the useful context needed for future answers.

It's lossy — what can get dropped

Exact wording, code, YAML files, DNS records, legal text, or detailed numbers may be lost or simplified during summarization. That is why, for technical or high-precision tasks, it is better to paste the latest exact version again rather than rely on the model's memory of it.

Practical mental model
  • Recent messages — kept in high detail, close to raw
  • Older messages — may be summarized, losing exact wording
  • Long-term memory — may store stable facts or preferences useful across conversations
Interview Q & A
Q: How does ChatGPT handle a conversation once it grows past the context window?
A: Recent messages stay in full detail. Once the conversation grows too long, older messages get semantically summarized — important facts, decisions, and preferences are kept, low-value chatter is dropped. This is lossy, so exact code or config should be re-pasted rather than relied on from memory.
Q2
Does context compression happen through attention?
Separating "attention inside the model" from "context compression before the model"
Common follow-up

Not exactly. There are two different concepts here: attention inside the model and context compression before the model processes the input.

In short: compression decides what context is included; attention decides how much importance each included part gets during generation.
Self-attention inside the transformer

Inside the model, ChatGPT uses a transformer architecture, and transformers rely on self-attention. Self-attention helps the model decide which parts of the currently available context are most relevant when generating the next token. For example, if the user asks about making a GitHub repository private, the attention mechanism may focus more on words like "GitHub Pages," "private repo," "Cloudflare Pages," and "custom domain," while giving less importance to unrelated older topics.

Attention isn't compression

Attention does not automatically mean the model is compressing the entire long conversation by itself. Attention works only over the tokens that are already present in the model's current context window. If the full conversation is too long, some preprocessing may happen before the model receives the input — older messages may be summarized, selected, or retrieved as relevant memory, and then that compressed information is inserted into the context.

The flow
Long conversation → recent messages kept mostly raw → older messages summarized or selectively retrieved → final context window prepared → transformer self-attention operates over that context → model generates the answer
Interview Q & A
Q: Is ChatGPT's long-context handling just attention, or something else?
A: They're different layers. Compression, summarization, and retrieval happen before the model runs, to decide what goes into the context window. Self-attention then runs inside the transformer over whatever ended up in that window, deciding which of the included tokens matter most for the next prediction.
Q3
Why do LLMs have limited context windows despite billions of parameters?
Parameters vs. context window — two different kinds of "capacity"
Must-know

Even though an LLM has billions of parameters, it still has a limited context window because parameters and context are two different things.

Model parameters = what the model has learned during training Context window = what the model can actively read right now

The billions of parameters store learned patterns — grammar, reasoning behavior, coding knowledge, facts, concepts. But they do not store your current conversation word-for-word. When you send a prompt, the model must process the actual input tokens currently given to it, and it can only attend to a fixed maximum number of tokens at once — the context window.

A simple analogy:

Parameters = long-term knowledge in the brain Context window = short-term working memory / desk space

A person may know a lot, but they cannot hold an entire 500-page book perfectly in active attention at the same time.

In short: LLMs have limited context because parameters represent learned knowledge, while context represents the active input the model can process during inference.
Main technical reason: attention cost

Most transformer models use self-attention. In basic self-attention, every token compares itself with many other tokens in the context — so as context length grows, computation grows very fast.

2x longer context ≠ 2x cost 2x longer context can be closer to 4x attention work

Because tokens interact with other tokens:

1,000 tokens → many token-to-token comparisons 10,000 tokens → far more comparisons 100,000 tokens → extremely expensive

This affects:

  • GPU memory
  • Latency
  • Serving cost
  • Energy usage
  • Throughput

So context length is not only a model design issue — it is also an infrastructure and cost issue.

Quality can degrade with very long context

Even if we technically allow a huge context window, the model may not use all of it equally well. Long-context models can sometimes miss details buried deep inside the prompt, confuse older and newer information, or over-focus on irrelevant text. So bigger context helps, but it does not automatically mean perfect recall.

Training also matters

A model must be trained or adapted to handle long contexts well. You cannot always take a model trained mostly on shorter sequences and expect it to perform perfectly on very long documents. Long-context ability needs special architecture choices, positional encoding strategies, training data, and evaluation.

Interview Q & A
Q: Why do LLMs have limited context windows despite having billions of parameters?
A: Parameters store learned knowledge from training; the context window is the model's working memory for the current input — two separate things. The window is capped mainly because self-attention cost grows faster than linearly with sequence length (more tokens means far more token-to-token comparisons), which hits GPU memory, latency, and cost. Beyond a point, quality also degrades — models don't reliably use every detail in a very long context — so handling long context well requires deliberate architecture and training choices, not just raising the limit.
Q4
Why do LLMs hallucinate?
Next-token prediction vs truth verification — why fluency and accuracy are different things
Must-know

LLMs hallucinate because they are trained to predict the most likely next token, not to directly verify truth. A model does not "know" facts the way a database knows facts — it generates answers based on patterns learned from huge training data. At inference time, the objective is roughly:

Prompt → predict next token → predict next token → predict next token...

The goal is to generate a likely and coherent answer — not automatically to check that answer against a trusted source. So if the model has incomplete, conflicting, outdated, or weak information, it may still generate a confident-looking answer.

In short: LLMs are probabilistic next-token predictors, not truth-verification systems. Fluency and accuracy are two separate properties — a model can be very fluent while being factually wrong.
Main causes of hallucination
  • Training objective — LLMs are optimized for language prediction. They learn what answers usually look like, not always what is true.
  • No built-in source of truth — unless connected to tools, documents, search, a database, or RAG, the model cannot verify fresh or exact facts.
  • Knowledge gaps — if the model has not seen enough reliable examples about a topic, it fills gaps using plausible patterns.
  • Conflicting training data — training data can contain outdated, duplicated, low-quality, or contradictory information; the model may blend them.
  • Overconfidence from language fluency — LLMs are very good at producing fluent text; fluency can make wrong information look convincing.
  • Prompt pressure — if the user asks for an answer even when information is missing, the model may try to be helpful instead of saying "I don't know."
  • Long context issues — in long prompts the model may miss details, mix old and new information, or rely on the wrong part of the context.
Worked example

Suppose you ask:

What is the API endpoint for X feature in Y product?

If the model has weak or outdated knowledge, it may generate something that follows a common API pattern:

GET /api/v1/x/{id}/details

This looks realistic, but it may not exist. That is hallucination: plausible but unsupported generation.

Where hallucination is most likely
  • Niche or low-coverage topics
  • Recent information beyond the training cutoff
  • Exact numbers, citations, and references
  • API endpoints, library versions, SDK signatures
  • Legal, medical, and financial specifics
  • Long-context conversations where context is partially lost
How to reduce hallucination
  • RAG — retrieve documents at query time and ground answers in source text
  • Tool use / search — let the model call external APIs or databases for verifiable facts
  • Citations — require the model to cite the source chunk it used; makes hallucination detectable
  • Structured output + validation — constrain output schema; validate extracted values against source
  • Confidence checks — ask the model to output confidence per claim; route low-confidence outputs to HITL
  • Prompt instruction — explicitly instruct the model to say "I don't know" when evidence is insufficient
  • Faithfulness eval — use NLI or LLM-as-judge to check whether each claim is supported by the retrieved context
Interview Q & A
Q: Why do LLMs hallucinate, and how do you reduce it in production?
A: LLMs hallucinate because they are probabilistic next-token predictors, not truth-verification systems. They generate responses based on learned patterns — when the model lacks reliable information, has conflicting data, sees an ambiguous prompt, or cannot access an external source of truth, it may still produce a fluent and confident answer that is factually wrong. Hallucination is most likely in niche topics, recent information, exact numbers, citations, API details, and long-context conversations. To reduce it: use RAG to ground answers in retrieved source text, require citations, validate structured outputs with Pydantic, use LLM-as-judge faithfulness scoring, and explicitly instruct the model to say "I don't know" when evidence is insufficient.
Q5
Why does an LLM predict tokens instead of directly predicting "truth"?
The training objective is language modeling, not fact verification
Must-know

An LLM is trained using a language modeling objective — mainly next-token prediction. Given a sequence of tokens, it learns to predict the most likely next token based on patterns in the training data.

The capital of India is ___

The model learns that "New Delhi" is likely based on examples seen during training. It is not trained like a database that verifies facts. It learns statistical and semantic patterns from large-scale text, so it can generate fluent and useful answers — but also plausible-sounding incorrect ones.

In short: An LLM predicts tokens because its training objective is to model the probability distribution of language. Truth can emerge from learned patterns, but truth verification is not built into the basic next-token prediction objective.
Interview line
Q: Why does an LLM predict tokens rather than facts?
A: The training objective is next-token prediction — the model learns what text is likely to follow given a context. Truth can emerge from those patterns, but the model has no built-in mechanism to verify claims against a source of truth. That is a fundamental reason why hallucination exists.
Q6
What exactly is a token, and why does tokenization matter in LLMs?
The basic unit the model processes — and why it affects almost everything
Must-know

A token is the basic unit of text that an LLM processes. A token can be a full word, part of a word, punctuation, whitespace, or a special symbol. A sentence like ChatGPT is useful. may split into tokens like:

Chat | G | PT | is | useful | .

Actual tokenization depends on the tokenizer. Models do not directly read characters or words — they read token IDs. Tokenization affects context length, cost, model performance, multilingual handling, code generation, and even simple tasks like counting letters.

In short: Tokens are the model's input units, and tokenization decides how raw text is converted into something the model can process.
Practical impacts of tokenization
  • Context length — one word may become multiple tokens, so a "4K token" window may hold fewer than 4K words
  • Cost — API pricing is per token, not per word; longer tokens = higher cost
  • Multilingual handling — non-English text often tokenizes into more tokens per character, effectively shrinking the usable context for those languages
  • Counting & spelling — the model may not see individual characters, which is why it can fail at tasks like "count the r's in strawberry"
  • Code generation — symbols, indentation, and identifiers may each be separate tokens affecting how the model reasons about code structure
Interview line
Q: What is a token and why does tokenization matter?
A: A token is the atomic text unit an LLM processes — a word, subword, punctuation, or special symbol. Tokenization affects context length, API cost, multilingual performance, and why the model can fail at character-level tasks like letter counting.
Q7
What is an embedding, and how is it different from a token?
Token = symbolic unit; embedding = dense numerical representation
Must-know

A token is a discrete text unit. An embedding is a numerical vector representation of that token. The model first converts text into tokens, then maps each token ID into an embedding vector. This vector captures learned information about the token's meaning and usage.

"king" → token ID → embedding vector [0.21, -0.45, 0.87, ...]

The embedding is usually a high-dimensional vector (hundreds or thousands of dimensions). Similar words or concepts often have embeddings that are geometrically closer in that space.

Token = symbolic unit (discrete) Embedding = numerical representation (continuous vector)
In short: Tokens are the discrete inputs; embeddings are dense vector representations that allow the neural network to process semantic relationships mathematically.
Interview line
Q: What is the difference between a token and an embedding?
A: A token is a symbolic text unit (word or subword). An embedding is the continuous numerical vector the model maps each token to. Embeddings encode semantic similarity — related concepts end up close in vector space — which is what lets the neural network reason about meaning.
Q8
How does self-attention help a model understand context?
Every token looks at every other token to decide what is relevant
Must-know

Self-attention allows each token to look at other tokens in the sequence and decide which ones are important for understanding the current token. Consider:

The trophy does not fit in the suitcase because it is too large.

The word "it" refers to "trophy," not "suitcase." Self-attention helps the model connect "it" to the correct earlier word, even across many tokens. Instead of processing words only left-to-right like older sequence models, transformers use attention to compare tokens with every other token in the context.

In short: Self-attention = deciding which previous or surrounding tokens matter most for understanding the current one. It is the core reason transformers handle language so well.
Interview line
Q: How does self-attention help a model understand context?
A: Self-attention lets each token directly compare itself with all other tokens in the context and assign importance weights. This lets the model resolve pronoun references, long-range dependencies, and semantic relationships without having to pass information step-by-step through every prior token the way RNNs did.
Q9
Why is transformer architecture better than RNN/LSTM models for LLMs?
Parallelism and long-range context — two things RNNs cannot scale
Must-know

Older RNNs and LSTMs process text sequentially, one token at a time. This makes training slow and makes it hard to capture relationships between distant words — information must travel through every intermediate step.

Transformers use self-attention, allowing tokens to compare directly across the full sequence. Training is parallel rather than sequential.

Why transformers won
  • Better long-range context — attention directly connects distant tokens; RNNs degrade over long sequences
  • Parallel training — all tokens processed simultaneously; RNNs must compute step by step
  • More scalable — larger transformers consistently improved with more data and compute; RNNs did not scale as predictably
  • GPU/TPU fit — matrix multiplications used by attention map naturally to hardware accelerators
  • Stronger performance — on translation, summarization, generation, and reasoning, transformers outperform RNN-based architectures at scale
Interview line
Q: Why did transformers replace RNNs for LLMs?
A: RNNs process tokens sequentially, which limits parallelism and makes long-range dependencies hard to capture. Transformers use self-attention to compare tokens across the full sequence simultaneously, making training much faster, more scalable, and better at capturing long-range context — which is why all modern LLMs are transformer-based.
Q10
What are Query, Key, and Value in attention?
The library-search analogy: what you're looking for vs. what's on the shelf vs. what's inside
Must-know

In attention, every token is projected into three vectors:

Query = what this token is looking for Key = what this token offers for matching Value = the actual information carried by the token

A simple analogy is library search. Your search query is matched against book indexes (keys); strong matches return the book content (values).

For the word "it" in The cat sat because it was tired, the Query may look for the entity being described. The Key of "cat" matches strongly, so the model pulls the Value of "cat" to understand the sentence.

In short: Q, K, and V are learned projections that let the model decide which tokens are relevant (via Q·K similarity) and what information to pull from them (V).
Interview line
Q: What are Q, K, and V in transformer attention?
A: Each token is projected into Query (what it's looking for), Key (what it exposes for matching), and Value (what it contributes). Attention scores = softmax(Q·Kᵀ / √d_k), then multiplied by V. High Q–K similarity means the model attends heavily to that token's Value — the mechanism by which context relationships are captured.
Q11
What is multi-head attention, and why do we need multiple heads?
Multiple parallel "views" of the same sequence — each learning different relationships
Must-know

Multi-head attention runs several attention mechanisms in parallel, called attention heads. Each head can learn to focus on different types of relationships — one head might focus on grammar, another on subject-object relationships, another on long-distance references, another on positional patterns.

For Amit gave Rahul his laptop because he needed help, different heads may focus on:

Head 1 → who gave something Head 2 → what was given Head 3 → who "he" refers to Head 4 → relation between people and objects
In short: Multi-head attention gives the model multiple parallel "views" of the same text, allowing it to capture different relationship types simultaneously rather than forcing one attention mechanism to learn everything.
Interview line
Q: Why use multiple attention heads instead of one?
A: A single attention head can only learn one attention pattern per layer. Multiple heads run in parallel with separate Q/K/V projections, each learning to focus on different relationship types (syntactic, semantic, positional, referential). Their outputs are concatenated, giving the model richer representational capacity at the same computational depth.
Q12
What is positional encoding, and why does a transformer need it?
Self-attention is order-agnostic — positional encoding injects sequence order
Must-know

Transformers process tokens in parallel and do not naturally understand word order. Unlike RNNs, they don't process tokens one after another. So without positional encoding, the model would treat these as equivalent:

Dog bites man. Man bites dog.

Positional encoding adds information about each token's position to its embedding before the first layer, letting the model distinguish order.

In short: A transformer needs positional encoding because self-attention alone is permutation-insensitive. Position information enables the model to understand sequence order.
Approaches used in practice
  • Sinusoidal (original paper) — fixed math formulas based on position and dimension; no training needed
  • Learned positional embeddings — position embeddings treated as trainable parameters, learned during training
  • Rotary Position Embedding (RoPE) — encodes position by rotating Q and K vectors; better for long contexts; used in LLaMA, Qwen, and many modern models
  • ALiBi — adds a position-based bias to attention scores rather than the embeddings; generalizes to sequences longer than those seen in training
Interview line
Q: Why do transformers need positional encoding?
A: Self-attention is permutation-invariant — it sees a bag of tokens, not a sequence. Positional encoding injects order information by adding position-dependent signals to token embeddings. Without it, "dog bites man" and "man bites dog" look identical to the model. Modern variants like RoPE encode position into Q/K rotations for better long-context generalization.
Q13
What is the difference between parameters, context, memory, and training data?
Four terms that are often conflated — each means something distinct
Must-know
Training data = what the model learned from Parameters = what the model learned (stored weights) Context = what the model sees right now (current prompt) Memory = selected information stored/retrieved across sessions
In short: Parameters are long-term learned weights, context is active working input, memory is external or system-managed recall, and training data is the source used to train the model.
Training data

The large collection of text (web, books, code, conversations) used to train the model. After training, it is not stored in the model — only its influence on the weights remains.

Parameters

The learned weights of the neural network. They store patterns learned from training data, but not as a searchable database — knowledge is distributed across millions or billions of weights. Not updated at inference time (unless fine-tuning).

Context

The current input given to the model during inference: user prompt, conversation history, system instructions, retrieved documents, tool outputs. The model only "sees" what is in its current context window. It is temporary — cleared at the end of the session.

Memory

User-specific information saved externally (database, vector store) and retrieved into future conversations. Managed by the application, not the model itself. Allows personalization and recall across sessions without retraining.

Interview line
Q: What is the difference between model parameters, context, memory, and training data?
A: Training data is what the model learned from; parameters are the learned weights after training; context is the active prompt the model reads at inference time; memory is application-managed information retrieved across sessions. Parameters are static at inference; context is the live working window; memory is external persistent recall.
Q14
Where is knowledge stored inside an LLM?
Distributed across weights — not rows in a database
Common

Knowledge in an LLM is stored in its parameters — the learned weights of the neural network. But it is not stored like rows in a database. You cannot simply open the model and find:

Capital of India = New Delhi

Instead, knowledge is distributed across many weights and layers. The model learns patterns from training data and encodes those patterns as high-dimensional representations. This is why LLMs can generalize — they learn relationships, concepts, grammar, style, and reasoning patterns, not just facts.

In short: Knowledge is stored as distributed representations across model parameters, not as explicit records. This enables generalization but makes inspection, editing, or deletion of specific facts very hard.
Interview line
Q: Where is knowledge stored in an LLM and why is it hard to edit?
A: Knowledge is stored as distributed patterns across billions of weights — not as explicit key-value entries. The same fact may be encoded across many layers and many weights simultaneously, which is why removing or correcting one specific fact is difficult and risks affecting related knowledge.
Q15
Does an LLM actually "understand" language, or just predict patterns?
Functional understanding vs human understanding — a nuanced answer
Common

Technically, an LLM predicts tokens based on learned statistical patterns. But because it is trained on huge amounts of language, code, reasoning examples, and world knowledge, it develops internal representations that can behave like understanding. It can summarize, translate, reason, write code, answer questions, and follow instructions.

However, it does not understand like a human. It has no lived experience, consciousness, goals, or direct grounding in the physical world — unless connected to tools, sensors, or external systems.

Balanced answer: LLMs do pattern prediction, but at scale those patterns encode semantic, syntactic, and reasoning-like representations. They show functional understanding, but not human-like understanding.
Interview line
Q: Does an LLM actually understand language?
A: LLMs predict tokens via learned patterns — not explicit reasoning. But at scale, those patterns encode rich semantic and syntactic structure that enables summarization, translation, code generation, and reasoning. The honest answer is: functional understanding, yes; human-like understanding with grounding, consciousness, or lived experience, no.
Q16
Can we delete one specific fact from an LLM?
Machine unlearning is hard — knowledge is entangled, not indexed
Common

Not easily. Because knowledge is distributed across many parameters, removing one fact is difficult. The model does not store facts in a clean key-value format, so removing "Person X works at Company Y" may require changing weights that also encode many related things.

In short: Deleting a fact from an LLM is hard because knowledge is distributed, entangled, and not stored as explicit database entries. Production systems usually manage sensitive or changing facts externally instead.
Research approaches
  • Machine unlearning — attempts to remove training influence; still an active research area
  • Model editing — techniques like ROME or MEMIT to directly patch specific facts in weights; imperfect and can break related knowledge
  • Fine-tuning — fine-tune on examples that override the fact; can partially work but risks side effects
  • Refusal tuning — train the model to refuse to answer questions about a specific topic
What works better in production
  • Manage sensitive or changing facts in external memory, RAG, or access-controlled databases
  • Add output filters or guardrails to block specific content before it reaches the user
  • Avoid relying on model weights for facts that need to be updated or deleted — keep them external
Interview line
Q: Can you delete a specific fact from an LLM?
A: Not cleanly. Knowledge is distributed across weights, so there's no "delete fact" operation. Research approaches like machine unlearning and model editing exist but are imperfect. In production, the better approach is to keep changing or sensitive facts in external systems (RAG, databases, filters) rather than trying to edit model weights post-training.
Q17
Why can small prompt changes change the answer so much?
Prompts shift the probability distribution — even minor wording matters
Common

The model generates output based on the probability distribution created by the full prompt. Even a small wording change can shift the model's interpretation, tone, reasoning path, or assumptions. For example:

Explain briefly. → concise, general answer Explain like an expert. → assumes audience, uses technical depth

Prompts act like soft instructions — they influence what the model attends to, what style it uses, and which learned patterns it activates. This sensitivity is strongest when the prompt is ambiguous, underspecified, or asks about complex topics.

In short: Small prompt changes alter the context distribution, attention patterns, and instruction interpretation used during generation — which is why prompt engineering matters and why LLMs need careful prompting for consistent outputs.
Interview line
Q: Why are LLMs so sensitive to small prompt changes?
A: Every word in the prompt shapes the probability distribution over next tokens. A small wording change can activate different learned patterns, shift attention to different parts of the context, and change the model's assumed audience or reasoning path. This is why prompt engineering, system prompts, and consistent templates matter in production — output consistency requires input consistency.
Q18
Why does an LLM struggle with exact counting or spelling inside words?
Tokenization hides character-level structure from the model
Good to know

LLMs process text as tokens, not as individual characters. A word like strawberry may be represented as one or a few subword tokens — not necessarily as separate letters. So when asked to count letters, the model predicts an answer based on learned patterns rather than performing exact symbolic counting.

strawberry → [straw | berry] (example split) NOT → [s | t | r | a | w | b | e | r | r | y]

The model may not "see" the individual r's at all. It generates a likely-sounding count based on pattern recognition rather than enumeration.

In short: LLMs struggle with exact spelling and counting because tokenization and probabilistic generation are not the same as symbolic character-level computation.
Interview line
Q: Why can't LLMs reliably count letters in a word?
A: Because the model processes tokens, not individual characters. A word like "strawberry" may be one or two tokens, not ten character tokens. The model has no direct way to enumerate characters — it predicts a plausible-sounding count. This is fixable with tools (code interpreter) or chain-of-thought prompting that forces character-by-character enumeration.
Q19
Why are LLMs good at language but sometimes weak at basic arithmetic?
Language is pattern-matching; arithmetic requires deterministic symbolic computation
Common

LLMs are trained primarily to predict language patterns, not to execute arithmetic algorithms. They may have seen many arithmetic examples during training, so they can answer common calculations — but for exact multi-step arithmetic they may make mistakes because they are generating likely tokens rather than running a calculator.

23 + 18 = 41 ← common enough to pattern-match correctly 9372 × 4817 = ? ← requires exact digit manipulation; model may approximate
In short: LLMs are strong at linguistic and pattern-based reasoning. Exact arithmetic is better handled with tools — a calculator or code interpreter — because arithmetic requires deterministic symbolic computation, not probability estimation.
Interview line
Q: Why do LLMs sometimes fail at simple arithmetic?
A: LLMs generate statistically likely tokens — they don't execute arithmetic algorithms. Simple arithmetic appears so often in training data that models pattern-match it correctly. Multi-step or large-number arithmetic requires exact digit manipulation the model wasn't trained to do. The production fix: give the LLM a code interpreter or calculator tool and let it delegate exact computation.
Q20
How does an LLM decide when to stop generating?
EOS tokens, max token limits, and stop sequences
Good to know

An LLM generates text token by token. At each step it predicts the next token. It stops when one of several conditions is met:

  • The model predicts an end-of-sequence (EOS) token — a special token the model was trained to output when a response is complete
  • It reaches the max token limit set by the caller or system
  • It produces a stop sequence defined by the developer (e.g., "\n\nUser:" in a chat template)
  • The API or server cuts off the response due to infrastructure limits
In short: Stopping is controlled by EOS token prediction (learned during training) combined with external generation constraints like max tokens and stop sequences set by the application.
Interview line
Q: How does an LLM know when to stop?
A: The model is trained to emit a special EOS token when a response is complete. The generation loop stops when EOS appears, the max token budget is exhausted, or a developer-defined stop sequence is matched. In practice, always set a max token limit as a hard guard to prevent runaway generation.
Q21
Why does an LLM repeat itself sometimes?
Autoregressive loops — previously generated text reinforces similar next tokens
Good to know

Since the model generates one token at a time, it may fall into a loop where previously generated text makes similar next tokens more likely. If it starts a repeated pattern like This means... This means... This means..., the generated context itself reinforces that pattern.

Repetition also happens when the model is trying to be comprehensive but lacks new information — it rephrases the same idea multiple times.

In short: Repetition happens because autoregressive generation can reinforce its own previous patterns, especially under poor decoding settings or ambiguous prompts.
Practical mitigations
  • Repetition penalty — down-weight tokens that have already appeared in the output
  • Stop sequences — halt generation when a known completion pattern is reached
  • Better prompts — give the model a clear scope and length expectation
  • Lower max tokens — prevents the model from padding when it has run out of content
  • Improved instruction tuning — models fine-tuned for conciseness are less prone to filler loops
  • Adjusted sampling — top-p / top-k sampling or temperature tuning can help break repetitive ruts
Interview line
Q: Why do LLMs repeat themselves, and how do you fix it?
A: Autoregressive generation can self-reinforce — repeated text in the context makes similar continuations more likely. Fixes: repetition penalty in decoding, explicit stop sequences, clear prompt scope, lower max tokens, and better instruction tuning. In production, repetition is usually a sign of either a weak prompt or a model running out of new content to say.
Q22
How do LLMs handle long conversations?
Combining recent context, summarization, retrieval, and memory
Must-know

A model can only process a limited number of tokens at once. Long conversations are handled using a combination of context window management, summarization, retrieval, and memory. The simplified flow:

Recent conversation → kept mostly raw Older conversation → summarized or retrieved if relevant Important user facts → stored as memory if supported Final context → sent to the model as one context window

The model then uses attention over that final assembled context. The key point: the model does not always see the full conversation word-for-word. Long conversation handling is often lossy — exact old wording, code, and small details may be lost unless explicitly preserved.

In short: Long conversations are handled by combining recent raw context with compressed summaries, memory, and retrieval mechanisms — not by giving the model unlimited memory.
Interview line
Q: How do LLMs handle long conversations that exceed the context window?
A: Recent messages stay in the context raw; older messages may be summarized or selectively retrieved. Long-term stable facts may go into external memory. The final context window is assembled from these pieces and fed to the model. The process is lossy — exact earlier content (code, config, legal text) may be dropped, which is why users should re-paste anything precision-critical.
Q23
What is context compression or summarization in chat systems?
Semantic compression — preserving meaning while reducing token count
Common

Context compression means reducing older or longer conversation history into a shorter representation while trying to preserve the important meaning. It is not like ZIP compression — the original text cannot be perfectly restored. It is semantic compression, more like summarization.

A long conversation about GitHub Pages, private repos, Cloudflare Pages, DNS, and branding might compress to:

"User is building Nextforay, wants a private source repo, is considering GitHub Pages or Cloudflare Pages, and prefers minimal professional branding."

This saves context space while preserving useful information. However, it can lose exact code, exact wording, chronology, minor decisions, or technical details.

In short: Context compression is semantic summarization of older context so the model can continue the conversation within a limited context window. It is lossy — re-paste high-precision content rather than relying on compressed memory.
Interview line
Q: What is context compression, and when does it cause problems?
A: Context compression is semantic summarization of older conversation history to fit within the context window. It preserves high-level intent, preferences, and decisions while dropping low-value filler. It causes problems for technical tasks because exact code, configuration, numbers, and detailed instructions are often lost in the summary. The fix: explicitly re-inject any precision-critical content into the current prompt.