Showing posts with label AI. Show all posts
Showing posts with label AI. Show all posts

Saturday, 24 October 2026

Inside ChatGPT: What Happens After You Hit Enter?

A step-by-step look at the journey of a single message, from keystroke to streaming reply

You type a question, press Enter, and within a second words begin to appear on screen. It feels instant and effortless. But in that fraction of a second, your message travels through a surprisingly elaborate pipeline of software and hardware.

One caveat before we begin: the exact internals of ChatGPT are proprietary, so this post describes how chat assistants built on large language models (LLMs) generally work. The broad strokes are shared across the industry, and they're enough to demystify what's going on.

Step 1: Your message goes to a server

When you hit Enter, the app sends your text over the internet to the provider's servers. There, it passes through the usual web infrastructure: authentication, rate limiting, and routing to a machine that has capacity to run the model. The model itself is far too large to run on your phone or laptop, so it lives in data centers on specialized chips called GPUs or other AI accelerators.

Step 2: Your prompt is assembled

The model doesn't see just the sentence you typed. The system builds a larger prompt that typically includes:

  • Instructions from the provider, which shape the assistant's tone, behavior, and boundaries.
  • The conversation so far, since the model has no memory between requests and must be re-shown the earlier messages each time.
  • Extras such as saved preferences or tool results, where the product supports them.
  • Your new message, placed at the end.

This whole bundle is the model's entire view of the world for this one response. That's why very long chats can eventually hit the context window, the maximum amount of text the model can consider at once.

Step 3: Text becomes tokens

The assembled prompt is split into tokens, small chunks such as whole words, word fragments, or punctuation. "Unbelievable" might become "un," "believ," and "able." Each token is mapped to a number, and each number is then converted into an embedding, a long list of values that captures the token's meaning. From this point on, the model works entirely with numbers.

Step 4: The forward pass through the transformer

Now the heavy lifting begins. The embeddings flow through dozens of stacked transformer layers. In each layer, an attention mechanism lets every token look at every other token and weigh which ones matter for interpreting it. In the sentence "The trophy didn't fit in the suitcase because it was too big," attention helps connect "it" to "trophy."

This step involves billions of multiplications performed in parallel across GPUs, which is why the hardware matters so much. Because the model's knowledge is stored in its billions of weights, every one of them participates in the calculation.

Step 5: The model predicts one token

At the end of the forward pass, the model produces a probability for every token in its vocabulary. Maybe "The" gets 12 percent, "Sure" gets 9 percent, and "A" gets 6 percent, with thousands of others sharing the rest.

The system then samples from these probabilities rather than always taking the top choice. Settings such as temperature control how adventurous that choice is: lower values make output more predictable, higher values make it more varied. This controlled randomness is why asking the same question twice can produce different answers.

Step 6: Repeat, and stream

The chosen token is appended to the text, and the whole process runs again to pick the next token, and the next, until the model emits a special end-of-response signal or hits a length limit. Engineering tricks, such as caching the work already done for earlier tokens, keep this loop fast.

As each token is produced, it's sent straight back to your screen. That's why the reply seems to be typed out live. It really is being generated one piece at a time, and streaming it makes the wait feel much shorter.

Step 7: Safeguards and tools along the way

Around this core loop, products typically add extra layers. Safety systems may check inputs and outputs for harmful content. If the assistant can use tools such as web search, code execution, or file analysis, the model may pause its text, request a tool call, receive the result, and then continue writing with that new information in hand.

What this means for you

Understanding the pipeline explains several everyday quirks:

  • Why long chats can drift or forget early details: the context window is finite, and everything must fit inside it.
  • Why answers vary between tries: sampling introduces randomness.
  • Why the model can be confidently wrong: it generates plausible next tokens, not verified facts.
  • Why clear prompts help: your words are the main steering signal the model gets.

The big picture

After you hit Enter, your message is wrapped in context, converted to numbers, pushed through a giant neural network, and turned back into words one token at a time. There's no hidden mind consulting an encyclopedia, just an extraordinarily well-trained pattern predictor running at remarkable speed.

