From simple neurons to memory - the evolution of language models
Jun 17, 2026 - ⧖ 23.0 minPublished as part of 'understanding-llm' series.
TakΕΌe po polsku: Polski
Tip
Want to run this code yourself? All the examples from this post (perceptron, RNN, LSTM) are in a ready-made Jupyter notebook: from-neurons-to-memory.ipynb
In the previous post we walked the whole path from cutting text into tokens, through counting words (TF-IDF), Markov chains, all the way to Word2Vec and meaning vectors. And at the end one fundamental question came up...
We have word vectors. Great. But how do we build something out of them that understands a sentence? Or a whole paragraph? Or a book?
Because "Dog bites man" isn't simply "dog" + "bites" + "man". It's a sequence - words follow each other in a specific order, and that order changes the meaning. "Dog bites man" and "Man bites dog" are the same words, but completely different stories :D
And Word2Vec? Word2Vec looks at words individually. It has no concept of order. It doesn't know that "not" before "like" changes everything.
So we need something that can process sequences. Something that reads text in order and builds understanding step by step.
And here begins a fascinating story - because the solution to this problem didn't appear overnight. It was an evolution that lasted several decades. From a single, simple neuron, to complicated memory cells. And each generation solved the previous generation's problem, but created a new one.
This is the fourth post in the "Understanding LLM" series. Today we go deeper into the architecture of neural networks - but relax, still without formulas you can't understand ;-) Instead, there will be plenty of metaphors, diagrams, and real-life examples.
The narrative of today's post: "From a single cell to memory - and why that still wasn't enough." Let's start from the basics.
Biological neuron vs artificial - where does the idea even come from?
Before we get into architectures, let's quickly settle one question you're probably asking yourselves: why is it even called a "neural network"? What does it have to do with the brain?
Answer: both a lot, and a little ;-) In the beginning there was inspiration from biology. Take a look:
First diagram - a real neuron. It has dendrites (receive signals from other neurons), a soma (the cell body - decides whether to "fire"), and an axon (passes the signal on).
Second diagram - an artificial neuron. It has inputs (numbers), a weighted sum (multiplies each input by its "importance" and adds it all up), and an output (the result passed through an activation function).
The resemblance is... loose. A biological neuron is unimaginably more complicated. But the inspiration was important - Warren McCulloch and Walter Pitts showed in 1943 that such a simplified model of a neuron can perform basic logical operations (AND, OR, NOT). And that meant a network of such neurons could theoretically compute anything.
Note
Does an LLM "think" like a brain? No. An artificial neuron is a mathematical abstraction, not a biological model. A biological neuron uses electrical impulses, neurotransmitters, has thousands of connections and a dynamics that can't be reduced to wβxβ + wβxβ. But the inspiration was the starting point - and an important one.
OK, that's enough biology. Let's move on to what came out of it ;-)
Perceptron - the simplest decision in the world
In 1958 Frank Rosenblatt created the perceptron - the first algorithm that could learn from data. It was a milestone.
The perceptron works trivially simply. Imagine you're deciding whether to go for a walk:
The mechanics are simple:
- Each input has its own weight (importance) - sun has weight +5, rain -8, temperature +3
- The perceptron multiplies each input by its weight and adds it all up (that's the "weighted sum")
- If the sum is greater than or equal to the threshold (in our case threshold = 0) - it fires "yes". Otherwise - "no".
Example:
| Situation | Sun (+5) | Rain (-8) | Temp >20Β° (+3) | Sum | Decision |
|---|---|---|---|---|---|
| Sunny, warm, no rain | 1 | 0 | 1 | 5 + 0 + 3 = 8 | β Going out |
| Raining, cold | 0 | 1 | 0 | 0 - 8 + 0 = -8 | β Staying home |
| Cloudy and raining, but warm | 0 | 1 | 1 | 0 - 8 + 3 = -5 | β Staying home |
And - most importantly - the perceptron can learn these weights. You show it 100 examples of "went out / didn't go out" and it gradually adjusts the weights so that its decisions match yours.
Brilliant in its simplicity, right?
But the perceptron has one big problem...
A perceptron can draw a single straight line dividing data into two groups. Which is great if the data can be split that way:
β« β« β« β βͺ βͺ βͺ
β« β« β« β βͺ βͺ βͺ
β
one line separates them β
But what if the data looks like this?
βͺ β«
β« βͺ
That's the famous XOR problem (exclusive OR). The output is "true" only when exactly one input is true - not both and not neither. And you can't draw a single straight line that would separate them.
This problem halted the development of neural networks for almost 20 years. Seriously. Researchers said: "well OK, the perceptron is cool, but if it can't handle something as simple as XOR, what's the point?" This period is called the "AI Winter".
Warning
Why was XOR so important? Because it showed that a single perceptron is limited to linearly separable problems. And the real world is rarely linear. Language definitely isn't.
And then someone said: what if we combine several perceptrons together?
MLP - a team that can do more than an individual
A Multilayer Perceptron (MLP) is a network made up of many layers of neurons. Instead of one decision layer, we have:
Every neuron in one layer is connected to every neuron in the next layer (that's why it's called "fully connected" or "dense").
The metaphor that fits best for me:
Imagine a company. Analysts (layer 1) look at raw data and pick out simple patterns. Managers (layer 2) combine those patterns into something more meaningful. The director (the output layer) makes the final decision. None of these people understands the full picture alone - but together they form a cascade of abstraction.
And that's exactly what solves the XOR problem! The first layer draws two lines. The second layer combines them into one region. Suddenly a non-linear problem becomes solvable.
But careful - there's a catch!
Adding hidden layers by itself does nothing. Why?
Because if each layer just does sum = weights Γ inputs + bias, then two layers of that operation are still... one big linear operation. Let me show with numbers:
Layer 1: y = 2Β·x + 1
Layer 2: z = 3Β·y + 2
Substitute the first into the second:
z = 3Β·(2Β·x + 1) + 2
z = 6Β·x + 3 + 2
z = 6Β·x + 5 β one operation, just with different numbers
The two layers collapsed into one. Instead of two transformations, you get one - just with different coefficients. It's like using one coffee filter twice as thick instead of two. Same effect.
So we need something non-linear between the layers. And that's where...
The activation function - the unsung hero of deep learning
An activation function is a kind of "non-standard processing plant" that we pass the sum through. The most popular today is ReLU (Rectified Linear Unit):
def relu (x ):
if x > 0 :
return x
else :
return 0
That's it. If the value is positive - keep it. If negative - zero it out.
Sounds trivial? It is trivial. But this one simple operation breaks linearity.
Back to our numbers example. Without ReLU, two layers collapsed into one (z = 6Β·x + 5). But now let's insert ReLU between them:
Layer 1: y = ReLU(2Β·x + 1)
Layer 2: z = ReLU(3Β·y + 2)
Let's check for three values of x:
| x | 2Β·x + 1 | y (after ReLU) | 3Β·y + 2 | after ReLU | Without ReLU (6Β·x + 5) |
|---|---|---|---|---|---|
| -2 | -3 | 0 β¬ zeroed out! | 2 | 2 | -7 |
| 0 | 1 | 1 | 5 | 5 | 5 |
| 1 | 3 | 3 | 11 | 11 | 11 |
Without ReLU the result changes linearly (-7, 5, 11 - constant increase). With ReLU, suddenly for x = -2 we get 2 instead of -7. This relationship is no longer a straight line. Zeroing out negative values is something that can't be expressed as aΒ·x + b - and that's exactly why layers stop collapsing into one.
Analogy: imagine window blinds. Linearity is a transparent pane of glass - it lets everything through, slightly dimmed. ReLU is blinds that completely block light below a certain angle. You can't simulate "complete blocking" by "dimming the glass more". It's a qualitatively different operation.
Thanks to ReLU, each layer does something different from the previous one. And suddenly a network with many layers becomes powerful - it can model non-linear, complicated relationships in data.
Important
ReLU in a nutshell: Without a (non-linear) activation function between layers, a network with 100 layers is just as expressive as a network with 1 layer. ReLU (and its cousins: sigmoid, tanh, GELU) is the ingredient that makes depth make sense.
Other popular activation functions:
| Function | Formula (simplified) | Range | Where it's used |
|---|---|---|---|
| ReLU | max(0, x) | [0, +β) | Hidden layers (standard) |
| Sigmoid | 1 / (1 + eβ»Λ£) | (0, 1) | LSTM gates, binary output |
| Tanh | (eΛ£ - eβ»Λ£) / (eΛ£ + eβ»Λ£) | (-1, 1) | LSTM gates, hidden states |
| Softmax | eΛ£β± / Ξ£eΛ£Κ² | (0, 1), sum = 1 | Output layer (classification) |
Tip
An experiment for you: Open Python and run this:
import numpy as np
def relu (x ):
return np .maximum (0 , x )
x = np .array ([- 3 , - 1 , 0 , 2 , 5 ])
print (f"Input: { x } " )
print (f"After ReLU: { relu ( x ) } " )
You'll see how ReLU "cuts off" everything below zero. This simple operation lets the network "choose" which features are active and which to ignore.
Mini-quiz: linear or not?1
- Plain linear regression (y = ax + b) - linear or non-linear?
- A perceptron with a step function (0 or 1) - linear or non-linear?
- An MLP without an activation function between layers - linear or non-linear?
Problem: an MLP doesn't understand order
OK, we have an MLP. It can model non-linear relationships. Great. But there's one fundamental problem that blocks us from using an MLP for language.
An MLP sees all features at once. It has no concept of order.
Take a classic English example. Two sentences with exactly the same words, but in a different order:
| Sentence | dog | bites | man |
|---|---|---|---|
| "Dog bites man" | 1 | 1 | 1 |
| "Man bites dog" | 1 | 1 | 1 |
Identical vector. And the meaning? The first is a boring news item. The second is a newspaper sensation :D
For an MLP both sentences are exactly the same - because the MLP gets the same vector and has no concept of order.
Note
What about Polish? Polish is tricky here - due to inflection (7 cases!) we rarely have two sentences with exactly the same word forms. "Pies gryzie czΕowieka" vs "CzΕowiek gryzie psa" are different forms (piesβpsa, czΕowiekaβczΕowiek). But English, with minimal inflection, shows this problem perfectly. And that's exactly why bag-of-words examples often use English ;-)
This is the permutation problem - an MLP can't distinguish [A, B, C] from [C, B, A]. And in language, order is everything. "I do not like" vs "I like not" - same words, completely different meaning.
You might think: "OK, then let's add word position as a feature." But that doesn't solve the problem - the MLP still doesn't understand that the word at position 1 has a relationship with the word at position 5. Each position is just another number on the input.
So we need something that processes data step by step, in order, and builds understanding sequentially. Just like we read a book - sentence by sentence, word by word.
And here enters the RNN.
RNN - "reads text one by one"
A Recurrent Neural Network (RNN) is a network that has something an MLP doesn't: memory. Well... sort of ;-)
Imagine you're reading a book. You don't read the whole page at once (like an MLP would). You read word by word, sentence by sentence. And with each new word you update your understanding of what's going on.
That's exactly what an RNN does. It has a hidden state - that's its "understanding of the text so far". With each new word:
- It takes the new word (x_t)
- It takes its current understanding (h_{t-1})
- It combines them and creates a new understanding (h_t)
This diagram is exactly the unrolling in time. In reality it's the same RNN neuron - but we "unwrap" it in time to show how it processes consecutive words. Notice: the arrow goes from left to right - information flows sequentially.
This is brilliant in its simplicity. The RNN "reads" text just like we do - one by one, building understanding step by step.
RNN in code - minimal
To really feel this, let's write the simplest possible RNN. No PyTorch, no TensorFlow - just NumPy:
import numpy as np
def simple_rnn (word_vectors , hidden_size = 4 ):
words , dim = word_vectors .shape
np .random .seed (42 )
W_h = np .random .randn (hidden_size , hidden_size ) * 0.01
W_x = np .random .randn (hidden_size , dim ) * 0.01
bias = np .zeros (hidden_size )
h = np .zeros (hidden_size )
for t , word in enumerate (word_vectors ):
h = np .tanh (W_h @ h + W_x @ word + bias )
print (f" Step { t + 1 } : hidden state = { np . round ( h , 2 ) } " )
return h
the = np .array ([1.0 , 0.0 ])
cat = np .array ([0.0 , 1.0 ])
sits = np .array ([0.3 , 0.3 ])
on_mat = np .array ([0.8 , 0.2 ])
sentence = np .array ([the , cat , sits , on_mat ])
print ("Processing: 'The cat sits on the mat'" )
final = simple_rnn (sentence )
print (f"\nFinal hidden state: { np . round ( final , 2 ) } " )
Run it! You'll see how with each word the hidden state changes. The last hidden state is the "understanding" of the whole sentence by our simple RNN.
Tip
Key intuition: Notice the line h = np.tanh(W_h @ h + W_x @ word + bias). That's the heart of the RNN.
Two parts of this line:
W_h @ h + W_x @ word + bias- this is the same "weighted sum" as in the perceptron and MLP. Except now it sums two sources: the previous hidden state (h) and the new word (word).tanh(...)- that's the activation function, exactly the same family as ReLU from the previous section. Instead of "cutting off below zero", tanh squeezes everything into the range (-1, 1). But the goal is the same: break linearity.
The new hidden state depends on two things: the previous hidden state (h) and the new word (word). That's exactly what we do when reading text - we combine what we already know with what we just read.
But the RNN has one big problem...
And here we get to the topic that changed everything.
The goldfish problem - why the RNN forgets
The RNN has memory, yes. But it's a goldfish memory.
Imagine this sentence:
"This is Jan and he's 30 years old. He likes hiking in the mountains, programming in Python, and playing the guitar. His favorite color is green. He once wanted to become an astronaut, but then he discovered that (...) [here 50 words about various things] (...) and that's why ___ went to music school."
What should "___" be? Jan. But to know that, the RNN has to remember the name from the beginning of the sentence. And here's the problem: after 50+ words, the signal from the first word is so diluted that the RNN practically doesn't remember it.
This is the famous vanishing gradient problem.
Metaphor: Chinese whispers. You play Chinese whispers - the first person whispers a message to the second, that one to the third, and so on. After 10 people the message is a bit distorted. After 50 people - completely unreadable. After 100 people - someone says "buy milk", and the last person hears "grab bread".
In an RNN the gradient (the learning signal) flows through the network exactly the same way - step by step. At each step it gets multiplied by some weights. If those weights are smaller than 1, then after many multiplications the gradient vanishes to zero. The network stops learning from distant words.
And sometimes it's the other way - the weights are bigger than 1 and the gradient grows exponentially (exploding gradient). The network "goes crazy" and values shoot into space.
Warning
Why is this so important? Because language is full of long dependencies. "The cat, which already ate all the fish in the fridge and then slept on the couch for three hours, was happy." - to connect "cat" with "was happy", the model has to jump over a dozen words. An RNN can't do that.
And then in 1997 Sepp Hochreiter and JΓΌrgen Schmidhuber said: what if we gave the network an explicit memory mechanism?
LSTM - the network with a notebook
A Long Short-Term Memory (LSTM) is an RNN on steroids. Instead of one simple hidden state, the LSTM has a memory cell (cell state) and three gates that decide what to do with that memory.
The metaphor that works best: an LSTM is a student with a notebook and three rules.
The forget gate - "throw out old notes"
At the beginning of each step the LSTM asks: "what from my current memory is already outdated and I can throw out?"
When you read a new chapter of a book, you don't need to remember what the characters had for breakfast three chapters ago. You forget irrelevant details to make room for new ones.
In an LSTM: the forget gate passes each element of memory through a sigmoid (values 0-1). Close to 0 = "forget". Close to 1 = "keep".
The input gate - "save this, it's important"
Then the LSTM asks: "what from the new word is worth saving?"
When you read "My name is Jan" - you have a reflex: "OK, this is important, I have to remember it". You don't memorize every word literally, but you pick out what's relevant.
In an LSTM: the input gate decides which new information to let through to the cell state.
The output gate - "show me what I need right now"
Finally the LSTM asks: "what from my memory is relevant to what I'm doing right now?"
When someone asks you "What's the name of that character we just read about?" - you reach into the notebook and pull out the specific information. You don't show the whole notebook - only what's needed now.
The key thing: the cell state is that "conveyor belt". Information on it can flow almost unchanged through many steps - the gates only decide what to let through, what to add, and what to remove. This solves the vanishing gradient problem, because the information doesn't have to be "multiplied" at every step - it can just flow.
Note
RNN vs LSTM in one sentence: An RNN tries to remember everything, but forgets quickly. An LSTM is selective - it decides what to keep, what to update, and what to show. That's the difference between "trying to memorize an entire lecture word for word" and "taking notes of the most important points".
For the curious: the math of LSTM gates
If you want to see the formulas, here they are (you don't have to memorize them, but it's worth seeing that it's not black magic):
Forget gate: $$f_t = \sigma(W_f \cdot [h_{t-1}, x_t] + b_f)$$
Input gate: $$i_t = \sigma(W_i \cdot [h_{t-1}, x_t] + b_i)$$
Cell state candidate: $$\tilde{C}t = \tanh(W_c \cdot [h{t-1}, x_t] + b_c)$$
Cell state update: $$C_t = f_t \odot C_{t-1} + i_t \odot \tilde{C}_t$$
Output gate: $$o_t = \sigma(W_o \cdot [h_{t-1}, x_t] + b_o)$$
Hidden state: $$h_t = o_t \odot \tanh(C_t)$$
Where $\sigma$ is the sigmoid (squashes values into 0-1), $\odot$ is element-wise multiplication, and $[h_{t-1}, x_t]$ is the concatenation of the previous hidden state with the new input.
An experiment for you
Try it yourself. Fire up ChatGPT (or Claude, Gemini - whatever you have) and send this prompt:
"Pola had a rare ability to remember numbers. Her favorite number was 42. She also liked longboarding, watercolor painting, and playing chess. Her cat was named Whiskers. (...) [paste 3-4 paragraphs of any text here - a pancake recipe, a weather report, whatever] (...) Still, it was ___ who decided to enter the math competition."
See whether the model fills in the blank correctly (Pola). An LSTM would handle this. A plain RNN - probably not. And why? Because the LSTM has a mechanism that says "remember the name Pola - this might be important later". The RNN would simply... forget ;-)
Why LSTM still wasn't enough
OK, so LSTM solved the memory problem. At least partially. But new problems appeared, and they turned out to be fundamental.
Problem 1: Even LSTM has its limits
LSTM solved vanishing gradient to a large extent, but not completely. When the distance between related words grows to hundreds or thousands of words, even LSTM starts losing the thread of the narrative. Bengio et al. (1994) showed that recurrent networks - even with gates - still struggle to maintain useful gradients over very long distances.
So: instead of forgetting after 10 words (RNN), LSTM forgets after... 100? 200? Better, but still not ideal.
Problem 2: Sequentiality = bottleneck
And this is the most important problem.
RNN and LSTM process data step by step. Step 2 has to wait for step 1. Step 3 for step 2. And so on.
Now think about GPUs. A GPU is a machine that loves doing many things at once (parallel processing). Thousands of cores working simultaneously.
But RNN/LSTM tells the GPU: "no, no, wait. First let's finish step 1, only then start step 2". The GPU cries.
It's like a book with 10,000 chapters, where each chapter has to be read after the previous one. You can't read chapter 500 until you've finished 499. You can't parallelize this. For short texts it's not a problem, but when training a model on billions of words? That's a nightmare.
LSTM additionally has 4x more parameters than a simple RNN (three gates + cell state = four sets of weights per neuron). So it trains slower and uses more memory.
Problem 3: "Black box"
LSTM (like most deep learning models) is hard to interpret. The model can generate correct results, but it's hard to understand why it made this decision and not another. In applications like medicine or finance, where interpretability is key, that's a serious problem.
Evolution summary - what solved what
| Architecture | Year | Solves... | But can't... |
|---|---|---|---|
| Perceptron | 1958 | Linear classification | XOR, non-linearity |
| MLP | 1986 | Non-linear relationships | Understand word order |
| RNN | 1986 | Process sequences step by step | Remember long dependencies |
| LSTM | 1997 | Remember longer thanks to gates | Process in parallel, very long texts |
Each generation solved the previous one's problem, but created a new one. It's like a game of whack-a-mole - you hit one mole, another pops up.
And then in 2017 someone asked a crazy question...
"What if we stop reading one by one?"
The metaphor that changes everything.
Imagine you're reading a novel. Now you have three ways to do it:
- RNN - you remember the last few sentences. The rest blurs.
- LSTM - you hold onto the main plot, forget the small details. Better, but you still read linearly.
- ??? - instead of reading word by word, you look at the whole page at once. Your attention jumps to the key characters, important plot moments, unexpected twists. You don't read in order - you grasp the whole thing simultaneously!
In 2017 a group of researchers at Google published a paper with the modest title: "Attention Is All You Need". Their crazy idea? What if we stop reading one by one altogether? What if every word could "see" all the other words at once?
And a revolution happened. Because if every word looks at every other simultaneously (not waiting for its turn), then:
- There's no sequential bottleneck - everything happens in parallel
- The GPU is in heaven - thousands of cores working at once
- Long dependencies? No problem - word no. 1 and word no. 1000 "see" each other directly, without 999 intermediate steps
This architecture is called the Transformer. And it's what ChatGPT, Claude, Gemini, and all the LLMs you know are built on.
Summary - the whole evolution in one place
| Architecture | Metaphor | What it can do | What it can't? |
|---|---|---|---|
| Perceptron | A ruler | Draws one line, classifies into 2 groups | XOR, non-linearity, anything complex |
| MLP | A team of analysts | Models non-linear relationships, "depth" | Doesn't understand order, sees everything at once |
| RNN | A word-by-word reader | Processes sequences, has a hidden state | Short memory (vanishing gradient) |
| LSTM | A student with a notebook and gates | Selective memory, three control gates | Sequential = slow, no parallelization |
| Transformer | The whole page at once | Parallelism, attention to everything | ...to be discovered in the next posts... |
Final quiz: match the architecture2
- You want to predict the price of a house based on square footage, number of rooms, and neighborhood - which architecture is enough?
- You need to process a 50-word sentence and determine its sentiment (positive/negative) - what do you choose?
- You're training a model on 10,000-word texts and every word has to "see" every other - RNN, LSTM, or something else?
- You want to classify points on a plane into two groups, but they're arranged in an X shape (XOR) - is a single perceptron enough?
This post is quite long, but I felt this evolution from the perceptron to LSTM deserved a full, told story.
If anything is unclear - let me know in the comments, I'll try to explain.
Which architecture surprised you the most? Did you know that the "AI Winter" was caused by something as "simple" as XOR?
What's in the next post? We're getting into the Transformer - the architecture that changed everything. Attention, self-attention, positional encoding, multi-head attention - all the things that made ChatGPT exist in the first place. Stay tuned!
See you next time!
Sources and interesting links:
If you want to go deeper, here are the materials I used:
- Multilayer Perceptrons - d2l.ai - an excellent, visual introduction to MLP: layers, activation functions, the transition from linear regression to multi-layer networks
- Multilayer perceptron - Wikipedia - definitions, network diagrams, a timeline of the history from 1943 to the present
- Multilayer Perceptron (MLP): A Practical Way to Understand Neural Networks - dev.to - a fresh, very intuitive article with metaphors and a comparison of MLP vs CNN vs Transformer
- Perceptron Explained - PlainEnglish - the perceptron as the "building block" of networks, components, geometric intuition, limitations
- Multi-Layer Perceptron Learning in TensorFlow - GeeksforGeeks - clear diagrams, forward propagation, backpropagation with implementation
- Introduction to Long Short Term Memory - GeeksforGeeks - an accessible introduction to LSTM: memory cell, gates, the long-term dependencies problem
- Drawbacks of LSTM Algorithm: A Case Study - SSRN - the drawbacks of LSTM: computational complexity, overfitting, lack of parallelization, sensitivity to hyperparameters
- Understanding Transformer Model Types: The Evolution from RNN to Modern AI - dev.to - a narrative account of the transition from RNNs to Transformers, encoder/decoder types
- LLM: Large Language Models Evolution - YouTube - a video telling the development line from sequential models to attention-based architectures
-
Mini-quiz answers: 1) Linear - y = ax + b is a linear function. 2) Non-linear - the step function "breaks" linearity. 3) Linear! Without a non-linear activation, an MLP with 100 layers = one big linear transformation. That's exactly why activation functions are necessary. β©
-
My answers: 1) A simple MLP is enough - tabular data, no sequence. 2) LSTM - a sequence of moderate length, LSTM will handle it. 3) Transformer - 10,000 words is too much even for LSTM. A Transformer with self-attention lets every word "see" every other without waiting. 4) No - a single perceptron can't solve XOR. You need at least an MLP (2 layers). β©