Vol. 07 · LLM Foundations
From a Neuron to an LLM
The route from linear regression to transformer: classical ML models and their limit, biological neuron and perceptron, deep networks and representations, recurrence and its problems, attention as a breakthrough, transformer as architecture and LLM as a result of scale.
Classic ML: models before neural networks
ML is not a “smart program”. This is the selection of parameters of a mathematical function so that it correctly maps the input to the output. Difference with conventional programming: rules are not written manually, they are calculated from data.
Source-complete notesthree ways to write a program · key insight
sqlNormal programming:
rules = person writes by hand
output = rules(input)
→ works as long as there are few rules and they are clear
Machine learning:
model = fit(inputs, outputs) ← from data!
output = model(new_input)
→ rules are found by the algorithm itself
Deep learning (ML subtype):
model = very flexible function (neural network)
→ finds rules even where
a person cannot formulate themkey insight
- data + algorithm = model
- model = function with trained parameters
Linear regression, logistic regression, SVM all construct a straight line (or hyperplane) separating classes. They work great on simple tasks, but the real world is nonlinear. How to distinguish a cat from a dog with a straight line by pixels?
Source-complete noteswhat did you do before
what did you do before
- feature engineering: manually created x² and x₁ x₂
- requires expert knowledge of the task
- does not scale to images/text
Classic models - SVM, Random Forest, Gradient Boosting - are excellent when the characteristics are well defined: price, area, age. But using raw data (pixels, symbols, sound), you first need to come up with signs. This is called feature engineering - and this is where they hit the ceiling.
Source-complete notesclassic NLP pipeline to neural networks
sql# Task: determine the sentiment of the review
Hand signs (2000s):
"good" → +1, "bad" → -1
number of exclamation marks → feature
TF-IDF by dictionary → sparse vector 50k
sentence length, capital letters...
Problem 1: "not bad" = "good"?
Problem 2: "Test!" — positive or sarcasm?
Problem 3: new words, slang → not in the dictionary
→ a person cannot come up with ALL the necessary signs
→ the neural network finds them itself from the dataNeuron and Network: where do the names come from?
Neural networks are so named because they are mathematically inspired by the neurons of the brain. A biological neuron collects signals from dendrites, sums them up, and if the sum exceeds a threshold, it “shoots” through the axon. It is this logic that is reproduced by an artificial neuron.
Source-complete notesanalogy
analogy
- dendrite = input feature x
- synapse strength = weight w
- response threshold = activation function
- the analogy is simplified - the brain is more complex
One neuron is a linear function plus nonlinearity. The linear part weighs the inputs; the activation function decides "how active" the neuron is. Without activation, a neuron is simply a linear regression.
Source-complete notesactivation formula and functions
typescriptz = w₁ x₁ + w₂ x₂ + … + wₙ xₙ + b
output = f(z) ← activation function
Activation functions:
Sigmoid: f(z) = 1 / (1 + e^-z) → [0,1]
historically the first, now rare
ReLU: f(z) = max(0, z) → [0,∞)
standard for hidden layers
SiLU/Swish: f(z) = z sigmoid(z) → smooth ReLU
used in modern LLM (SwiGLU)
# Why nonlinearity is critical:
without f(z): 100 layer network = one linear function
with f(z): the network can approximate ANY functionOne neuron is weak. When neurons are connected in layers, and layers are connected in series, a network emerges. Each layer transforms the input's representation: the first layer sees raw pixels, the last layer sees abstract concepts. This is called a feature hierarchy.
Source-complete noteswhy "neural NETWORK"
why "neural NETWORK"
- neuro - from neuron biology
- network - neurons connected to each other
- output of one neuron = input of the next
It has been mathematically proven (Cybenko, 1989): a neural network with one hidden layer and a sufficient number of neurons can approximate any continuous function with any accuracy. This explains why neural networks are so versatile - they are not limited to a specific form of function.
Source-complete noteswhat does this mean in practice
textTheorem: ∃ network W such that
|W(x) − f(x)| < ε for any x
In other words, a neural network can learn:
✓ grammar rules (no one wrote explicitly)
✓ what does “cat” mean based on thousands of photos
✓ connection between words in the text
✓ style of a specific author
But: the theorem says “exists”, not “how to find”
→ you need enough data
→ training needed (backprop + optimizer)
→ the right architecture is neededDeep Learning: Why Depth
A “deep” neural network is simply a network with many layers. But depth is not just quantity: each layer builds more abstract representations on top of the previous one. This is what allows deep networks to understand images, sound and text without manual cues.
Source-complete notesdeep learning = automatic feature engineering
deep learning = automatic feature engineering
- signs are learned, not invented
- works on raw data: pixels, tokens, PCM
- requires a lot of data and calculations
- interpretability is worse than linear ones
Learning is an iterative process of minimizing error. The model makes a prediction, compares it with the correct answer, calculates “how much it was wrong” (loss), and slightly adjusts all the weights in the right direction.
Source-complete notesgradient descent loop
python① Forward pass:
prediction = model(x) ← through all layers
② Loss (error function):
L = loss_fn(prediction, y_true)
for example cross-entropy: how wrong is the probability?
③ Backward pass (backpropagation):
gradients = ∂L/∂W ← chain rule across all layers
"how to change each weight to reduce L?"
④ Update (optimizer):
W ← W - lr gradients ← small step
⑤ Repeat a million times
→ the weights gradually “correctly” describe the dataUntil 2012, SVM and Random Forest won most benchmarks. In 2012, AlexNet (CNN) reduced the error on ImageNet from 26% to 16%—by half. Since then, neural networks have dominated wherever there is a lot of data and complex features.
Source-complete notestable
| Classic ML | Neural network | |
|---|---|---|
| Signs | Hand Engineering | Automatically |
| Raw data | Bad | Okay |
| Data scale | Plateau at 10k–100k | Grows with data |
| Interpretability | High | "Black box" |
| Computations | CPU, fast | GPU, expensive |
| Best problems | tabular data | text, photo, audio |
The text problem: sequences and RNNs
A picture is a fixed grid of pixels. The text is a sequence of variable length, where the order is critical: “the dog bit the man” ≠ “the man bit the dog.” A regular MLP does not know the concept of “before” and “after” - a special architecture is needed.
Source-complete notesspecificity of the text
textProblem 1 - variable length:
"Yes." → 2 tokens
"War and Peace" → ~580,000 tokens
→ MLP requires a fixed input
Problem 2 - long-distance dependencies:
"The neighbor's cat around the corner meowed."
→ “meowed” depends on “cat” after 9 words
Problem 3 - order is important:
"not good" ≠ "good"
"I just left" ≠ "I just left"
Problem 4 - context changes meaning:
"key" → door? spring? way to solve?RNN (Recurrent Neural Network) solves the problem of sequences through “memory”: it processes tokens one by one, passing the hidden state h forward. h is a “compressed memory” of everything that has been read up to this point.
Source-complete notessolutions on top of RNN
solutions on top of RNN
- LSTM - gated memory cell (1997)
- GRU - simplified LSTM (2014)
- still bad at >500 tokens
- sequential processing = cannot be parallelized
In the translation task (seq2seq), the encoder compressed an entire sentence into a single fixed-size vector. Then the decoder turned it into translation. With long sentences, the vector could not retain all the information - the quality dropped.
Attention: the heart of modern NLP
Attention is a soft search mechanism: instead of reading all the information at once, the model learns to assign importance weights. For each position, it calculates how “relevant” each other position is right now.
Source-complete notesrevolutionism
revolutionism
- direct access to any token - no attenuation
- weights are calculated dynamically depending on the context
- parallel to all positions
- Bahdanau 2015 - first attention for NLP
In the original attention decoder looked at the encoder. Self-attention is when a sequence looks at itself. Each token is simultaneously a query, a key, and a value. This allows you to build contextual representations without recurrence.
Source-complete notesmechanics Q, K, V · vs recurrence
texFor each token x_i:
Q_i = x_i · W_Q ← “what am I looking for?”
K_j = x_j · W_K ← “what am I offering?”
V_j = x_j · W_V ← “what am I returning?”
score(i,j) = Q_i·K_jᵀ / √d_k
α_ij = softmax(score)
out_i = Σⱼ α_ij · V_j
Result: "key" in the context of "door"
has a different vector than the “key” in the “spring”
→ contextual embeddings!vs recurrence
- O(1) steps between any tokens (RNN: O(n))
- parallel processing of the entire sequence
- O(n²) memory - expensive on long contexts
One attention mechanism answers one “question”. Multi-head attention launches several parallel attentions with different weights - each head specializes in its own type of connections: syntax, coreference, semantics, position.
Source-complete noteswhat different heads teach
textHead 1: syntactic connections
“the cat meowed” - the head sees the subject↔predicate
Head 2: coreference
"Masha went home. She was tired."
— the head notices “she” = “Masha”
Head 3: Positional Patterns
— monitors neighboring tokens
Head 4: semantic proximity
- "king" ↔ "monarch" ↔ "ruler"
→ concatenation of all heads → W_O → final vector
→ each token gets a “comprehensive” understanding of the contextTransformer: «Attention Is All You Need»
Vaswani et al. (Google, 2017) proposed to remove recurrence completely and build an architecture based only on attention and MLP. The result is better quality, 3x faster training. This became the foundation for all LLMs.
Source-complete noteswhat has changed
textBefore (RNN/LSTM seq2seq):
processing: sequential (token by token)
long dependencies: lost
training on 8 GPU: weeks
context: ~200–500 tokens
After (Transformer):
processing: parallel (all tokens at once)
long dependencies: direct O(1) access
training: days
context: scalable (hundreds of thousands, 1M+, for some models up to ~2M)
The key idea is positional embeddings:
“if there is no recurrence, how can we know the order?”
→ add position information to the token vector itselfOne transformer block is two subblocks with residual connections. Self-attention “mixes” information between positions - it recognizes the context. The MLP “thinks” about each position independently—applies knowledge. LLM = stack of such blocks.
The job of the language model is to predict the next token. A stack of transformer blocks builds an increasingly deeper representation of the context, and the final linear layer (LM Head) converts it into probabilities over a dictionary. Training in “guess the next word” gives language abilities.
Source-complete noteslanguage modeling · scale laws (Kaplan et al. 2020)
textTask: P(next token | all previous ones)
Entrance: "Moscow - the capital"
↓ × 32 transformer blocks
↓ LM Head (d_model → vocab_size)
↓ softmax
Probabilities:
"Russia" → 0.71
"Russia." → 0.12
"Russia," → 0.08
"world" → 0.02 …
Training: on trillions of text tokens
learning to guess the next word → side
effect: the model “understands” language, facts, logicscale laws (Kaplan et al. 2020)
- more parameters → better
- more data → better
- more compute → better
- predictable - can be planned
From Transformer to LLM
LLM is not a new architecture. This is a decoder-only transformer trained in three stages on a fundamentally different scale of data and calculations. GPT-2 (2019) showed: just a large transformer can already do a lot without additional training.
Source-complete notesthree stages of creating an LLM
text① Pretraining (language modeling):
data: the entire Internet, books, code (~10T tokens)
task: predict next token
result: the model “knows the language” and the facts of the world
② Supervised Fine-Tuning (SFT):
data: pairs (question → good answer), ~100k
task: learning to follow instructions
result: model responds as assistant
③ RLHF/DPO (alignment):
data: human ranks answers
task: to maximize “human preference”
result: safe, useful, honest answer
Pretraining: 99% calculations
SFT + RLHF: 1% computation but UX criticalAt a certain scale, a model suddenly exhibits abilities that smaller models did not have—not gradually, but in leaps and bounds. No one specifically taught GPT-4 to solve chemistry problems—it taught itself.
Source-complete notesexamples of emergent abilities
sqlAppears at ~10B+ parameters:
✓ Multi-step reasoning (chain-of-thought)
✓ Arithmetic (3-5 characters)
✓ Translation into languages not from training
✓ Analogies and metaphors
Appears at ~100B+ parameters:
✓ Coding in new languages
✓ Explain your reasoning
✓ Solving problems using symbolic logic
✓ Understanding sarcasm and irony
Why: debatable. Possibly critical mass
compressed knowledge allows you to combine themNow you can collect a complete answer to the question “why LLM is a neural network.” This is not a metaphor or marketing - this is a specific architectural chain from the perceptron to the modern model.
Source-complete notesfull argument
sqlLLM is a neural network because:
"Neuro":
consists of artificial neurons
(weighted sum + nonlinearity)
inspired by biological brain neurons
"Network":
neurons are connected in layers
output of one → input of the next
32–80 layers of transformer blocks
"Transformer":
a special neural network where the “connections” between
neurons are not fixed, but are calculated
dynamically through the attention mechanism
"Language":
trained on the predict-next-token task
→ learned grammar, facts, logic, style
Parameters: 8B–1T+ weights wᵢ,
selected by gradient descent
on trillions of text tokensThe big picture: 70 years behind one scheme
Each next step solved a specific problem of the previous one. This is not a random sequence of inventions - it is a deliberate movement towards a universal sequence processor.
Source-complete notesTimeline
Timeline
- 1958 Perceptron Rosenblatt. One neuron. Linear classifier.
- 1986 Backprop Rumelhart. Deep networks can be trained.
- 1997 LSTM Hochreiter. Memory in a recurrent network.
- 2012 AlexNet CNN defeats ImageNet. Deep learning works.
- 2015 Attention Bahdanau. Decoder looks at the required encoder tokens.
- 2017 Transformer Vaswani. Only attention, no recurrence.
- 2018 BERT/GPT Pretrain on a large body → finetune to the task.
- 2022+ LLM Scale + RLHF → ChatGPT, Claude, Gemini.
No dead end
Keep moving through the map.
Continue in sequence, switch to a related guide, or return to the seven-track learning map.