The next time a reply streams onto your screen, you'll know a lot is happening behind that blinking cursor.

What Is a Large Language Model, and How Does It Work?


If you've chatted with Claude, ChatGPT, Gemini, or Llama, you've used a Large Language Model (LLM). These systems write code, draft emails, summarize reports, and translate languages, and they can feel almost magical. But under the hood, the core idea is surprisingly simple. In this post, we'll break down what an LLM is, how it works, and where it falls short.

So, what is an LLM?

A Large Language Model is an AI system trained on enormous amounts of text to understand and generate human language. At its core, it does one thing: given some text, it predicts what text should come next.

That sounds almost too simple. But when you do it at massive scale, with billions of adjustable parameters and trillions of words of training data, the result is a system that can answer questions, reason through problems, and write in nearly any style.

How an LLM works, step by step

1. Tokenization: chopping text into pieces

Models don't read words the way we do. Text is first split into small chunks called tokens, which can be whole words, word fragments, or punctuation. For example, "unbelievable" might become "un," "believ," and "able." Each token is then mapped to a number the model can process.

2. Embeddings: turning words into meaning

Each token is converted into a long list of numbers called a vector, which captures something about its meaning. Words with similar meanings end up with similar vectors. This lets the model work with meaning mathematically: "king" and "queen" land near each other, while "king" and "sandwich" do not.

3. The transformer and the power of attention

Nearly all modern LLMs are built on the transformer architecture, introduced in 2017. Its breakthrough idea is attention, a mechanism that lets every token look at every other token in the input and decide which ones matter most.

Consider this sentence: "The trophy didn't fit in the suitcase because it was too big." What does "it" refer to? Attention helps the model link "it" to "trophy" rather than "suitcase." Dozens of stacked transformer layers refine this understanding step by step, building richer and richer representations of the text.

4. Predicting the next token, again and again

Finally, the model outputs a probability for every possible next token. It picks one (with a controlled amount of randomness), adds it to the text, and repeats. That loop, one token at a time, is how a full response gets generated.

How an LLM learns

Pretraining

During pretraining, the model reads trillions of tokens from books, websites, code, and more. For each passage, it tries to predict the next token, compares its guess with the real answer, and nudges its internal weights (billions of numerical parameters) to do slightly better next time. Repeated over countless examples, this process teaches the model grammar, facts, reasoning patterns, and writing styles.

Fine-tuning and alignment

A raw pretrained model simply continues text; it isn't naturally a helpful assistant. To get there, it is further trained on example conversations and refined using human feedback, such as reinforcement learning from human feedback (RLHF). This teaches the model to follow instructions, be helpful, and avoid harmful outputs.

What LLMs are good at

  • Flexibility: One model can handle writing, coding, analysis, translation, and more.
  • Fluent language: They produce natural, coherent text across many styles and tones.
  • Generalization: They can tackle new problems from just a description or a few examples.

Where LLMs fall short

  • Hallucinations: LLMs can state false things with total confidence, so important claims are worth verifying.
  • Knowledge cutoffs: A model's knowledge stops at its training cutoff unless it's given tools such as web search.
  • Different kind of understanding: LLMs learn patterns from text rather than from direct experience of the world, so they don't understand things the way humans do.

A helpful mental model

Think of an LLM as a system that has compressed patterns from a huge portion of written human knowledge into its weights. When you give it a prompt, it draws on those patterns to generate the most plausible continuation. With enough scale and training, "plausible continuation" turns out to cover a surprising amount of useful intelligence.

Final thoughts

LLMs aren't magic, and they aren't mind-readers. They're prediction engines built on a clever architecture and trained on vast amounts of text. Understanding the basics (tokens, embeddings, attention, and next-token prediction) makes it easier to use them well: to write better prompts, spot their mistakes, and appreciate what they can and can't do.

As techniques like retrieval and tool use continue to extend what these models can do, the best way to understand LLMs is to keep experimenting with them.

