100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
HomeBlogHow Large Language Models Actually Work
AI & Technology

How Large Language Models Actually Work

SV

SkillVeris Team

AI Research Team

May 14, 2026 10 min read
Share:
How Large Language Models Actually Work
Key Takeaway

An LLM is a next-token predictor that estimates the probability of every possible next token and samples from that distribution.

In this guide, you'll learn:

  • Tokenisation splits text into sub-word pieces from a learned vocabulary, so rare words and complex languages cost more tokens.
  • Embeddings map each token to a high-dimensional vector where semantically similar tokens sit geometrically close.
  • The transformer's self-attention mechanism lets every token weigh the relevance of every other token in the context.
  • Pre-training builds base knowledge, while supervised fine-tuning and RLHF make a model helpful, harmless, and aligned.

1What Is a Large Language Model?

A large language model is a neural network trained to predict the next token in a sequence. That's it. The "large" refers to scale: billions of parameters trained on trillions of tokens of text.

The emergent result of this scale is a system that appears to understand language, reason, write, and answer questions — because predicting text at scale requires implicit models of grammar, facts, logic, and world knowledge.

Understanding what LLMs are (and aren't) makes you a better user, a better prompt engineer, and a more thoughtful AI application developer.

🔑Key Takeaway

An LLM is a next-token predictor: given a sequence of tokens, it estimates the probability of every possible next token and samples from that distribution. The magic is in the transformer architecture and attention mechanism, which let the model weigh the relevance of every previous token when predicting the next one. Training on trillions of tokens builds a statistical model of language.

2Step 1: Tokenisation

LLMs don't process characters or words — they process tokens. A tokeniser splits text into sub-word pieces according to a learned vocabulary (typically 32k–200k tokens).

The tokenisation choices have real consequences: rare words, languages with complex morphology (like Tamil or Finnish), and technical jargon may require more tokens per concept, making them relatively more expensive and less efficiently modelled than common English words.

Counting Tokens with tiktoken

Using the tiktoken library (OpenAI's tokeniser) you can see how text becomes token IDs.

code
# Using the tiktoken library (OpenAI's tokeniser)
import tiktoken
enc = tiktoken.get_encoding("cl100k_base")
text = "SkillVeris teaches coding"
tokens = enc.encode(text)
print(tokens) # [50560, 548, 285, 22816, 49625]
print(len(tokens)) # 5 tokens for 4 words
# Common words are single tokens; rare words split into sub-pieces
# "unhappy" might become ["un", "happy"]
# "SkillVeris" might become ["Skill", "Veris"]

3Step 2: Embeddings

Each token ID maps to a vector — a list of numbers (typically 768–4096 dimensions in large models) called an embedding. These embeddings are learned during training so that semantically similar tokens end up geometrically close in the embedding space.

The embedding layer is essentially a lookup table: token ID 42 maps to a specific 768-dimensional vector. Initially random; after training, the vector for "king" minus the vector for "man" plus the vector for "woman" points toward the vector for "queen" — the geometry of the embedding space captures relationships.

Embeddings as a Lookup Table

Conceptually (simplified), a sequence of tokens is converted into a matrix of vectors.

code
# Conceptually (simplified)
embedding_table = {
42: [0.21, -0.45, 0.89, ...], # 768 numbers for token 42
7: [-0.11, 0.73, 0.14, ...], # 768 numbers for token 7
}
# A sequence of 5 tokens becomes a 5x768 matrix

4The Transformer Architecture

The transformer, introduced in the 2017 paper "Attention Is All You Need," is the architecture underlying every modern LLM. A transformer consists of stacked layers, each containing several core components.

A large model like Claude or GPT-4 has 80-100+ such layers. Each pass through a layer adds nuance and context to the token representations.

The four-stage processing pipeline every LLM runs on each input: tokenise, embed, transformer layers, output probabilities.
The four-stage processing pipeline every LLM runs on each input: tokenise, embed, transformer layers, output probabilities.
  • Multi-head self-attention — lets each token "look at" all other tokens in the context and decide how much to borrow from each.
  • Feed-forward network (FFN) — applies a two-layer neural network to each position independently, adding non-linearity.
  • Layer normalisation — stabilises training by normalising activations.
  • Residual connections — add the layer's output to its input, allowing gradients to flow through deep networks without vanishing.

5Self-Attention: The Core Mechanism

Self-attention is what makes transformers revolutionary. For each token, it computes how much attention to pay to every other token in the context.

Intuitively: when processing the word "it" in "The dog chased the cat because it was fast," the attention mechanism learns to assign high attention weight to "cat" (the correct referent), solving the coreference problem implicitly.

Multi-head attention runs this process in parallel with different learned Q/K/V projections, allowing the model to attend to different types of relationships simultaneously (syntactic, semantic, positional).

  • Each token creates three vectors: Query (Q), Key (K), and Value (V).
  • For token A, the attention score toward token B = dot product of A's Query with B's Key.
  • Scores are normalised (softmax) to sum to 1 — these are attention weights.
  • Token A's output = weighted sum of all Value vectors, where weights are the attention scores.

6Feed-Forward Layers and Residuals

After attention, each token's representation passes through a position-wise feed-forward network — two linear transformations with a non-linear activation (GELU or ReLU) in between. This is where much of the model's "knowledge" is stored: the FFN weights act as a key-value memory that maps input patterns to stored facts.

Research has shown that factual recall ("Paris is the capital of France") is largely mediated by specific FFN neurons, while the attention mechanism handles contextual reasoning. Both are essential.

Residual connections add the original input to the output of each sub-layer: output = sublayer(x) + x. This ensures that information from early layers is preserved throughout the deep network and gradients can flow back without vanishing.

7How Models Are Trained

Pre-training uses self-supervised learning: no human labels are needed. The model sees a sequence of tokens, tries to predict the next one, compares its prediction to the actual next token, and updates its weights to reduce the error.

Repeated across trillions of token positions from the entire web, books, and code, this builds a rich statistical model of language and world knowledge.

Training a frontier LLM from scratch costs tens of millions of dollars in compute. This is why most AI engineers use pre-trained models via API rather than training from scratch.

  • Pre-training · Trillions of tokens, web-scraped · Predict next token
  • Supervised fine-tuning · Thousands of high-quality Q&A pairs · Follow instructions
  • RLHF · Human preference rankings · Align with human values

8RLHF: Making Models Helpful

Reinforcement Learning from Human Feedback (RLHF) is how base pre-trained models become helpful chat assistants.

RLHF is what transforms a "predict the next token" model into a model that tries to be helpful, harmless, and honest. Constitutional AI (Anthropic's approach with Claude) extends this by using the model itself to generate and rate responses against a set of principles, reducing the need for human annotation at scale.

The four key concepts that determine how LLMs behave at inference time: context window, temperature, top-p sampling, and RLHF.
The four key concepts that determine how LLMs behave at inference time: context window, temperature, top-p sampling, and RLHF.
  • Generate multiple responses to the same prompt.
  • Human raters rank the responses from best to worst.
  • Train a reward model to predict which response a human would prefer.
  • Use reinforcement learning to tune the language model to maximise the reward model's score.

9Generating Text: Sampling Strategies

When an LLM generates text, at each step it produces a probability distribution over its entire vocabulary (~50k-200k tokens). The sampling strategy determines which token is selected.

Most production APIs combine temperature and top-p. The defaults (temperature ~1.0, top-p ~0.95) produce fluent, varied, non-repetitive text for most tasks.

  • Greedy — always pick the most probable token. Deterministic but often repetitive and bland.
  • Temperature — divide logits by temperature before softmax. Temperature < 1 makes the distribution sharper (more predictable); > 1 makes it flatter (more random). Temperature = 0 is greedy.
  • Top-p (nucleus) sampling — sample only from the top-p fraction of the probability mass. E.g. top-p=0.9 samples from the smallest set of tokens accounting for 90% of probability.
  • Top-k — sample from the k most probable tokens only.

10Context Windows

The context window is the maximum number of tokens the model can process in a single forward pass. It determines how much text the model can "see" at once.

In 2026, most frontier models have 128k-200k token context windows, with some (Gemini 1.5) supporting 1M+. Larger windows enable long document Q&A without chunking, but longer contexts are slower and more expensive to process.

  • 4,096 tokens · ~3,000 words (~5-6 pages)
  • 32,768 tokens · ~25,000 words (a short novel)
  • 128,000 tokens · ~100,000 words (a full novel)
  • 1,000,000 tokens · ~750,000 words (multiple books)

11Why Scale Matters

The "scaling laws" discovered by Kaplan et al. (2020) and Hoffmann et al. (2022) showed that model performance improves predictably as you scale model size (parameters), dataset size (tokens), and compute. Beyond a certain scale, new capabilities "emerge" — the model can suddenly do arithmetic, write code, or reason in ways smaller models cannot, even without being explicitly trained for those tasks.

This is why the race to larger models matters: more parameters + more data + more compute = qualitatively better capabilities, not just marginally better. The emergent capabilities are what drive commercial value and, increasingly, safety concerns.

12Key Takeaways

The essentials to remember about how large language models work and behave.

  • An LLM is a next-token predictor: it models P(next token | all previous tokens).
  • The transformer's attention mechanism lets every token attend to every other token in context, enabling long-range reasoning.
  • Pre-training on massive text gives base knowledge; fine-tuning and RLHF make the model helpful and aligned.
  • Context window = how much the model can "see" at once; temperature = how creative vs predictable the output is.
  • LLMs don't "know" facts in the human sense — they model the statistical structure of language, which implicitly encodes facts, reasoning patterns, and world knowledge.

13What to Learn Next

Go deeper into LLMs with these follow-on topics.

  • Prompt Engineering Guide — knowing how LLMs work makes you a better prompt writer.
  • RAG Explained — how to ground LLM outputs in your own data.
  • Fine-Tuning LLMs — adapt a pre-trained model to your specific use case.

14Frequently Asked Questions

Do LLMs actually "understand" language? This is contested. LLMs process language statistically and can perform tasks that look like understanding (answering questions correctly, translating, summarising). Whether this constitutes genuine understanding in a philosophical sense is debated. Practically: LLMs are extremely useful but make errors that suggest they don't have the grounded world understanding humans do. Calibrated scepticism is appropriate.

Why do LLMs hallucinate? Hallucination happens because LLMs are trained to produce fluent, plausible text — not to retrieve verified facts. When a model doesn't "know" something, it doesn't have a reliable "I don't know" signal; instead it generates text that continues to sound plausible, which may be wrong. RAG (grounding in retrieved documents) is currently the most effective mitigation.

What is the difference between GPT-4 and Claude? Both are large transformer-based language models trained on similar datasets with RLHF-style alignment. They differ in training objectives (Anthropic uses Constitutional AI; OpenAI uses RLHF), model architecture details, context window sizes, and system prompt behaviour. Both are highly capable; differences in practice are often task-specific. Benchmark both on your actual use case rather than relying on general rankings.

Can LLMs reason? LLMs exhibit behaviour that looks like reasoning: solving multi-step maths, writing code, explaining their thinking. However, they're also prone to systematic errors on tasks that require robust logical reasoning (especially when the surface form doesn't match training distribution). Chain-of-thought prompting improves reasoning significantly. The field of "LLM reasoning" is active research — the honest answer is "sometimes, unreliably, and we don't fully understand when."

📄

Get The Print Version

Download a PDF of this article for offline reading.

About the Publisher

SV

SkillVeris Team

AI Research Team

Our AI team covers the latest in machine learning, generative AI, and emerging tech — clearly and accurately.

View all posts

Never miss an update

Get the latest tutorials and guides delivered to your inbox.

No spam. Unsubscribe anytime.

Frequently Asked Questions

21 categories · pick one to explore

Does SkillVeris have a tech blog, and what does it cover?
Yes, the SkillVeris blog has over 500 articles covering AI and machine learning, programming, web development, DevOps, cloud, security, databases and career guidance. Articles are practical and answer-first, and many use the Learn Through Hobbies approach, teaching technical concepts through cricket, music, gaming or cooking analogies. Everything is free to read.
What is the SkillVeris tech glossary and how big is it?
The SkillVeris glossary is a free reference of roughly 2,000-plus technology terms, each with a clear plain-language definition. It spans AI, programming, web, DevOps, cloud, security and database vocabulary, so whenever a lesson, article or job description uses jargon you do not recognise, the glossary gives you a fast, reliable answer.
Are the developer cheat sheets on SkillVeris free to download?
The cheat sheets are completely free to use, like everything else on SkillVeris. Each sheet condenses a language or tool into its essential syntax, commands and patterns for quick reference while coding. They are designed for rapid lookup during real work, complementing the deeper explanations found in study notes and courses.
Which programming references and cheat sheets are available?
Cheat sheets cover the platform's main domains, including programming languages, AI and ML tooling, web development, DevOps, cloud, security and databases, matching the topics of the 37 live courses. Each sheet lists related reading links and hashtags, so you can jump from a quick reference into fuller study notes or blog articles.
How do I find the meaning of a technical term quickly?
Search the SkillVeris glossary, which holds around 2,000-plus terms with concise, plain-language definitions. Each entry gets to the point in its first sentence, then links to related reading like blog posts or study notes for deeper context. It is faster and more consistent than sifting through scattered search results.
Is the SkillVeris blog good for beginners learning to code?
Yes, many blog articles are written specifically for beginners, and the Learn Through Hobbies style makes them unusually approachable: you might learn Python concepts through cricket or understand APIs through cooking. With 500-plus articles across skill levels, beginners can start with fundamentals and keep reading as they advance, entirely free.
Can cheat sheets replace full courses for learning a language?
No, cheat sheets are references, not teaching tools; they assume you already understand the concepts and just need syntax or commands fast. To actually learn a language, take a structured SkillVeris course with its 24–40 lessons and assessments, then keep the cheat sheet beside you while practising in Code Lab.
How often are new blog articles published on SkillVeris?
The blog grows regularly and already exceeds 500 articles, with new posts added as courses launch and technologies evolve. Topics track the platform's catalogue across AI, programming, web development, DevOps, cloud and security, so checking the Blog section periodically surfaces fresh tutorials, explainers and career-focused pieces, all free to read.
Does the glossary cover AI and machine learning terms?
Yes, AI and machine learning vocabulary is a major part of the roughly 2,000-plus term glossary, covering everything from foundational terms to modern concepts around LLMs, RAG and MLOps. Definitions are plain-language and answer-first, which helps when dense AI papers or course lessons throw unfamiliar jargon at you.
Are there cheat sheets for interview preparation?
Cheat sheets work well as interview-day refreshers because they compress syntax, commands and key concepts into scannable references. For dedicated preparation, combine them with the SkillVeris interview questions feature, which includes readiness scoring, plus study notes for depth. Reviewing a relevant cheat sheet just before an interview steadies recall under pressure.
Can I read the tech blog without signing up?
Yes, the blog is freely readable, and SkillVeris never charges for content. All 500-plus articles are open, covering tutorials, concept explainers and career advice. Creating a free account adds value elsewhere on the platform, like course progress tracking and certificates, but reading the blog requires no commitment at all.
How is the SkillVeris glossary different from Wikipedia?
The glossary is purpose-built for learners: definitions are short, plain-language and answer-first, sized for a quick lookup mid-lesson rather than a deep encyclopedic read. Entries also cross-link to related SkillVeris study notes, blog posts and courses, so a definition becomes a doorway into structured learning instead of a dead end.
Do blog articles use the Learn Through Hobbies method?
Many blog articles teach technical topics through hobby analogies, a hallmark of the SkillVeris blog, so you will find articles explaining programming through cricket, machine learning through music, or system design through cooking. The analogy is the teaching device; the article still delivers the real technical concept underneath.
Where can I find quick programming references while coding?
Open the SkillVeris cheat sheets, which are built exactly for that moment: compact, scannable references for syntax, commands and common patterns across languages and tools. Keep the relevant sheet in a browser tab while you work in Code Lab or your own editor, and dip into the glossary for terminology.
Is there a glossary entry for terms I meet in job descriptions?
Very likely yes, with roughly 2,000-plus terms across AI, programming, web, DevOps, cloud, security and databases, the glossary covers most jargon that appears in tech job descriptions. Decoding a listing this way helps you judge role fit honestly and prepares you to discuss those terms in interviews.
Are the blog articles written for the Indian tech audience?
The blog serves Indian learners plus a worldwide audience. Content stays globally relevant while acknowledging realities that matter in India, such as free access being essential for students and freshers, and career guidance that connects naturally to the SkillVeris jobs portal, which aggregates roles across India, UK, USA, Germany and Remote.
Can I suggest a topic for the blog or glossary?
SkillVeris content grows in response to what learners need, so feedback is welcome through the platform's support channels. If a term is missing from the glossary or a topic deserves an article, telling the team helps prioritise it. Meanwhile, the AI Mentor can answer the question immediately, 24/7, at any depth.
Do cheat sheets and glossary entries link to deeper learning?
Yes, every cheat sheet and glossary entry carries related reading links into study notes, blog articles and courses, plus concept hashtags for discovering similar content. This cross-linking means a thirty-second lookup can smoothly become a structured learning session whenever you decide you want more than a quick answer.
What makes SkillVeris programming references trustworthy?
The references are written to strict internal quality standards, kept consistent with the platform's 37 live courses, and never padded with invented statistics or hype. Definitions and cheat sheets are reviewed against the same content contracts that govern courses, and the answer-first style makes any inaccuracy easy to spot and correct.
How do the blog, glossary and cheat sheets fit into my learning routine?
Use them as satellites around your main course: read blog articles for context and motivation, hit the glossary the instant jargon appears, and keep cheat sheets open while coding. Together with study notes, Code Lab and the 24/7 AI Mentor, they turn passive reading into a complete, free learning system.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse