DEV Community

Cover image for How ChatGPT Understands Your Questions?
Kunal
Kunal

Posted on

How ChatGPT Understands Your Questions?

While working and integrating AI into my projects for the past 2 years i never really thought about how much happens under the hood in LLMs and GPTs.

When I finally started to research about it... it was honestly overwhelming.

So let me share it in a very easy and analogy-based way. Hopefully it will help you understand how LLMs actually work under the hood and make working with AI a little easier.

Topics to Cover

  1. What is an LLM?
  2. What Happens When You Send a Message to ChatGPT?
  3. Why Computers Don't Understand Human Language
  4. Tokenization
  5. Transformers

What is an LLM

Ohh... I've used LLMs a couple of times but forgot to mention what they actually are and what they stand for.

LLM stands for Large Language Model. Let's decode each word.

Large :- Because it's trained on billions of pieces of existing data.

Language :- Because it works with human language.

Model :- A mathematical model that predicts the next output or the next piece of text.

llms

So, an LLM is a Large Language Model that takes tokens (text) as input, processes them, and predicts the next tokens as output.

Some popular examples of LLMs

GPT-5 and GPT-4 by OpenAI, 
Gemini by Google,
Claude by Anthropic, 
Llama by Meta AI. 
Enter fullscreen mode Exit fullscreen mode

Some common daily-life applications of LLMs are:

  • Chatbots like ChatGPT for answering questions
  • Writing emails, messages, and documents
  • Translating between languages
  • Summarizing long articles or PDFs
  • Coding assistants like GitHub Copilot
  • Customer support bots

This is the big overview how a LLMs work lets go a little deep what happens when you send a prompt to these llms


What Happens When You Send a Message to ChatGPT?

When you type a prompt like:

examples

Forget memory, past context and everything else for now.

The first question is...

How did the LLM guess it right?

The answer is actually very simple.

It just keeps guessing the most possible next output.

Every LLM has something called a Transformer. You can think of it as the main engine that keeps predicting the next token based on your input and the tokens it has already generated and the patterns it learned from its training data.

It keeps doing this again and again until the complete response is generated.

transformer

The whole flow should look like

  • Typing a prompt:- You type a prompt/message
  • Processing your message:- The Transformer converts your text into tokens and understands the context.
  • Generating a response:- It predicts one token at a time until the response is complete.

But have you ever noticed that Why responses are not copied from the internet ?

Instead of finding an answer from internet the model keeps predicting the next token from their trained data and patterns until it finishes the response.

But when you say hey there to Computers they are not able to perfectly understands it as they are effecient with numeric values.


Why Computers Don't Understand Human Language

So far we know that LLMs take text as input and generate text as output.

But here's the catch...

Computers don't actually understand words like "hello", "chatgpt", or "how are you?"

They only understand numbers.

So before an LLM can process your message, every word has to be converted into numbers first.

This is where tokens come in.

But how our human language converted into tokens 🤔


Tokenization

Before we start learning about Tokenization, let's first understand what tokens actually are.

Tokens are simply words (or parts of words) that are mapped to numeric values so a computer can understand and process them.

It looks something like this:

Tiktokenizer

For example:

hey  -> 48467
how  -> 1495
are  -> 553
you  -> 481
?    -> 1423
Enter fullscreen mode Exit fullscreen mode

So instead of reading "hey how are you?", the computer actually sees those numbers.

So, Tokenization is the process of converting human language into tokens (numeric values) so that computers can understand and process it.

But there is a misconception about token that they represent a whole word that actually not true.
A token can be anything a whole word, part of a word, a punctuation mark, or even a space.

Now we know a lot about tokens LLMs and how they gives us the response but how are they doing it what's the main engine behind it 🤔 ??


Transformers

Now we know how text becomes tokens and how computers understand those tokens.

But one big question is still left...

What is actually doing all this work?

The answer is Transformers.

A Transformer is the main engine behind almost every modern LLM. It's the architecture that helps the model understand your input, find relationships between words, and predict the next token.

The Transformer - model architecture

Why did Transformers change AI?

Before Transformers, AI models struggled to understand long sentences and contexts like River Banks , Money Bank

Transformers changed that by looking at the entire sentence together. This helps them understand context much better and generate more accurate responses.

How do Transformers understand language?

Transformers pay attention to every token in your sentence and figure out how they're connected. This helps them understand the meaning of your prompt instead of just reading words one by one.

Why do almost all modern LLMs use Transformers?

Because they're fast, scalable, and much better at understanding context.

That's why models like GPT, Claude, Gemini, Llama, and almost every modern LLM today are built on the Transformer architecture.


Thanks for reading! If you enjoyed this blog, you can read more here 👇

Top comments (0)