ShopySquares
- Home
- United Kingdom
- London
- ShopySquares
Read. Learn. Grow. I’m "Elsayed Zewayed", founder of ShopySquares. Everything here is designed to be simple, usable, and built for real-world results.
(4)
Ebooks, templates, and digital tools plus engineering consulting, document drafting, SEO services, and business setup (companies, stores, banking).
📚 Shopysquares.com where knowledge meets imagination. I build practical digital products eBooks, templates, and ready-to-use models alongside consulting services that help individuals and businesses grow with clarity and structure. My work focuses on S
EO and content strategy (plans, audits, and execution), professional writing (articles and marketing content), and engineering documentation (technical templates, contract-ready documents, and structured project records). I also support founders with business setup services, including UK company formation guidance and launch documentation.
22/08/2026
Every AI response begins with a hidden engineering pipeline: text becomes tokens, tokens become vectors, vectors pass through Transformer layers, and the model predicts what comes next.
This book opens that pipeline.
You will build a decoder-only AI-Model step by step in modern C++, studying tokenization, embeddings, causal self-attention, RoPE, RMSNorm, feed-forward networks, training loss, AdamW, checkpoints, KV cache, sampling, and chat inference.
The goal is not simply to make the code run.
The goal is to understand why it works.
https://shoponetime.com/product/create-ai-model-pure-c-transformers
22/08/2026
The Equation That Taught Machines to Pay Attention............................................................................................................
For most of human history, intelligence belonged to living things.
A child learned language by listening. A scientist formed ideas by connecting facts. A writer remembered the beginning of a sentence while choosing the words that would end it. Human thought depended on memory, association, context, and attention.
Computers were very different.
They were excellent at arithmetic, terrible at ambiguity, and completely dependent on instructions written by people.
Then something changed.
Not because a machine suddenly became conscious. Not because engineers discovered a secret formula for intelligence. And not because computers began thinking like humans.
The change came from a new way of letting machines decide which pieces of information matter most to other pieces of information.
That idea became known as attention.
And one equation helped change the direction of artificial intelligence.
[
Attention(Q,K,V)=softmax\left(\frac{QK^T}{\sqrt{d_k}}\right)V
]
To a non-specialist, this may look like a small collection of letters and mathematical symbols.
In practice, it became one of the central mechanisms behind modern AI language models.
To understand why, we need to begin with a simpler question.
What Is an AI Model Actually Doing?
Imagine typing this sentence into a language model:
“The engineer opened the server room because the system was…”
A human reader immediately expects a word such as:
“overheating,”
“offline,”
“failing,”
or perhaps “unstable.”
A language model does something much less mysterious than most people imagine.
It predicts what token is most likely to come next.
That is the core idea.
The model does not begin with a dictionary of thoughts. It does not search its memory for a stored answer. It receives a sequence of tokens and calculates probabilities for the next one.
The entire process can be simplified like this:
Text → Tokens → Numbers → Vectors → Transformer Layers → Probabilities → Next Token
Then the new token is added to the sequence, and the process starts again.
Again.
And again.
This repeated prediction is what produces paragraphs, explanations, code, stories, and conversations.
The remarkable part is not that the machine predicts the next token.
The remarkable part is how much structure it can learn while learning to do that.
First, Words Must Become Numbers
Computers do not understand the word “engineer.”
They understand numbers.
So the sentence:
“The engineer opened the door.”
might first become a sequence such as:
[412, 7812, 93, 551, 18]
These numbers are called token IDs.
A tokenizer decides how text is divided.
Sometimes one word becomes one token.
Sometimes a long word becomes several.
Punctuation can become its own token. Common fragments may receive their own IDs. In multilingual systems, Arabic, English, numbers, symbols, and code may all share the same vocabulary.
But token IDs are still only labels.
Token 412 is not mathematically similar to token 413 merely because the numbers are close.
So the model transforms each token ID into a vector.
A vector might contain hundreds or thousands of floating-point values.
Instead of representing a word as:
412
the model may internally represent it as something conceptually like:
[0.13, -0.42, 0.71, 0.08, ...]
This is called an embedding.
The embedding gives the model a numerical space in which relationships can be learned.
Words used in similar contexts can develop related representations.
Technical terms can cluster around other technical terms.
Grammatical patterns can emerge.
But embeddings alone are not enough.
A model must understand context.
And context is where attention changed everything.
The Problem Before Attention
Earlier sequence models often processed language step by step.
They read one token, updated an internal state, then read the next.
This was useful, but long sequences were difficult.
Imagine someone whispering a 300-word paragraph into your ear one word at a time, while you are allowed to preserve the whole paragraph only by repeatedly compressing everything you remember into a single mental state.
Important details from the beginning may weaken by the time you reach the end.
Computers faced a similar problem.
Researchers needed a better way for each token to examine the other relevant tokens in the sequence directly.
Attention provided that mechanism.
A Sentence Walks Into an Attention Layer
Consider:
“The animal did not cross the street because it was tired.”
What does “it” refer to?
The street?
The animal?
Humans resolve this using context.
An attention mechanism allows a model to learn which earlier words are relevant to the current position.
But the model does not ask this question using ordinary language.
It creates three mathematical representations for each token:
Query
Key
Value
Usually written:
Q, K, V
These are created through learned linear transformations.
In code, the idea looks something like:
auto q = query_projection(x);
auto k = key_projection(x);
auto v = value_projection(x);
where x represents the current hidden states.
You can think of them loosely like this:
A Query asks:
“What information am I looking for?”
A Key says:
“What kind of information do I contain?”
A Value says:
“If I am relevant, this is the information I can contribute.”
This is only an analogy, but it is useful.
Now the model compares Queries with Keys.
That comparison is done with dot products.
The famous attention equation begins to make sense:
[
QK^T
]
The Query matrix is multiplied by the transposed Key matrix.
The result is a table of scores.
Every position receives a score describing how strongly it relates to other positions.
The model has created something like a relevance map.
Why Divide by the Square Root?
The equation does not stop at:
[
QK^T
]
It divides the scores by:
[
\sqrt{d_k}
]
where (d_k) is the dimension of each Key vector.
Why?
Because as vector dimensions grow, dot products can become numerically large.
Large numbers passed into softmax can produce extremely sharp probability distributions and unstable gradients.
The division controls the scale.
It is a small mathematical adjustment with an important practical effect.
This is one of the beautiful things about modern AI engineering: enormous systems are often stabilized by details that look almost trivial on paper.
Then Softmax Enters the Story
The raw attention scores are not yet probabilities.
They may be positive, negative, large, or small.
Softmax transforms them into values that sum to one.
Conceptually, the model might produce:
animal 0.62
street 0.08
cross 0.05
tired 0.19
other 0.06
Now attention weights can be used to combine the Value vectors.
That is the final part of:
[
Attention(Q,K,V)=softmax\left(\frac{QK^T}{\sqrt{d_k}}\right)V
]
The model is effectively saying:
“For this token, gather more information from these positions and less from those positions.”
That happens for every relevant position.
And not just once.
Modern Transformers use multiple attention heads.
Why Multiple Heads?
One attention head might learn relationships related to grammar.
Another may focus on names.
Another may become sensitive to local phrase structure.
Another may learn long-distance relationships.
Another might detect code syntax.
No engineer manually assigns those jobs.
Training discovers useful patterns.
Suppose the hidden dimension is 768 and there are 12 attention heads.
Then one simple arrangement gives each head:
[
768 / 12 = 64
]
features.
Each head operates over a different learned projection of the same sequence.
Their outputs are then combined.
This gives the model multiple ways of examining the same context.
That idea was one of the reasons Transformers became so powerful.
But Language Generation Needs a Rule: Never Look Into the Future
There is another important detail.
Suppose we train the model on:
“Artificial intelligence is changing software.”
When predicting “changing,” the model must not be allowed to read “software” from the future.
Otherwise, the exercise becomes cheating.
So decoder-only models use a causal mask.
Imagine the token positions as a table:
1 2 3 4
1 ✓ X X X
2 ✓ ✓ X X
3 ✓ ✓ ✓ X
4 ✓ ✓ ✓ ✓
Position 1 can see only itself.
Position 2 can see positions 1 and 2.
Position 3 can see 1, 2, and 3.
And so on.
This allows training to happen efficiently across an entire sequence while preserving the logic of next-token prediction.
A broken causal mask can produce a model that appears to train well while secretly seeing information it should not have.
This is why serious AI development requires testing, not only equations.
Attention Was Only the Beginning
Attention alone is not the complete Transformer.
The output moves through additional components.
There are normalization layers.
Residual connections.
Feed-forward networks.
Modern variants may use RMSNorm, SwiGLU, rotary position embeddings, grouped-query attention, and other refinements.
A simplified decoder block looks like:
Input
↓
Normalization
↓
Attention
↓
Residual connection
↓
Normalization
↓
Feed-forward network
↓
Residual connection
The block is repeated many times.
Maybe 12 layers.
Maybe 32.
Maybe 80 or more.
Each layer transforms the representation slightly.
Information becomes increasingly contextual.
By the end, the final hidden state is projected into vocabulary-sized logits.
If the vocabulary contains 50,000 tokens, the model may produce 50,000 scores for the next position.
The tokenizer and model vocabulary must agree.
If they do not, the entire system becomes inconsistent.
Where Does Learning Come From?
At first, the model weights are mostly random.
Its predictions are poor.
Training changes them.
Suppose the correct next token is:
“system”
but the model predicts high probability for:
“banana.”
A loss function measures how wrong the prediction is.
For next-token language modeling, this is commonly cross-entropy.
If the correct token receives probability (p), a simplified expression is:
[
L=-\log(p)
]
High probability for the correct answer means low loss.
Low probability means high loss.
Then backpropagation calculates how each parameter contributed to the error.
An optimizer such as AdamW updates the weights.
The process repeats across enormous amounts of text.
Forward pass.
Loss.
Backward pass.
Weight update.
Again.
Again.
Again.
Over time, the model learns statistical structure.
Grammar.
Association.
Style.
Facts present in the data.
Patterns of reasoning.
Patterns of code.
Not because someone explicitly programmed every rule, but because the optimization process shaped millions or billions of parameters toward better prediction.
Why Did Attention Change the World?
The real historical impact of attention was not just that it improved one equation.
It changed the architecture of sequence learning.
Transformers made it possible to process many positions in parallel during training.
That was a major advantage over strongly sequential architectures.
Parallel processing matched modern GPUs extremely well.
Larger datasets became practical.
Larger models became practical.
Longer training runs became practical.
Then scaling began to reveal unexpected capabilities.
Language models became better at translation.
Then summarization.
Then question answering.
Then programming.
Then reasoning-like tasks.
Then multimodal systems began connecting text with images, audio, and video.
The same central idea remained:
Let information dynamically decide which other information deserves attention.
That idea moved from a mathematical mechanism to an industrial foundation.
Today it influences search engines, assistants, coding tools, scientific software, translation systems, education platforms, business automation, and creative applications.
Attention did not single-handedly create the AI revolution.
Hardware mattered.
Data mattered.
Optimization mattered.
Software libraries mattered.
Research culture mattered.
But attention provided an architecture that allowed all of those forces to combine at scale.
The Most Surprising Part
Perhaps the most surprising fact about modern AI is that once you look inside it, the magic does not disappear.
It changes form.
You do not find a tiny artificial person living inside the machine.
You find matrices.
Vectors.
Probability distributions.
Gradient updates.
Memory buffers.
C++ or Python code.
GPU kernels.
Datasets.
Checkpoints.
And an enormous number of carefully connected mathematical operations.
Yet from those operations emerges language.
That is the part worth thinking about.
The extraordinary achievement of modern AI is not that engineers discovered a single equation for intelligence.
They discovered architectures in which simple mathematical operations, repeated at huge scale and trained on rich data, can produce behavior that begins to resemble abilities we once believed required entirely different kinds of machinery.
Attention became one of the most important pieces of that architecture.
A Query asks.
A Key offers a match.
A Value carries information.
Softmax decides how much each source matters.
And a Transformer repeats this process again and again until relationships between tokens become relationships between ideas.
That small mathematical mechanism helped move artificial intelligence from systems that processed sequences awkwardly into models that can write, explain, translate, code, summarize, and converse.
The equation itself fits on one line.
Its consequences are still unfolding.
And perhaps that is the most remarkable lesson of all:
Sometimes the ideas that change the world do not begin by looking enormous. They begin as a better way of deciding what deserves attention.
find all details in New Book... https://shoponetime.com/product/create-ai-model-pure-c-transformers
22/08/2026
Inside Pure C++ Transformers: A Critical Look at a Book That Treats the AI-Model as an Engineering System
There is a familiar pattern in books about artificial intelligence. The first chapter explains neural networks, the second introduces attention, somewhere in the middle appears the famous Transformer diagram, and eventually the reader is shown how to load a pretrained model.
That approach is useful, but it often leaves an uncomfortable gap.
You may finish the book knowing what a Transformer is supposed to do without knowing what it takes to make one behave correctly as software.
Pure C++ Transformers: Design, Tokenize, Train, Optimize, and Deploy a Decoder-Only Language Model from First Principles takes that gap seriously.
Its central idea is not particularly flashy: an AI-Model should be treated as an engineered system rather than a mysterious mathematical object.
That distinction turns out to affect almost every chapter.
The book does explain attention, embeddings, tokenization and training, but it repeatedly asks a second question after explaining the mathematics:
How do you know that your implementation is actually correct?
That question is where the book becomes interesting.
One of the strongest ideas in the book appears very early.
A model compiling successfully does not prove that it is mathematically correct.
Even a falling training loss does not prove that the implementation is correct.
Consider causal attention.
In a decoder-only language model, a token at position 5 must not be allowed to read the token at position 6 while predicting it. If the causal mask is incorrect, the model can effectively see part of the answer during training.
The program may still compile.
The GPU may remain busy.
The loss may even decrease impressively.
Yet the experiment is invalid.
The book therefore proposes a simple but powerful test: change a future token and verify that logits at earlier positions do not change.
That is a very different teaching philosophy from merely showing this equation:
Attention(Q,K,V)
softmax\left(
\frac{QK^T}{\sqrt{d_k}} + M
\right)V
]
The equation tells us what attention should calculate. The test tells us whether the software actually respects that equation.
This emphasis on evidence appears throughout the book.
Full-sequence inference is compared with KV-cached inference. Continuous training is compared with resumed training. Parameter estimates are compared with the number of parameters actually instantiated by the model.
The result is a book that treats verification as part of AI development rather than something to think about after the interesting work has finished.
Another useful section begins with something as ordinary as a tensor shape.
Suppose a tensor is:
[4, 512, 256]
It is tempting for a beginner to see three numbers and move on.
The book refuses to do that.
Those dimensions may represent a batch of 4 sequences, each containing 512 positions, with each position represented by a 256-dimensional hidden vector.
Now suppose there are eight attention heads.
The head dimension becomes:
256 / 8 = 32
That calculation is elementary. Its consequences are not.
Query tensors must be reshaped correctly. Key and Value tensors need compatible dimensions. A transpose changes the logical layout. Some operations produce non-contiguous tensors. RoPE requires an even head dimension because it rotates features in pairs.
Then device and datatype rules enter the picture.
Token IDs should remain integer indices. Activations are floating point. A causal mask created on CPU cannot simply be applied to an attention-score tensor living on CUDA. Converting a model to BF16 does not mean token identifiers should suddenly become BF16.
These details rarely appear on the cover of an AI book, yet they are exactly the details that decide whether a native implementation works.
The C++ approach helps here because the reader is forced to confront those boundaries rather than treating them as invisible infrastructure.
I was pleased to see that the book avoids one of the easiest marketing claims it could have made.
It does not argue that C++ automatically makes Transformers faster than Python.
That would be misleading.
The expensive matrix multiplications and GPU kernels used in modern frameworks are already native code. Calling the same optimized operation from Python or C++ does not magically change the underlying arithmetic.
Instead, the book argues for C++ on the grounds of control.
Build configuration becomes visible.
Native dependencies become visible.
Memory and device placement become visible.
Packaging becomes visible.
The application can integrate directly into another native product without placing a Python interpreter in the middle.
This is also why the book uses LibTorch rather than pretending that “from first principles” requires manually reimplementing matrix multiplication, CUDA kernels and automatic differentiation.
That is an important distinction.
The Transformer architecture remains explicit. Query, Key and Value are still constructed by the reader. RoPE, masking, residual paths, logits and KV-cache behavior are visible. LibTorch supplies the numerical machinery that already has mature implementations.
That is a pragmatic compromise between educational transparency and unnecessary reinvention.
The worked studies are probably where the book's engineering philosophy becomes easiest to see.
One example starts with a workstation rather than with an abstract architecture.
Assume roughly:
16 GiB of system RAM, a modern Windows machine and an optional NVIDIA GPU with only 4 GiB of VRAM.
Instead of saying “choose a small model,” the book develops an actual candidate:
vocabulary: 16,000
context: 1,024
hidden dimension: 384
decoder layers: 12
query heads: 6
KV heads: 2
feed-forward width: 1,024
tied embeddings
Immediately, the reader can start reasoning about cost.
Increasing the vocabulary from 16K to 20K does not merely give the tokenizer more pieces. With a hidden dimension of 384, that increase adds 1,536,000 tied parameters.
That means vocabulary design is no longer an isolated NLP decision. It changes model memory.
The study also demonstrates why “the weights fit in VRAM” is an inadequate way to judge whether training will fit.
Weights are only one part of training memory.
There are gradients, optimizer moments, activations and attention workspaces.
For a sequence length of 1,024, even one conceptual FP32 attention-score tensor can become large enough to matter. Increase the batch and the memory pressure rises quickly.
The recommendation is therefore deliberately conservative: qualify with batch 1, measure actual peak memory, run a tiny number of real updates, produce a checkpoint, reload it, generate text, test resume, and only then decide whether a larger run is justified.
That is far more useful than a generic table saying that a certain GPU “should” train a certain model.
The 100M-class study continues that realism.
Its reference configuration uses a 32,000-token vocabulary, 2,048-token context, hidden width 768, twelve layers, twelve query heads, four KV heads and a 2,048-wide feed-forward network.
The interesting part is not the parameter count itself.
The interesting part is what happens next.
The book examines memory, attention cost, KV-cache size, token budgets and checkpoint storage.
It gives a surprisingly practical storage example: if a complete checkpoint were around 1.6 GiB and one were saved every thousand updates during a 100,000-update run, keeping every checkpoint could consume roughly 160 GiB.
Suddenly checkpoint retention becomes an engineering policy rather than a checkbox.
Keep the latest few.
Keep selected historical checkpoints.
Keep milestones.
Keep good validation checkpoints.
Do not delete the previous good state until the newer checkpoint has successfully reloaded.
There is also an important sentence in this chapter that captures the book's tone:
A 100M parameter count is not a quality certificate.
A larger model means capacity and cost. Whether that capacity becomes useful depends on the tokenizer, data, training budget and evaluation process.
That may sound obvious, but in a field obsessed with parameter counts it is worth stating clearly.
The tokenizer chapter is also more thoughtful than simply recommending a vocabulary size.
For a bilingual English-Arabic model, the book proposes training several candidates: Unigram 10K, 16K and 20K, plus a 16K BPE model.
Then it evaluates them on held-out text.
A worked example asks us to imagine a 100-word Arabic sample.
The candidates produce:
10K Unigram: 182 tokens
16K Unigram: 154 tokens
20K Unigram: 146 tokens
16K BPE: 161 tokens
At first glance, 20K appears to win.
But that is not automatically the correct decision.
The 20K tokenizer also requires a larger embedding matrix. If 16K produces acceptable Arabic and English segmentation, the smaller vocabulary may provide a better balance between token efficiency and parameter cost.
The book also raises details that are easy to overlook in Arabic NLP: Alef variants, Ya versus Alef Maqsura, Ta Marbuta, Tatweel, Arabic and Western digits, diacritics, zero-width characters and mixed Arabic-English technical text.
The important lesson is that normalization should be a deliberate product decision, not an automatic cleanup step.
That is a mature way to discuss tokenization.
Perhaps my favorite section is not about a successful model at all.
It presents failure investigations.
In one case, the training loss becomes NaN at update 143.
Instead of suggesting random hyperparameter changes, the investigation restores checkpoint 142, restores the dataset RNG, captures the exact next batch and searches for the first invalid tensor.
That phrase matters.
The objective is not to make the symptom disappear. It is to locate the first point where correct behavior becomes incorrect.
Another case is even more revealing.
Chat output looks plausible, yet KV-cache parity fails.
The likely bug is subtle: tokens_seen is incremented inside the decoder-layer loop. Every tensor shape remains valid, but different layers apply different positional offsets to the same token.
This is exactly the kind of defect that can survive casual testing because the program still produces language.
A third case examines training that resumes successfully but immediately diverges from the uninterrupted run. Possible causes include dataset RNG state, optimizer state, learning-rate indexing and the definition of the completed step.
The book's rule is blunt and sensible:
Do not solve a reproducible failure by changing the seed.
Preserve it. Reproduce it. Find the first divergence. Fix the contract. Add a regression test.
This is not a book for someone who wants to create a commercial competitor to the largest frontier models on a laptop.
It does not promise that.
The reference implementation is deliberately smaller than a commercial LLM platform, and the book explicitly states that architecture correctness alone cannot compensate for inadequate data, compute or evaluation.
It is also Windows-oriented in its practical workflow. PowerShell, MSVC, CMake, Ninja and LibTorch form the main toolchain.
And although CUDA is supported as a target, the book correctly treats a successful build on one environment as local evidence, not a universal guarantee across every GPU, driver and binary combination.
These limitations make the book more believable, not less.
The strongest feature of Pure C++ Transformers is that it refuses to separate neural-network theory from software behavior.
It wants the reader to understand attention, but also to test causality.
It wants the reader to understand AdamW, but also to think about optimizer-state memory.
It explains KV caching, then asks the reader to prove cached inference agrees with ordinary inference.
It explains checkpoints, then distinguishes a weight snapshot from a state capable of exact training continuation.
And it discusses scaling without pretending that parameter count alone creates intelligence.
For a complete programming beginner, there are easier entry points.
For someone looking only for quick API usage, this book is probably more detail than necessary.
But for a C++ developer, AI engineer, technically ambitious student, or programmer who has reached the point where “just load the model” no longer feels satisfying, that detail is exactly the point.
The book's most valuable idea may ultimately be very simple:
An AI-Model is not one piece of magic.
It is a chain of contracts.
Text must agree with the tokenizer. The tokenizer must agree with the embedding table. Tensor shapes must agree with attention. Training state must agree with resume. The checkpoint must agree with inference. The runtime must agree with the requested hardware. And the tests must provide evidence that all of those agreements are real.
Once you begin seeing a Transformer that way, the black box starts to disappear.
What remains is something far more interesting:
a system you can inspect, calculate, test, break, repair, optimize and, eventually, truly understand.
A Transformer That Compiles Can Still Be Wrong
The Tensor Example Is More Important Than It Looks
Why C++? The Book Gives a More Sensible Answer Than “Speed”
A Real Example: Designing a 25M-Class AI-Model on Modest Hardware
The 100M Example Is Refreshingly Unspectacular
The English-Arabic Tokenizer Study Is a Particularly Good Example
Where the Book Becomes Most “Engineering-Like”: Things Go Wrong
The Book Has Limitations, and That Is Part of Its Credibility
Final Impression.
Get all you need about AI model with C++ https://shoponetime.com/product/create-ai-model-pure-c-transformers
20/08/2026
What If You Stopped Using AI — and Started Understanding How It Is Built?
There comes a point in every serious programmer’s journey with artificial intelligence when using AI is no longer enough.
At first, everything feels almost magical.
You install a library.
You download a pretrained model.
You write a few lines of code.
You send a prompt.
And suddenly, the machine answers.
It writes. It predicts. It summarizes. It generates.
The experience is impressive.
But sooner or later, a much more interesting question begins to appear:
What is actually happening inside the AI-Model?
Not how to call it.
Not how to connect to an API.
Not how to send a request and receive a response.
But how was the model built in the first place?
How does ordinary human language become numbers inside computer memory?
How does a Transformer decide which previous tokens matter?
Where do Query, Key, and Value really come from?
What does Attention actually calculate?
Why are there multiple heads?
Why do we need normalization?
What exactly happens during backpropagation?
How can millions of apparently meaningless numerical parameters gradually become a language model capable of generating coherent text?
And perhaps the most exciting question of all:
Can you build the entire AI-Model yourself and understand what every major part is doing?
That is the idea behind:
HOW CREATE AI-Model — Pure C++ TRANSFORMERS
Design, Tokenize, Train, Optimize, and Deploy a Decoder-Only Language Model from First Principles
This book was not created to add another shallow Transformer explanation to the internet.
It was not written to show you a colorful Attention diagram, give you ten lines of code, and then tell you that you now understand large language models.
And it certainly was not designed around the idea that AI engineering means calling someone else’s API.
The goal is very different.
The goal is to open the Transformer.
To examine it.
To understand its mathematics.
To translate those mathematics into C++.
And then to build the system piece by piece until you have something real running in front of you.
________________________________________
Imagine beginning with nothing more than a sentence.
For example:
The engineer designed a new...
To a human reader, those words already carry meaning.
To a language model, however, they must first become numbers.
The text passes through a tokenizer.
The tokenizer transforms language into token IDs.
Those IDs enter an embedding matrix.
The embeddings become vectors.
The vectors pass through Transformer blocks.
Attention allows the model to determine relationships between positions.
Feed-forward networks transform internal representations.
Normalization stabilizes the computation.
Residual connections preserve information.
Finally, the model produces a set of numbers called logits.
Those logits become probabilities.
And from those probabilities, the next token is selected.
Then the process repeats.
Again.
And again.
Until language appears.
That process sounds simple when compressed into a paragraph.
But every arrow in that pipeline contains an entire engineering problem.
And that is where this book goes deeper.
________________________________________
One of the biggest differences between reading about Transformers and actually building one is that real code forces you to answer questions theory can sometimes hide.
Suppose your tensor has the shape:
[4, 512, 256]
What does that mean?
Batch size?
Sequence length?
Hidden dimension?
What happens when that hidden dimension is divided across attention heads?
If there are eight heads, what is the dimension of each head?
How are Query, Key, and Value reshaped?
What dimensions are multiplied?
What happens if one tensor is on CPU and another is on CUDA?
What happens if one is FP32 while another is BF16?
What happens if the causal mask is wrong?
The code will not politely ignore these mistakes.
A real implementation forces clarity.
That is one of the reasons C++ is so powerful for learning AI engineering.
It brings you closer to the machine.
Closer to memory.
Closer to tensors.
Closer to runtime behavior.
Closer to the actual system you are building.
________________________________________
Inside the book, Attention is not treated as a magical function.
You will examine the famous equation:
[
Attention(Q,K,V)=softmax\left(\frac{QK^T}{\sqrt{d_k}}+M\right)V
]
But more importantly, you will see how that equation becomes software.
You will understand why the model creates Query, Key, and Value projections.
Why the Key matrix must be transposed.
Why the scores are scaled.
Why the causal mask exists.
Why future tokens must remain invisible during autoregressive training.
And why a model can appear to train successfully while actually learning from a broken attention implementation.
This is where the book becomes more than a coding guide.
It becomes an engineering journey.
Because knowing how to write the function is useful.
Knowing how to prove that the function is correct is far more valuable.
________________________________________
Then comes training.
Another word that sounds simple until you actually build the system.
Training is not just:
“give the model data and wait.”
It is a transaction.
Input tokens enter the network.
The model predicts.
The prediction is compared to the correct next token.
A loss is calculated.
Gradients are produced.
The optimizer updates parameters.
The learning rate changes.
The process repeats thousands or millions of times.
But what happens when the learning rate is wrong?
What happens when gradients explode?
Why use gradient clipping?
What is gradient accumulation?
Why does AdamW require additional memory beyond the model parameters?
What is stored inside the optimizer state?
Why can a 100-million-parameter model consume far more memory than the size of its weights suggests?
These are the questions that transform someone from a person who can run training into someone who understands training.
The book goes through the mathematics of cross-entropy, AdamW, learning-rate scheduling, gradient behavior, numerical precision, and memory usage — and connects each concept directly to implementation.
________________________________________
Then comes another problem almost every serious training system eventually encounters:
What happens when training stops?
Perhaps the computer restarts.
Perhaps CUDA crashes.
Perhaps you simply want to continue tomorrow.
Saving only the weights is not always enough.
A serious checkpoint may need to preserve the model parameters, optimizer state, training step, tokens processed, learning-rate state, random generator state, tokenizer information, configuration, and dataset position.
Otherwise, “resume” may not really mean resume.
The model may continue.
But not from the exact training state you thought you preserved.
The book explores checkpoint architecture because production AI is not only about creating a network.
It is about creating a system that survives reality.
________________________________________
And then comes one of the most rewarding moments.
Inference.
You trained the model.
Now it must speak.
A prompt enters.
The model produces logits.
The logits become a probability distribution.
And now you must decide how the next token is selected.
Always choose the highest probability?
That is greedy decoding.
Add randomness?
Now temperature matters.
Restrict the candidate set?
Top-K enters the picture.
Select from a probability mass instead?
Now you are working with Top-P.
The model has not changed.
Its parameters remain exactly the same.
Yet its behavior can feel dramatically different because generation itself is an engineering layer.
Then KV Cache enters the system.
Instead of recomputing everything again for every generated token, previous Keys and Values can be reused.
Suddenly, inference becomes faster.
But now another set of questions appears.
How is the cache shaped?
How are new tokens appended?
How does RoPE handle positional offsets?
When should the cache be invalidated?
How do you verify that cached inference produces the same result as full forward computation?
This is where “Transformer knowledge” becomes “Transformer engineering.”
________________________________________
The book also goes beyond the neural core.
Because a real AI-Model does not live inside one .cpp file.
You need a development environment.
A build system.
Dependencies.
Runtime libraries.
Scripts.
Tests.
Configuration.
Packaging.
That is why PowerShell plays a major role throughout the project.
Instead of depending on dozens of hidden IDE settings, the workflow is designed to be repeatable.
Check prerequisites.
Configure the project.
Build it.
Prepare data.
Train.
Resume.
Generate.
Chat.
Package.
A serious engineering project should not work only because its creator remembers which buttons to click.
It should be reproducible.
________________________________________
And this is where the book takes a very deliberate position.
C++ is not presented as “better than every other language.”
Python has transformed modern machine learning for good reasons.
Its ecosystem is extraordinary.
Research moves quickly because of it.
But C++ gives you something different.
Control.
It forces you to confront the runtime.
It makes memory visible.
It makes device placement visible.
It makes data types visible.
It makes dependency management visible.
And for developers who want to understand what lies beneath high-level AI abstractions, that visibility is incredibly valuable.
________________________________________
The deeper you go into the book, the less mysterious the AI-Model becomes.
You begin to see that what once looked like an impossible machine is composed of understandable pieces.
Tokens.
Matrices.
Vectors.
Attention scores.
Residual paths.
Normalization.
Weights.
Gradients.
Optimizers.
Caches.
Memory.
Code.
Individually, none of these pieces is magic.
The power comes from how they are connected.
And understanding those connections changes the way you look at artificial intelligence.
________________________________________
This book is not aimed at someone looking for a five-minute shortcut.
It is for the developer who wants to know.
The C++ programmer who wants to enter AI from a serious engineering perspective.
The AI developer who already works with high-level frameworks but wants to understand what happens underneath them.
The student who knows the Transformer equation but has never translated it into a complete system.
The independent developer who wants to experiment with their own models.
The engineer who is tired of treating powerful technology as an unexplained black box.
Because there is an enormous difference between saying:
“I can use an AI-Model.”
and saying:
“I understand how one is built.”
________________________________________
By the end of this journey, you will have followed the complete path:
Text becomes tokens.
Tokens become embeddings.
Embeddings enter Transformer blocks.
Attention creates relationships.
The network predicts.
Loss measures error.
Gradients carry correction signals.
AdamW updates the parameters.
Checkpoints preserve progress.
Inference converts learned weights into generated language.
KV Cache accelerates generation.
Sampling controls behavior.
Conversation management transforms the model into a chat system.
And C++ connects all of it into a real engineering project.
The intention is not simply to make you comfortable with Transformer terminology.
It is to make those terms concrete.
To make them executable.
To make them understandable.
________________________________________
There is a moment during this process when something changes.
You stop seeing an AI-Model as a mysterious object created by giant laboratories.
You begin seeing architecture.
You begin seeing tensors.
You begin seeing decisions.
You begin seeing things you could modify, test, optimize, and rebuild.
That is the moment this book is really trying to create.
Because perhaps the most valuable step in learning artificial intelligence is not learning how to ask AI better questions.
It is reaching the point where you can ask yourself:
“What would happen if I built the model differently?”
And then having enough knowledge to find out.
________________________________________
HOW CREATE AI-Model — Pure C++ TRANSFORMERS
Design, Tokenize, Train, Optimize, and Deploy a Decoder-Only Language Model from First Principles
For developers who no longer want to stop at the API.
For engineers who want to follow the tensors.
For programmers who want to understand the mathematics.
And for builders who want to see what happens when theory becomes code, code becomes training, and training becomes an AI-Model.
Do not just use the technology.
Open it. Understand it. Build it.
Buy Now On AMAZON... https://www.amazon.com/dp/B0HFTF9GBP?ref_=cm_sw_r_ffobk_cp_ud_dp_KWMSGQHBM5Q99JE2WNC2
Address
Wenlock Road
London
N17GU
Alerts
Be the first to know and let us send you an email when ShopySquares posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.
Category
Listing takedown request
Tell us why this listing should be removed. Our team will review your request.