DEV Community

Cover image for What Happens When You Send a Message to ChatGPT ?
kundan
kundan

Posted on

What Happens When You Send a Message to ChatGPT ?

How Does ChatGPT Actually Work?

Every day, millions of people use ChatGPT to write emails, solve coding problems, summarize documents, and even learn new skills. You type a question, press Enter, and within a few seconds, ChatGPT gives you a detailed answer.

It almost feels like you're talking to another human.

The answer lies in something called a Large Language Model (LLM).


What Is an LLM?

Let's break the term down, one word at a time.

Large

"Large" doesn't mean the model is physically big. It means the model was trained on a massive amount of data — books, research papers, documentation, websites, newspapers, and more. Generally speaking, the more (and more varied) data a model is trained on, the more capable it becomes.

Language

Humans communicate through language. We ask questions, explain ideas, and share opinions. Language models are designed to recognize the patterns in that language and generate text that sounds natural.

Here's the important part: LLMs don't understand language the way humans do. They learn statistical relationships between words — which words tend to follow which other words, in which contexts.

For example, after training on millions of sentences, a model learns that in:

"I drink coffee every…"

the most likely next word is:

morning

The model isn't recalling a memorized sentence. It's recognizing a pattern it has seen play out millions of times before.

Model

A model, in this context, is simply a mathematical system trained to make predictions.

Think of it like Netflix predicting which movie you'll want to watch next based on your viewing history. An LLM does something similar with text — it predicts what word (or piece of a word) should come next, based on everything that came before it.


What Problems Do LLMs Solve?

Traditional software relies on predefined rules or exact keyword matches. LLMs work differently — they understand the intent behind your request, not just the literal words.

For example, instead of matching keywords, ChatGPT can understand a prompt like:

"Suggest a gaming phone under ₹20,000 with a good camera."

and actually reason about what "good camera," "gaming phone," and "under ₹20,000" mean together — something a simple keyword search never could.

Today, LLMs are used for:

  • Answering questions
  • Writing and debugging code
  • Translating languages
  • Summarizing documents

Some of the most popular LLMs include:

  • GPT (used in ChatGPT)
  • Claude
  • Gemini

Where Do We Use LLMs?

LLMs power a lot of tools you probably already use, including:

  • AI chatbots
  • Coding assistants
  • Content writing tools
  • Translation services

Here's a useful way to picture it: imagine someone who has read millions of books and articles. When you ask them a question, they answer using everything they've learned — not by running off to search the internet again.

An LLM works the same way. It generates a fresh response based on patterns it learned during training, instead of copying text from a website.

Now that we know what an LLM is, let's look at what actually happens the moment you send a message to ChatGPT.


What Happens When You Send a Message to ChatGPT?

Step 1: You Type a Prompt

Everything starts with a prompt — the message or question you send to ChatGPT. For example:

"Explain JWT authentication."

or

"Write a Java program to reverse a linked list."

The better and more specific your prompt, the better the response you'll get back.

Step 2: The Model Receives Your Prompt

When you hit Send, your prompt is sent to the model along with the recent conversation history. This is what gives ChatGPT context.

For example:

You: My name is Kundan.

…a few messages later…

You: What's my name?

ChatGPT: Your name is Kundan.

ChatGPT can answer correctly because your earlier message is still part of the conversation it's looking at — not because it "remembers" you across chats.

Step 3: Text Is Converted into Numbers

Computers don't understand English directly. Before ChatGPT can process your prompt, it converts your text into small chunks called tokens, which are then represented as numbers.

Step 4: The Transformer Understands the Context

Those tokens are passed to a Transformer, which analyzes how all the words in your prompt relate to one another. Instead of reading one word at a time in isolation, it looks at the entire sentence at once to understand context.

Step 5: Generating the Response

ChatGPT doesn't write a full paragraph in one go. It predicts one token at a time.

For example, given:

"The capital of India is…"

the model predicts:

New Delhi

Then it predicts the next token, and the next, and the next — repeating this process until the full answer is complete.

You type a prompt -> Sent with conversation history -> Text converted into tokens -> Transformer analyzes context -> Model predicts one token at a time -> Final response shown to you

flowchart LR
    A[You type a prompt] --> B[Sent with conversation history]
    B --> C[Text converted into tokens]
    C --> D[Transformer analyzes context]
    D --> E[Model predicts one token at a time]
    E --> F[Final response shown to you]
Enter fullscreen mode Exit fullscreen mode

Why Everything Must Be Converted into Numbers

AI models work by performing mathematical calculations. Since words aren't numbers, they need to be translated into a format the computer can actually compute with. This translation process begins with tokenization.


Tokenization

What Are Tokens?

A token is a small piece of text. It can be:

  • A whole word
  • Part of a word
  • A punctuation mark
  • Even a single character

For example:

Text Tokens
Hello Hello
Playing Play + ing
ChatGPT Chat + G + PT

Different AI models may split the same word differently depending on how their tokenizer was built.

Why Is Tokenization Needed?

Before ChatGPT can "understand" your prompt, it first converts your text into tokens. Each token is then assigned a unique token ID, which becomes the number the model actually processes.

Without tokenization, an AI model wouldn't have any way to work with language at all.

Words vs. Tokens

A common misconception is that one word always equals one token. That's not true.

Word Tokens (Example)
cat cat
cats cat + s
unbelievable un + believ + able

This is exactly why AI models measure input and output limits in tokens, not words.


Transformers

Once your text has been converted into tokens, it's passed to the Transformer — the technology behind almost every modern LLM.

What Is a Transformer?

A Transformer is a deep learning architecture introduced in 2017 in the paper "Attention Is All You Need." Its job is to figure out how all the words in a sentence relate to one another.

Why Did Transformers Change AI?

Older AI models processed text one word at a time and often "forgot" earlier words by the time they reached the end of a sentence.

Transformers introduced self-attention, which lets every token weigh its relevance against every other token in the sentence — all at once. This made AI dramatically better at understanding context.

How Does It Understand Language?

Consider this sentence:

"The trophy didn't fit in the suitcase because it was too big."

What does "it" refer to — the trophy or the suitcase?

A Transformer looks at the entire sentence at once and, using self-attention, figures out that "it" refers to the trophy, not the suitcase. This ability to resolve context is one of the biggest reasons ChatGPT feels genuinely intelligent rather than just a word-guessing machine.

Why Do Modern LLMs Use Transformers?

Models like GPT, Claude, Gemini, Llama, and Mistral all use the Transformer architecture because it:

  • Understands context better than older architectures
  • Processes text efficiently by working on all tokens in parallel
  • Scales well to billions of parameters
  • Generates natural, human-like responses

Without Transformers, modern AI assistants like ChatGPT simply not be as powerful.

Top comments (0)