All posts
· 10 min read

There's levels to this game.

LLM from scratch without all the stuff that came after like reasoning, MOE, and RL instruction fine-tuning and safety alignment.

LLM from ScratchAttentionTokenizationToken EmbeddingsPositional Embeddings

Bare bones LLM from scratch

The Image shown is a basic example of how things go when you want to build and train an LLM from Scratch.

Data Preprocessing plays a major role in how the LLM behaves after training (obviously).

Narrowed scope. Bare bones architecture on which one call do all the magic to form Claude code level intelligence from here.

Let me go through the Stage 1, step 1 :

Data Preprocessing :

Tokenization

Tokens to Token Embeddings ( Vector Embeddings )

Addition of Positional Embeddings to Token Embeddings

Tokenization

Why ?

Dumb LLM doesn't understand words. It needs numbers. So we convert the words into numbers. Technically.

A neural network trained to convert words(more specifically subwords) into tokens is required. So OpenAI made BPE Tokenizer ( Byte Pair Encoding ). How does this work, here's an rough idea.

Considering 4 words in a corpus that repeated x times as mentioned below.

So BPE helps this way.

Tokens to Token Embedding Bridge

Why ?

Tokens by themselves have no similarity or meaning when compared with other tokens.

Lets say there is a word "King" -> token id : 38, another "Man" -> token id : 143

There is no relation between the two words in any sense. So if those two are converted into embeddings, their similarity will surface based on dimensions of the embedding.

Addition of Positional Embeddings to Token Embeddings

Why ?

Ex : "The cat sat on the table" and "the table sat on the cat" have same vector embeddings. So that really makes it crazy for an LLM to understand which sat on which.

That's it for today.

Asking why ? has been really entertaining for me. I feel that I should have asked that earlier.