A chatbot can answer a question in seconds, but it builds that answer one small piece of text at a time. You might ask, “What should I pack for a rainy hike?” and get a useful-sounding list. The software does not simply look up a finished answer. It uses patterns learned from text to form a response.
This beginner-friendly explanation follows the path from your prompt to the words on your screen. It shows how artificial intelligence and machine learning help a model handle language. You will also get a clear way to think about why a fluent response can still need a closer look.
Key Takeaways
- A model learns patterns from large amounts of text.
- It processes text as small pieces called tokens.
- It uses context to predict what text should come next.
- Training shapes how the model responds to prompts.
- A fluent answer can still contain errors.
- Human judgment helps you use responses with care.
A useful way to understand the process is to follow the text from a prompt to a predicted response.
A Simple Walkthrough: How Do Large Language Models Work?
An LLM produces text by predicting one token at a time from the text that came before it. Each step uses patterns learned during machine learning, rather than a stored answer for every question.
Large language models estimate which token or sequence is likely in a given context. A token is a machine-readable unit of text that may be a word, part of a word or a character. For example, after “The dog chased the,” a model may predict “ball” because that continuation often fits.

Artificial intelligence is the broader field, while machine learning is one way to build AI systems. The best description of AI is software that performs tasks linked with human abilities, such as understanding language. AI can also use fixed rules, so it does not always learn from data.
A language model estimates the probability of tokens or token sequences based on context. Neural networks, which are computing systems made of connected units, help learn those patterns. The term intelligence does not mean the model thinks like a person.
A visual explanation of how LLMs work can follow this path: prompt text, numerical representations, contextual processing, next-token prediction, then repeated output. A beginner’s guide to LLMs explains how this fits within broader AI concepts.
A plausible continuation is not the same thing as a verified fact.
The model’s likely next word may sound natural without matching the world. That gap matters when you use an answer to make a choice or share information.
The important distinction is that a plausible continuation is not the same thing as a verified fact.
How Does Text Become Something a Model Can Process?
Before a model can work with a sentence, it splits the text into tokens and represents each token as numbers. That conversion lets a neural network process words as data.
A token is a machine-readable unit of text that may be a word, part of a word or a character. Tokenization can turn a common word into one token, while an uncommon word may split into several subwords. A token count, then, does not match a word count exactly.

The model maps each token to an embedding, a learned numerical vector. An embedding represents patterns in how a token relates to other text. It is not a fixed dictionary definition, and its meaning can shift with context.
Positional encodings add information about where tokens appear in a sequence. Without that order, “the cat chased the dog” could be hard to distinguish from “the dog chased the cat.” Position helps preserve which word came first and how the sentence is arranged.
For English, one token is about four characters or three-quarters of a word. Punctuation, uncommon terms, and other languages can change that rough rate. A short phrase may use more tokens than its word count suggests.
For a rough English estimate, 400 tokens are about 300 words, but tokenization varies with the text and language.
How Does Transformer Attention Use Context?
In “the bank raised its rates,” the words around “bank” help indicate a financial meaning rather than a riverbank. Self-attention lets a Transformer relate tokens across a sequence, including words that sit far apart.
Attention gives a token a way to weigh useful information from other tokens. The Transformer architecture was introduced in 2017 in the paper “Attention Is All You Need.” Its design made context a central part of language processing.

