Tutorial 02 · 23 pages · August 8, 2026

Talking Matrices: from embeddings to BERT.

This tutorial is the crash-course prerequisite for the rest of the semester. In twenty-three deliberately terse slides it walks from the earliest attempts to turn a word into a vector, through the MLP, RNN, LSTM and GRU that dominated the 2010s, into attention and the transformer, and finishes with the muppet family, ELMo, BERT and their descendants. If any of these names still feel like black boxes to you, this is the deck to sit with.

Tutorial 02 23 pages Aparajitha Allamraju

§0The deck at a glance

The slide-deck's own navigation bar tells you the plan: four sections, named ini di beninging, recurrence, optimus prime and muppets. Playful surface, serious spine. Read it as: the era before neural nets, the era of recurrence, the transformer takeover, and the pretrained encoder family that followed. Each section is short. None of them is optional if you want the next twenty lectures to make sense.


§0The opener

page 01 / 23
Title slide: Talking matrices. And other prerequisites. aNLP M'26, August 8 2026, IIIT Hyderabad.
page 01 · title

On the slide

The title slide. Talking Matrices: And other prerequisites, delivered on 8 August 2026 at IIIT Hyderabad.

What it means

The joke in the title is that all the neural machinery you will meet in this course is, at heart, matrices talking to matrices. A word becomes a row of numbers, a sentence becomes a stack of rows, a network is a chain of matrix multiplies with a nonlinearity between each pair, and training is the slow rearrangement of those numbers by gradient descent. Everything else, the diagrams, the exotic cell drawings, the muppet mascots, is just naming schemes over that same operation.

✦ the aha

Whenever a later slide looks intimidating, ask yourself: which matrices are being multiplied, and what shape is the result. That is almost always the whole story.


§1ini di beninging(the early days)

Five slides on how NLP represented a word before deep learning got good, and the little feed-forward network that everything after this section is a variation on.

page 02 / 23
Section divider: Word Embeddings
page 02 · section divider

A section divider. Everything until page 06 is about the pre-deep-learning question: how do you turn a word into a vector at all?

page 03 / 23
Word Embeddings bullets: deterministic methods treated each word as atomic, SVD had huge sparse matrices, Word2Vec: a word is known by the company it keeps.
page 03 · a very short history

On the slide

A three-beat history of word representation. Before neural nets, words were atoms, one-hot vectors with no notion of similarity between "king" and "queen". People tried to fix this with count-based statistics and SVD on a co-occurrence matrix, which worked in principle but produced enormous, mostly-zero matrices. Then Word2Vec (Mikolov, 2013) reframed the problem: learn a dense vector for each word by predicting its context.

What it means

The Firthian slogan on the last bullet, "a word is known by the company it keeps", is the entire justification for distributional semantics. If two words show up in the same neighbourhoods (doctor, nurse) their meanings are close; if they never co-occur (doctor, banana) they are not. Every embedding technique from Word2Vec through GloVe to BERT's contextual embeddings is a refinement of this one bet.

◆ mechanism

An SVD on a term-context matrix M gives you U Σ V T ; keep the top k singular values and each row of U Σ k is a k -dimensional word vector. Word2Vec ends up learning something startlingly similar, but stochastically, with a shallow network, and without ever materialising the giant matrix.

page 04 / 23
Word2Vec: CBOW predicts target from surrounding words, SkipGram predicts surrounding words from target, Negative Sampling reduces computation.
page 04 · Word2Vec, three moves

On the slide

The three ingredients that make Word2Vec work: two training objectives and one computational trick.

  • CBOW (Continuous Bag of Words): given the context words in a small window, predict the missing centre word. Averages the context embeddings and asks a softmax to name the target.
  • SkipGram: flip it. Given the centre word, predict each context word independently. Empirically better for rare words because every occurrence teaches the model something.
  • Negative sampling: the honest softmax over a 100K-word vocabulary is unaffordable. Replace it with a binary classifier, is this a real (word, context) pair or a randomly sampled fake one?, and you only touch a handful of vectors per update.