Want to dig deeper? Future posts could explore attention in detail, how training works, or how tools and retrieval make LLMs more capable.

Thursday, 22 October 2026

LLM Fundamentals Interview Questions Part1


1. What Are Foundation Models?

A foundation model is a large AI model trained on broad and diverse datasets that can be adapted to perform multiple tasks.

Instead of being designed for a single purpose, a foundation model learns general patterns and representations from data. Developers can then use or adapt it for specific applications.

Foundation models may be trained to work with different types of data, including:

  • Text and natural language

  • Source code

  • Images

  • Audio and speech

  • Video and other multimodal inputs

Examples of Foundation Models

Some well-known examples include:

  • GPT: A family of models used for language understanding, content generation, reasoning, and coding.

  • Claude: AI models used for writing, analysis, and software development.

  • Gemini: Models designed for language, reasoning, and multimodal tasks.

  • Llama: A family of open-weight language models that developers can adapt and deploy under the applicable license.

  • Stable Diffusion: A family of generative models used for image creation.

These models provide reusable capabilities that can support many different applications.

2. How Do Foundation Models Work?

Foundation models generally involve several stages, from training to application development.

Step 1: Data Collection and Preparation

Models are trained on large datasets containing relevant information, such as text, code, images, or other data.

The quality, diversity, and suitability of training data influence the capabilities and limitations of the resulting model.

Step 2: Model Training

During training, the model learns patterns and relationships in the data.

For example, a language model learns statistical relationships between tokens and can use those relationships to generate text.

Training large foundation models can require substantial computing resources, specialized hardware, and extensive engineering expertise.

Step 3: Model Adaptation

Once a foundation model is available, developers can adapt it to their needs using techniques such as:

  • Prompt engineering: Providing carefully designed instructions and context.

  • Fine-tuning: Further training a model on selected examples for a particular task or behavior.

  • Retrieval-Augmented Generation (RAG): Supplying relevant external information to the model at inference time.

  • Tool calling: Allowing the model to request actions from approved tools or external systems.

Step 4: Application Development

Developers integrate the model into applications such as chatbots, business assistants, search systems, coding tools, and AI agents.

The final application typically combines the model with application logic, data sources, security controls, and evaluation mechanisms.

3. Foundation Models vs. Traditional AI Development

Before foundation models became widely available, many AI projects relied on specialized models built for individual tasks.

For example, a team might develop one model for text classification, another for sentiment analysis, and another for document processing.

Foundation models offer a more reusable starting point.

Traditional AI developmentFoundation-model-based development
Often requires task-specific model developmentStarts with a pretrained general-purpose model
May require substantial labeled dataCan often begin with prompting and limited examples
Usually targets a narrower taskCan support multiple tasks
Focuses heavily on model trainingEmphasizes integration, adaptation, and evaluation
Requires task-specific maintenanceRequires model and application lifecycle management

Foundation models do not eliminate the need for traditional machine learning. Specialized models can still be more appropriate when accuracy, cost, speed, or predictable behavior are critical.

4. How Have Foundation Models Changed AI Engineering?

Foundation models have changed both the technical architecture of AI applications and the responsibilities of AI engineers.

4.1 Faster Application Development

Developers can use existing models through APIs or deploy suitable models in their own infrastructure.

This reduces the need to train large models from scratch and allows teams to focus on solving business problems.

4.2 New Application Architectures

Modern AI applications often combine a foundation model with external data, business logic, and tools.

For example, an enterprise assistant might use an LLM to understand a question, a retrieval system to find relevant documents, and an application service to enforce access permissions.

This approach enables more useful applications than relying on a model's pretrained knowledge alone.

4.3 Greater Importance of Evaluation

A working AI demonstration is not necessarily a reliable production system.

AI engineers must evaluate:

  • Answer accuracy and relevance

  • Hallucination rates

  • Response consistency

  • Latency and throughput

  • Token usage and operating costs

  • Safety and security