What self-attention calculates
Self-attention uses query, key, and value vectors to calculate relationships. A query is what a token is seeking. A key is the information a token offers, while a value is the information that can be weighted into another token’s representation.
For “the bank raised its rates,” the query for “bank” can give more weight to words like “raised” and “rates.” Those clues point toward a financial institution. A sentence about a river might give attention to “shore” or “water” instead.
An interactive Transformer explanation lets you see how attention relates token representations. It offers a visual way to follow the calculations without treating each word as an isolated item.
How layers build a contextual representation
Transformer layers refine token representations, adding context at each stage. Positional information helps the layers keep track of order, so a model can use both word identity and sentence structure.
A hidden layer is an intermediate neural-network layer between its input and output. Several such layers can build a richer representation of a sentence, though the exact design differs across models.
Standard full self-attention has computational complexity O(n²), where n is the sequence length. If the sequence doubles, attention calculations can grow by about four times. That quadratic cost makes very long sequences computationally demanding.
Self-attention can use distant context, but processing longer sequences with full attention takes more computation.
How Are Large Language Models Trained and Refined?
Pretraining teaches a model patterns by repeatedly comparing its prediction with the next token in its training text. Repeated practice helps it learn language patterns from books, articles, websites, code, and other text.
Training changes the model’s weights, the internal values that shape its predictions. Large training corpora can contain billions or trillions of words. A loss function measures how far a prediction is from the expected token.