What it means

Notice what Word2Vec is not: it is not a deep network. It is a shallow, essentially linear model whose only nonlinearity is the sigmoid on the final classifier. The magic is not in depth; it is in the objective. You train on billions of context windows and the geometry of the resulting embedding space starts to encode analogies, the famous king − man + woman ≈ queen .

page 05 / 23
Section divider: MLP
page 05 · section divider
page 06 / 23
Multi-Layer Perceptron: input x, two hidden layers h(1) and h(2), output y-hat, fully connected arrows between every pair of adjacent nodes.
page 06 · a Multi-Layer Perceptron

On the slide

A section divider and then the diagram everyone draws when they say "neural network": an input x , two fully-connected hidden layers h 1 and h 2 , and an output y ^ . Every arrow is a weight; every circle applies a nonlinearity to the sum of its inputs.

What it means

An MLP is a stack of affine transforms interleaved with nonlinearities. In matrix form:

h 1 = σ ( W 1 x + b 1 )
h 2 = σ ( W 2 h 1 + b 2 )
y ^ = softmax ( W 3 h 2 + b 3 )

That is the whole engine. A universal function approximator in principle. But look what it lacks: nothing in this picture cares that the input is a sequence. Feed it "the cat sat" and "sat cat the" as bags of one-hots and it will happily produce the same output. That defect is the reason the next section exists.

✦ the aha

The MLP is not a rival to the transformer. It is a component of the transformer, the feed-forward block inside every layer is exactly this two-layer MLP, applied position-wise. You never leave the MLP behind; you just wrap it in cleverer plumbing.


§2recurrence(RNNs and their kin)

Ten slides on the family of networks that dominated NLP between about 2013 and 2017: the vanilla RNN, the LSTM and GRU that fixed its gradient problems, the bidirectional trick, and Bahdanau's attention, the crack in the wall through which the transformer would soon walk.

page 07 / 23
Section divider: Recurrent Neural networks
page 07 · section divider

A section divider. The next ten pages are the recurrent story.

page 08 / 23
Classic RNN: rolled cell on the left with self-loop, equal to unrolled chain h1 → h2 → ... → hT taking inputs x1..xT and emitting y-hat_1..y-hat_T.
page 08 · rolled = unrolled

On the slide

The founding picture of the RNN. On the left, a single cell with a loop from its hidden state back to itself. On the right, that same cell drawn out across time, h 1 , h 2 , … , h T , with each step taking a new input x t and emitting a prediction y ^ t .

What it means

The RNN's whole contribution is one word: share. Instead of an MLP with a separate weight matrix for each timestep, you have one matrix that gets applied over and over. Whatever the network learns about how to update its memory when it sees a verb at step 3, it also uses at step 47. That parameter sharing is what makes learning from sequences tractable at all.

page 09 / 23
'Classic MLP (Oops)': the unrolled RNN redrawn with disconnected h cells that no longer pass state between timesteps.
page 09 · what an MLP would look like on a sequence

On the slide

The same picture as page 08 with one detail changed: the horizontal arrows between hidden states are gone. Now it is just a stack of independent MLPs, one per timestep.

What it means

This is what an MLP would do if you naively applied it word-by-word. Each step processes its input in isolation. Nothing carries forward. Feed it "not bad" and the "bad" step has no idea it was just negated. This is the context problem, and the horizontal arrow of the previous slide, the recurrence, is the whole answer.

⚠ common trap

"But couldn't you just widen the MLP's input to include a window of the last few words?" You can, and people did, the original n-gram neural language model of Bengio et al. But a fixed window is not the same as unbounded memory. The RNN's promise, at least on paper, is that it can carry information forward as long as it needs to.