Evaluation must continue after deployment because model behavior, data sources, and user requirements can change.

4.4 Multimodal Applications

Modern foundation models increasingly support multiple types of input and output.

Applications can use these capabilities for tasks such as interpreting images, transcribing speech, answering questions about documents, and creating conversational voice assistants.

This allows developers to create richer user experiences without building every capability independently.

4.5 New Security and Operational Challenges

Foundation models also introduce new engineering challenges, including:

  • Prompt injection and malicious input

  • Protection of confidential data

  • Unintended or incorrect outputs

  • Model versioning and monitoring

  • Inference latency and cost management

  • Bias and responsible AI practices

Consequently, production AI engineering requires more than selecting a capable model. It requires a secure, observable, and well-tested system.

5. Practical Example: Building an AI Company Policy Assistant

Consider an organization that wants an AI assistant capable of answering employee questions about company policies.

Employees might ask questions such as:

  • How many annual leave days do I receive?

  • What is the work-from-home policy?

  • How do I submit an expense reimbursement request?

Traditional Approach

A team might build a specialized question-answering system using task-specific data, rules, or models. Updating the system as policies change could require additional development and maintenance.

Foundation Model Approach

The team can start with an existing language model and combine it with Retrieval-Augmented Generation (RAG).

A typical workflow looks like this:

  1. Store approved company policies in a document repository.

  2. Split documents into searchable sections.

  3. Convert sections into embeddings and index them in a vector database or another retrieval system.

  4. Retrieve relevant sections when an employee asks a question.

  5. Provide the question and retrieved information to the language model.

  6. Generate an answer grounded in the retrieved documents.

  7. Display appropriate source references so the employee can verify the answer.

Example architecture:

Employee Question → Application API → Document Retrieval → Foundation Model → Answer with Sources

This design can make company information easier to access while reducing the need to train a custom language model.

However, RAG does not guarantee correct answers. Engineers must validate retrieval quality, enforce document-level permissions, test for hallucinations, and monitor the system in production.

6. Important Technologies in Foundation-Model Engineering

AI engineers commonly work with several complementary techniques.

Large Language Models (LLMs)

LLMs are language-focused foundation models designed to process and generate natural language. Many can also work with code and structured information.

Retrieval-Augmented Generation (RAG)

RAG combines information retrieval with generation. It helps applications provide models with relevant external information, including information that may not have been part of their training data.

Fine-Tuning

Fine-tuning adapts a pretrained model through additional training. It can improve performance on particular tasks, formats, or behaviors when suitable data and evaluation methods are available.

AI Agents and Tool Calling

Agentic systems use models to select steps or request actions through tools. Depending on their design, they may retrieve information, call APIs, or complete multi-step workflows.

These systems need controlled permissions, validation, and limits on what actions they can take.

7. Challenges and Limitations of Foundation Models

Despite their capabilities, foundation models have important limitations.

Hallucinations: Models can generate plausible but incorrect information.

Cost: Model inference can become expensive at high usage volumes, especially for large models and long prompts.

Latency: Complex requests and large inputs may increase response times.

Privacy: Sensitive information must be handled according to the application's security and data-governance requirements.

Bias: Training data and model behavior can introduce unwanted biases.

Dependence on providers: Hosted models can involve pricing changes, rate limits, availability constraints, and version changes.

AI engineers should select models based on measured performance, business requirements, and operational constraints rather than assuming that the largest model is always the best choice.

8. The Future of AI Engineering

Foundation models are encouraging a shift from building individual predictive models toward engineering complete AI-powered systems.

Future AI engineering work will increasingly involve:

  • Designing reliable RAG pipelines

  • Building and evaluating AI agents

  • Integrating AI with existing business applications

  • Developing multimodal user experiences

  • Improving model efficiency and inference costs

  • Implementing AI security and governance

  • Monitoring quality throughout the model lifecycle

The most successful AI systems will combine model capabilities with reliable data, sound software engineering, clear evaluation criteria, and appropriate human oversight.