Pretraining learns patterns from unlabeled text
During pretraining, the model predicts a token that already appears next in a text sequence. Backpropagation and gradient descent use the loss to adjust weights and reduce prediction errors over time.
This is self-supervised learning because the text provides its own training target. People do not need to label every line with a separate answer. The model learns broad patterns from the examples it processes.
The original GPT approach used a Transformer trained on unlabeled text, then adapted it to labeled tasks. The GPT pretraining paper describes that approach.
Supervised fine-tuning adapts responses
Supervised fine-tuning uses a smaller labeled dataset to guide a model toward specific tasks. Human-written demonstrations can show the format and style of a useful response.
For example, examples of summaries can teach a general model to shorten reports. Other labeled examples can help it handle classification or customer support. Fine-tuning adapts an existing model instead of building one from scratch.
A step-by-step guide to training an AI model explains how task examples can shape a model. Careful testing on new examples helps reveal whether the changes work beyond the training set.
Human feedback ranks preferred answers
Reinforcement learning from human feedback, or RLHF, uses human rankings to guide which answers a model should prefer. Those rankings can train a reward model, which scores responses and helps steer later optimization.
In a 2022 OpenAI study, labelers wrote demonstrations for supervised fine-tuning, then ranked responses for RLHF. On that study’s prompt distribution, evaluators preferred a 1.3-billion-parameter InstructGPT model over a 175-billion-parameter GPT-3 model. InstructGPT had 100 times fewer parameters.
The result applies to that study’s prompts, not every task or model. It shows that model size alone does not set the response people prefer.
The InstructGPT comparison shows why instruction quality and human preferences can matter alongside parameter count.
How Does an LLM Generate an Answer?
Once trained, a model generates an answer by choosing a token, adding it to the sequence and predicting again. This process is called inference, or generating output with a trained model.
The model repeats its next-token choice until it stops or reaches its output limit. It first calculates a probability distribution, which gives possible next tokens different likelihoods.
- Tokenize and process the prompt.
- Calculate probabilities for the next token.
- Select a token from the available choices.
- Append it to the sequence and repeat until the model stops or reaches its output limit.
The model may choose the most likely token or sample from several likely options. Sampling can make responses less predictable. A setting called temperature can affect how varied those choices are.
The model can use only the text that fits in its context window, the maximum number of tokens it can use at once. If an application adds retrieved documents or earlier conversation text, that material must fit too.
Context windows and limits can differ by model or endpoint. For example, an API setup guide for Mistral Large 4 lists different token limits for its Mistral and OpenRouter endpoints.
A prompt that exceeds the context window cannot all guide the same generation at once.
What Are the Main Types of LLM Architecture?
An encoder-only model such as BERT is suited to understanding an input, while a decoder-only model such as GPT is built to generate text. Encoder-decoder models use both parts to turn input into a new form.
These are Transformer architecture types, not a ranking of models. Each arrangement supports different ways to process text, so the useful choice depends on the task.
Encoder-only models read the full input
BERT reads a full input to build context from words on both sides of a token. It uses masked language modeling, which means it learns to predict tokens hidden in an input sequence.
This design suits tasks that label or identify parts of text. BERT can support classification, such as sorting feedback by topic, and named-entity recognition, such as finding names or places in a sentence.
Decoder-only models predict what comes next
GPT predicts from preceding tokens, which suits text generation. It can continue a prompt, draft a passage, or produce code in response to an instruction.
Decoder-only models process earlier text to decide what can follow. They are often used when the output needs to grow one piece at a time.
Encoder-decoder models transform input into output
An encoder-decoder model first interprets the input, then uses a decoder to create an output. BART and T5 are examples used for tasks such as translation and summarization.
The encoder can represent the source text as a whole, while the decoder forms a new sequence. This arrangement fits tasks where the output needs to restate or convert the input.
| Architecture type | Example models | How it processes text | Suitable tasks |
|---|---|---|---|
| Encoder-only | BERT | Full input context; masked-token training | Classification; named-entity recognition |
| Decoder-only | GPT | Predicts from preceding tokens | Text generation |
| Encoder-decoder | BART; T5 | Encoder reads input; decoder creates output | Translation; summarization |
Choose the architecture by whether a task needs input analysis, continuation or a generated transformation.
How Are GPT, an LLM, and ChatGPT Different?
LLM names describe different things: LLM is the broad category, GPT is a model family and ChatGPT is an application. The names are related, but they do not mean the same thing.
Model versions and product names should not be treated as interchangeable. GPT models belong to the wider group of language models, while ChatGPT is a service that uses them.
GPT-1 appeared in 2018 as a Transformer pretrained to predict the next token. GPT-2 followed in 2019 with 1.5 billion parameters, trained on WebText, a 40-gigabyte dataset containing 8 million web pages.
GPT-3 arrived in 2020 with 175 billion parameters. GPT-4 was released on March 14, 2023. Its default context window was 8K tokens, with a special API version supporting up to 32K tokens.
GPT-4 Turbo was announced in November 2023 with a 128K-token context window. Those figures belong to specific versions, not every product that uses the GPT name.
| Model | Year or date | Parameter count | Distinguishing detail |
|---|---|---|---|
| GPT-1 | 2018 | Not provided | Pretrained next-token prediction |
| GPT-2 | 2019 | 1.5 billion | WebText: 40 GB; 8 million pages |
| GPT-3 | 2020 | 175 billion | Large decoder-only model |
| GPT-4 | March 14, 2023 | Not provided | 8K default; special API version up to 32K tokens |
| GPT-4 Turbo | November 2023 | Not provided | 128K-token context window |
Check the specific model version when a context-window figure matters, since the GPT family has changed over time.
What Can LLMs Do, and How Can You Adapt Them?
An LLM can draft an email, summarize a report or help debug code because the same text model can be prompted for different tasks. Clear instructions help shape the kind of content it returns.
Prompts, retrieval and fine-tuning affect responses in different ways. Prompt engineering guides a response without changing model weights, while fine-tuning changes weights using task-specific examples.
Common tasks include writing, analysis and code
LLMs can work with text in several practical ways. One model may handle these different tasks when you give it a clear prompt:
- Draft or edit text, such as an email or short post.
- Summarize a long report into key points.
- Generate code or help debug a program.
- Classify text or extract details from a document.
- Translate text between languages.
Prompts and retrieval add task-specific context
Retrieval-augmented generation, or RAG, adds relevant outside information to a prompt without retraining the model. A weather service could retrieve the latest forecast before asking an LLM to explain it.
The retrieved text still needs to fit within the context window. Fine-tuning takes another route: it uses task examples to change model weights, but does not automatically retrieve new facts.
| Approach | Changes model weights | Adds outside information at response time | Typical use |
|---|---|---|---|
| Prompt engineering | No | Only if included in the prompt | Guide a task or format |
| RAG | No | Yes, retrieved material | Use current or domain-specific information |
| Fine-tuning | Yes | No automatic retrieval | Adapt behavior to examples |
A guide to foundation models explains how broad models can be adapted for narrower work. You can also use practical AI model tips to shape task instructions and output formats.
Use retrieval when an answer depends on changing information that was not part of the model’s training.
What Are the Limits of Large Language Models?
A confident-sounding answer can still be false because the model predicts plausible text rather than checking every claim against the world. Fluent wording is not proof that a statement is true.
Hallucinations are false or misleading outputs that can sound plausible. Next-token probability helps a model form likely text, but it does not act as a fact-checking system.
Plausible answers can still be wrong
When a response includes a date, name, or number, treat it as a claim to check. A smooth explanation can mix correct details with an error, which makes careful review important.
- Verify important factual claims.
- Check calculations and sources independently.
- Keep human review for high-stakes decisions.
Training data and computing bring risks
Training data can contain social biases, and a model may reflect or amplify them in its responses. The effect can vary with the data, prompt, and task.
Training and running large models require computing power and energy. Developers use red-teaming to probe models for unsafe or biased responses before or during use.
The NIST AI Risk Management Framework offers a way to organize AI risk work. It does not remove the risks, so people still need to judge how a system is used.
Treat an LLM response as a draft to verify, especially when a decision carries real consequences.
A NIST framework can help teams plan risk checks, but it cannot guarantee that every response will be safe or accurate.
Conclusion
The simplest mental model is that an LLM learns text patterns and uses them to build a response one token at a time. Its usefulness depends on the context it receives and the judgment you bring to its output.
Try a low-stakes prompt, such as asking for a short packing list. Request a specific format, then check one factual claim in the answer.
Try that process on a low-stakes question, then check whether the answer’s key fact holds up.
FAQ
Can you explain what an LLM is?
An LLM is a model trained on text patterns to process and generate language, often by predicting the next token. It learns how pieces of text tend to fit together across many examples. That lets it respond to prompts in different styles and formats. It does not mean the model understands each answer as a person would.
What are the foundations of large language models?
Large language models build on machine learning, neural networks, large-scale text training, and Transformer architecture. Machine learning lets the system adjust its internal weights from data. Neural networks process numerical representations, while Transformers help connect words across a sequence. Training gives the model patterns that it can use to respond to new text.
What is the difference between GPT and LLM?
An LLM is a broad category of language models, while GPT is one model family within that category. The name GPT refers to a series of models built to process and generate text. Other LLM families use different designs or training choices. ChatGPT is a product name, not another term for every LLM.
Is ChatGPT machine learning?
Yes. ChatGPT is an application powered by machine-learning models, including GPT models. Those models learn patterns from data during training, then generate responses when you send a prompt. The application can also include product features around the model. Its name refers to the chat service, not one fixed model version.
Can AI exist without ML?
Yes. Rule-based AI can follow explicit instructions without learning patterns from data. For example, a system can apply set rules to sort a request or route it to a service. Machine learning is one part of artificial intelligence, not the only way to build an AI system.
How many hidden layers does ChatGPT have?
There is no single hidden-layer count for the ChatGPT product. ChatGPT can use different underlying models and versions, and exact architecture details are not consistently published. A hidden layer is an intermediate neural-network layer that transforms information. The count belongs to a specific model design, not to the product name as a whole.
What is the architecture behind ChatGPT?
ChatGPT uses GPT models, which are decoder-only Transformers, though the exact deployed model can vary by version. A decoder-only model predicts text using the tokens that came before. ChatGPT is the application people use to interact with those models. Product features and available models may change over time.
What is a hidden layer in a neural network?
A hidden layer is an intermediate layer between a neural network’s input and output layers. It transforms numerical representations as information moves through the network. A model can use many hidden layers to build more complex representations. The number and design of those layers depend on the specific model.