page 10 / 23
An RNN cell: h_{t-1} and x_t both flow into a tanh block whose output becomes h_t; y_hat_t is a projection of h_t.
page 10 · the cell
page 11 / 23
RNN update equation: h_t = tanh([x_t : h_{t-1}]).
page 11 · the update rule

On the slide

The vanilla RNN cell, opened up. The previous hidden state h t - 1 and the current input x t are concatenated, pushed through a single learned linear layer, and squashed by a tanh . The result is both the new hidden state h t and (after one more projection) the output y ^ t .

What it means

The compact form is:

h t = tanh ( W [ x t ; h t - 1 ] )

Note what "concatenate then multiply by W " secretly is: W x x t + W h h t - 1 . Two matrices masquerading as one. Everyone writes it the concatenated way because it looks tidier on a slide.

⚠ common trap

Backpropagating through a chain of the same W multiplies gradients by the same Jacobian at every step. If its spectral radius is above 1, gradients blow up; below 1, they die. This is the vanishing / exploding gradient problem, and it is exactly what LSTMs and GRUs were invented to fix.

page 12 / 23
An LSTM cell: cell state c_{t-1} is modified by a forget gate f_t and an input gate i_t times a candidate c-tilde_t, giving c_t; hidden state h_t = o_t · tanh(c_t).
page 12 · the LSTM cell
page 13 / 23
LSTM equations: f, i, o are sigmoid gates on the concatenation of x_t and h_{t-1}; c-tilde is a tanh candidate; c_t = c_{t-1}·f_t + i_t·c-tilde; h_t = o_t · tanh(c_t).
page 13 · the LSTM equations

On the slide

The Long Short-Term Memory cell (Hochreiter & Schmidhuber, 1997), a vanilla RNN's better-behaved cousin. It carries two states, not one: an internal cell state c t that runs along the top of the diagram like a conveyor belt, and the usual hidden state h t . Three sigmoid gates decide what to do with the belt:

  • Forget gate f t , multiplies the old cell state elementwise. Zero means forget, one means keep.
  • Input gate i t , decides how much of the new candidate c ~ t to add.
  • Output gate o t , decides how much of the (tanh'd) cell state to expose as the new hidden state.

What it means

The magic is the top wire: the cell state passes through only additive updates and elementwise multiplications by a sigmoid. There is no repeated matrix multiply on that path. So when you backpropagate along the belt, gradients survive across dozens of timesteps rather than vanishing after five. That, and nothing else, is why LSTMs beat vanilla RNNs on real sequence tasks for two decades.

◆ mechanism

Each gate is its own tiny MLP: f t = σ ( W f [ x t ; h t - 1 ] ) , and similarly for i , o , c ~ . Four gates, four weight matrices, one cell. Roughly 4× the parameters of a vanilla RNN.

page 14 / 23
A GRU cell: reset gate r_t and update gate z_t decide how the previous hidden state combines with a tanh candidate h-tilde_t to produce h_t. No separate cell state.
page 14 · the GRU cell

On the slide

The Gated Recurrent Unit (Cho et al., 2014), the LSTM stripped down. Two gates instead of three, and no separate cell state at all, the hidden state doubles as the memory.

  • Reset gate r t , decides how much of the old hidden state feeds into the candidate.
  • Update gate z t , a single knob that interpolates between "keep old" and "take new". The diagram's 1 - block is what makes this a convex mixture.

What it means

Formally: h t = ( 1 - z t ) ⊙ h t - 1 + z t ⊙ h ~ t . Fewer parameters than an LSTM, comparable performance on most tasks, faster to train. The empirical answer to "do we really need three separate gates?" turned out to be: often, no.

✦ the aha

The playful title "Steal the Moon!" refers to the LSTM's cell state going away, the GRU quietly absorbs it into the hidden state. Less machinery, same gradient-preserving trick, because the update gate lets the model choose to just copy h t - 1 forward unchanged.

page 15 / 23
Bidirectional RNN: forward hidden states h→_1..h→_T and backward hidden states h←_1..h←_T are concatenated per timestep to produce y-hat_1..y-hat_T.
page 15 · bidirectional

On the slide

A bidirectional RNN. Two independent recurrent passes over the same input: one left-to-right ( h → t ) and one right-to-left ( h ← t ). At each timestep the two are concatenated before predicting y ^ t .

What it means

A unidirectional RNN's hidden state at step t knows about the past but not the future. That is fine when you are generating, one token at a time. It is a real limitation when you are tagging, labelling every word in a sentence, because "bank" in "river bank" needs the word "river" to disambiguate, and "river" comes after in some dialects of the same idea. The bidirectional variant fixes this at the cost of doubling the compute and forbidding streaming inference.

page 16 / 23
Bahdanau attention diagram: encoder produces bi-directional hidden states h_1..h_T; decoder step t computes attention weights α_{t,i} over them; the weighted sum c_t is fed into the decoder hidden state h'_t.
page 16 · Bahdanau attention

On the slide

The single most important slide in this section. Bahdanau, Cho and Bengio's 2015 attention mechanism, drawn over an encoder-decoder architecture. The encoder is a BiRNN. The decoder, at each step t , does not receive a single fixed context vector; it receives a weighted sum c t = ∑ i α t , i h i of the encoder hidden states, where the weights α t , i are computed on the fly.

What it means

Before Bahdanau, the entire source sentence in a neural translation model was squeezed into one fixed-size vector. Long sentences failed because you cannot cram a paragraph into 512 floats without loss. Attention broke the bottleneck: at every decoder step, the model gets to look at the encoder states directly and decide which ones matter for the word it is about to emit. The weights α are a soft version of "which source word am I translating right now".

✦ the aha

This is the moment the transformer becomes almost inevitable. Once you have attention, the recurrence is doing less and less useful work, it is just providing an ordering. Vaswani et al. (2017) will remove the recurrence entirely and keep only the attention. That is the next section.

◆ mechanism

The alignment score e t , i = a ( h t - 1 ′ , h i ) is passed through a softmax to get α t , i . In Bahdanau's paper a is a small MLP; in Luong's follow-up it is just a dot product. The dot-product version is the seed of scaled dot-product attention.


§3optimus prime(the transformer takes over)

Two slides that compress the whole Attention Is All You Need paper into six equations. Deliberately terse: the full transformer lecture is still to come.

page 17 / 23
Section divider: Transformers and Attention
page 17 · section divider

A section divider. The recurrence is gone; attention is the whole engine now.

page 18 / 23
Attention equations: q_i = x_i W_Q, k_i = x_i W_K, v_i = x_i W_V; Attention = softmax(qk / sqrt(d_k)); o_i = Attention × v_i.
page 18 · scaled dot-product attention

On the slide

The attention operation in six lines. Each input vector x i is projected three ways into a query q i , a key k i and a value v i by three learned matrices W Q , W K , W V . The attention weights are:

Attention = softmax ( q · k d k )

And the output at position i is the corresponding weighted sum of value vectors.

What it means

The database metaphor is exact: every position gets to query every other position, matches its query against those positions' keys, and pulls back a soft-lookup of the corresponding values. The d k in the denominator is not decorative: without it, at large d k the dot products grow, the softmax saturates, gradients vanish, and training stalls. Vaswani et al. discovered this scaling empirically and it is now folklore.

✦ the aha

Notice what is missing. No recurrence. No convolution. The only interaction between positions is this one softmax over dot products. Every position in a sequence talks directly to every other position in one layer, at the price of O ( n 2 ) memory. Almost everything that happens later in the course, Flash Attention, sparse attention, state space models, is a reaction to that quadratic cost.


§4muppets(BERT and friends)

Four slides on the family of pretrained encoders that inherited the earth after 2018. Called "muppets" because the naming convention started with ELMo and BERT and stayed there (ERNIE, KERMIT, ROBERTA, and so on).

page 19 / 23
Section divider: Some popular embedding models
page 19 · section divider

A section divider. From this page on, "embedding model" means contextual embedding: the vector for a word depends on the sentence it sits in.

page 20 / 23
ELMo diagram from jalammar.github.io/illustrated-bert: three-step composition — concatenate hidden layers from forward and backward LMs, multiply each vector by a task-learned weight, sum them.
page 20 · ELMo, a BiLSTM in disguise

On the slide

ELMo (Embeddings from Language Models, Peters et al. 2018) built on top of a two-layer bidirectional LSTM language model. For any word in a sentence, it stacks the forward and backward LSTM hidden states at every layer, weighs them by task-learned scalars s 0 , s 1 , s 2 , and sums the result into one contextual vector.

What it means

Word2Vec gave you one vector per word, forever. ELMo gave you a different vector for "bank" depending on whether it appeared next to "river" or next to "loan". That single shift, from a lookup table to a function of the sentence, is what made the muppet era possible.

◆ mechanism

The task-learned weights s ℓ are the point. Different downstream tasks care about different layers: syntactic tasks lean on the lower layer, semantic tasks on the upper. Letting the task pick its own mixture is why ELMo dominated the GLUE benchmarks in 2018.

page 21 / 23
BERT? illustration: a yellow BERT box taking 512 input tokens ([CLS], Help, Prince, Mayuko, ...) and producing 512 output vectors.
page 21 · BERT, the black box
page 22 / 23
BERT... illustration: the same 512-in / 512-out story, box opened up to reveal 12 stacked Transformer Encoder blocks.
page 22 · BERT, opened up

On the slide

Two views of the same object. First, BERT as a friendly yellow blob: 512 tokens go in, 512 contextual vectors come out. Then, the blob opened up to reveal 12 identical transformer encoder blocks stacked on top of each other. (BERT-large uses 24.)

What it means

BERT (Devlin et al., 2018) is what you get when you take the transformer encoder from section §3, throw away the decoder entirely, and pretrain the encoder on two self-supervised objectives on a mountain of text:

  • Masked Language Modelling. Randomly hide 15% of the input tokens and ask the encoder to guess them back. Because attention is bidirectional inside an encoder, the model gets to look both left and right, the muppet update of ELMo's core trick.
  • Next Sentence Prediction. Given two segments, decide whether the second one follows the first. Later work (RoBERTa) showed this objective barely helps; the MLM does most of the heavy lifting.

Once pretraining is done, you attach a tiny task-specific head to the [ CLS ] vector (for classification) or to the per-token outputs (for tagging) and fine-tune. That is the whole recipe.

✦ the aha

The single most striking thing about BERT is how ordinary the architecture is. It is literally a stack of the encoder blocks defined on page 18. The revolution was the training objective and the scale, not the model. Every "encoder-only" descendant, RoBERTa, DeBERTa, ELECTRA, is a variation on which mask, which loss, and how much data.


§5fin

page 23 / 23
A dark slide with a single serifed word: Fin.
page 23 · end

On the slide

The end card. Fin. From atomic one-hot vectors to a stack of twelve transformer encoder blocks, in twenty-two slides.

What it means

If you sat with every page here you now have the whole ladder in view: Word2Vec teaches you that words can live in a geometry; the MLP teaches you what a learned function looks like; the RNN teaches you why sequence order matters and why plain backprop through time is a nightmare; LSTM/GRU teach you the additive-path trick that saves gradients; attention teaches you that you can just look instead of remember; the transformer removes the crutch of recurrence entirely; and BERT shows that once you have a good encoder, all of NLP starts to look like fine-tuning one big pretrained model. The rest of this course is what happened next.

Tutorial 02 · Talking Matrices · ANLP Monsoon '26
home · github ↗