You should study these as a progression of representation learning in NLP:

Sparse features → Static embeddings → Contextual embeddings → Sequence models → Attention → Self-attention → Transformers → LLMs

Here is the deeper version.

1
Why Did NLP Need Embeddings?
The representation problem that started modern NLP.
Must-know

Earlier NLP systems represented text using simple symbolic or statistical features.

Examples:

- One-hot encoding - Bag of Words - TF-IDF - N-grams

Suppose we have a vocabulary:

["king", "queen", "apple", "doctor", "hospital"]

A one-hot representation would look like:

king = [1, 0, 0, 0, 0] queen = [0, 1, 0, 0, 0] apple = [0, 0, 1, 0, 0] doctor = [0, 0, 0, 1, 0] hospital = [0, 0, 0, 0, 1]

The problem is that one-hot vectors do not capture meaning.

In this representation:

king and queen are as unrelated as king and apple

because every pair of different words has the same distance.

So the model cannot naturally understand that:

king ≈ queen doctor ≈ hospital car ≈ vehicle

This created the need for dense vector representations, called embeddings.

2
What Is an Embedding?
Dense vectors that make meaning usable by neural networks.
Must-know

An embedding is a dense numerical vector that represents a word, token, sentence, document, image, user, product, or any other object in a continuous vector space.

For NLP:

word/token → vector

Example:

king = [0.21, -0.54, 0.33, 0.91, ...] queen = [0.24, -0.49, 0.36, 0.88, ...] apple = [-0.71, 0.15, 0.92, -0.31, ...]

The key idea is:

similar meaning → nearby vectors different meaning → distant vectors

So embeddings convert discrete language into a mathematical form that neural networks can process.

A good embedding space should capture relationships like:

king - man + woman ≈ queen Paris - France + India ≈ Delhi doctor relates to hospital teacher relates to school

These relationships are not manually programmed. They emerge because words appear in similar contexts during training.

3
Why Are Embeddings Important in LLMs?
How token IDs become numerical inputs to transformer layers.
Must-know

LLMs do not directly understand raw text.

The input pipeline is roughly:

Raw text → tokenization → token IDs → token embeddings → transformer layers → output token probabilities

Example:

Input: "I love machine learning"

First tokenization happens:

["I", " love", " machine", " learning"]

Then each token is converted into an integer ID:

[40, 3021, 5780, 6975]

Then each token ID is mapped to an embedding vector:

40 → [0.12, -0.33, ...] 3021 → [0.76, 0.04, ...] 5780 → [-0.18, 0.91, ...] 6975 → [0.44, -0.22, ...]

These vectors are the real input to the neural network.

So in LLMs:

tokens are symbolic units embeddings are numerical representations transformer layers contextualize those embeddings

Important distinction:

Initial token embedding: The base representation of a token before reading surrounding context. Contextual representation / hidden state: The updated representation after the token interacts with other tokens.

Example:

I deposited money in the bank. I sat near the river bank.

The token “bank” starts with a base embedding. But after transformer layers process the full sentence, the representation of “bank” becomes different in each sentence.

That is the bridge from static meaning to contextual meaning.

4
How Are Embeddings Trained?
Why useful vector spaces emerge from prediction tasks.
Must-know

Embeddings usually start as random vectors.

During training, the model tries to solve a task. When it makes mistakes, the loss is calculated, and backpropagation updates the model weights, including the embedding vectors.

Basic training flow:

Input text → convert tokens to embeddings → model predicts output → compare prediction with correct answer → calculate loss → backpropagate gradients → update embeddings and model weights

Over millions or billions of examples, embeddings become meaningful.

Why?

Because words used in similar contexts receive similar gradient updates.

Example:

The doctor treated the patient. The nurse treated the patient. The physician treated the patient.

Words like doctor, nurse, and physician appear in similar contexts. Their vectors are repeatedly adjusted in similar directions.

So the model learns:

doctor ≈ physician doctor related to patient nurse related to hospital

This is not manually labeled. It emerges from distributional patterns.

The principle is:

You shall know a word by the company it keeps.
5
Word2Vec: Static Word Embeddings
The classic static embedding breakthrough.
Must-know

Word2Vec was a major breakthrough because it showed that useful word meaning could be learned from raw text.

It introduced dense word vectors trained from local context.

Word2Vec has two main architectures:

1. CBOW 2. Skip-gram
CBOW: Continuous Bag of Words

CBOW predicts the target word from surrounding context.

Example sentence:

The cat sits on the mat

Context:

The, cat, on, the

Target:

sits

So the model learns:

surrounding words → center word

CBOW is usually faster and works well with frequent words.

Skip-gram

Skip-gram does the reverse.

It predicts surrounding words from the center word.

Example:

Input word: cat Predict context: The, sits, on, mat

So the model learns:

center word → surrounding words

Skip-gram often works better for rare words because each word gets many training examples from its surrounding context.

What Word2Vec Learned Well

Word2Vec embeddings capture semantic similarity.

Examples:

king close to queen doctor close to physician car close to vehicle India close to country

It also captures analogy-like relations:

king - man + woman ≈ queen

This happens because vector directions encode certain relationships.

For example:

king → queen man → woman

may share a similar gender-related vector direction.

Limitation of Word2Vec

The biggest limitation:

Word2Vec creates static embeddings.

That means each word has only one vector.

Example:

bank = same vector everywhere

But “bank” can mean:

financial institution river side

Word2Vec cannot create different vectors based on sentence context.

So:

I deposited money in the bank. I sat near the river bank.

Word2Vec gives the same base vector for “bank” in both cases.

This is a major limitation because natural language is highly contextual.

Interview answer:

Word2Vec learns static word embeddings using context prediction. It captures semantic similarity well, but it cannot handle polysemy because each word has one fixed vector regardless of context.

6
From Word2Vec to Neural Sequence Models
How sequential models added context before attention.
High value

After Word2Vec, NLP moved toward models that could process sequences.

Common sequence models:

- RNN - LSTM - GRU

The idea was to read text step by step and maintain a hidden state.

Example:

The → cat → sat → on → the → mat

An RNN processes this sequentially:

h1 = f(The) h2 = f(cat, h1) h3 = f(sat, h2) h4 = f(on, h3) ...

The hidden state acts like a memory of what the model has seen so far.

Problem with RNNs

Basic RNNs struggle with long-term dependencies.

Example:

The book that I borrowed from my friend last week was interesting.

To understand “was,” the model needs to connect it to “book,” even though many words appear in between.

RNNs pass information step by step. As distance increases, earlier information can fade.

This is called the vanishing gradient problem.

LSTMs and GRUs

LSTMs were designed to improve long-term memory using gates.

LSTM has gates such as:

forget gate input gate output gate

These gates decide:

what to remember what to forget what to output

This made LSTMs better than simple RNNs for long sequences.

But they still had problems:

- sequential processing is slow - hard to parallelize - long-range context is still difficult - all information must flow through hidden states

These limitations motivated attention.

7
ELMo: Contextual Embeddings
The move from fixed word vectors to contextual meaning.
High value

ELMo was important because it introduced widely used contextual word embeddings.

Unlike Word2Vec:

Word2Vec: one word → one vector ELMo: one word → different vector depending on context

Example:

I deposited money in the bank. I sat near the river bank.

In ELMo, “bank” gets different representations in each sentence.

How ELMo Worked

ELMo used bidirectional LSTM language models.

It read text in both directions:

Forward LSTM: I → deposited → money → in → the → bank Backward LSTM: bank → the → in → money → deposited → I

Then it combined representations from both directions.

This allowed the model to understand a word using both left and right context.

Example:

The bat flew at night. He swung the bat.

ELMo can create different contextual embeddings for “bat” based on whether the sentence is about an animal or a sports object.

Why ELMo Was Important

ELMo changed the idea of embeddings.

Before ELMo:

embedding = lookup vector for a word

After ELMo:

embedding = function of the entire sentence

So meaning became contextual.

This was a huge step toward modern LLMs.

But ELMo still used LSTMs, so it inherited some limitations:

- sequential computation - harder to scale than transformers - weaker parallelization - long context still challenging

Interview answer:

ELMo introduced contextual embeddings by using bidirectional LSTM language models. It solved the static embedding problem by generating different representations for the same word in different contexts.

8
Why Attention Was Needed
The bottleneck that attention was designed to remove.
High value

Sequence models like LSTMs compressed information into hidden states.

In translation, this was a big problem.

Example:

English sentence: The boy who was wearing a red shirt and carrying a small bag went to school. Translate to another language.

A traditional encoder-decoder model had to compress the entire sentence into one fixed vector before decoding.

This creates an information bottleneck.

Attention solved this by allowing the decoder to look back at different parts of the input whenever needed.

Instead of relying only on one compressed vector, the model can dynamically focus on relevant words.

Simple idea:

Attention = dynamic lookup over input tokens
9
What Is Attention?
Dynamic focus over relevant input information.
High value

Attention is a mechanism that calculates how much focus one token or state should give to other tokens or states.

Suppose we are translating:

The cat sat on the mat.

When generating the translated word for “cat,” the model should focus strongly on “cat.”

When generating the translated word for “mat,” it should focus on “mat.”

So attention produces weights like:

The → 0.05 cat → 0.70 sat → 0.10 on → 0.05 mat → 0.10

Then it creates a weighted combination of input representations.

The general formula is:

Attention output = weighted sum of values

Where weights represent relevance.

10
Query, Key, Value: The Core of Attention
The search-and-lookup mental model behind attention.
Must-know

Modern attention uses three vectors:

Query Key Value

Intuition:

Query = what I am looking for Key = what each token offers Value = the information I will take if relevant

Library analogy:

Query = your search request Key = book title/index tags Value = actual book content

In attention:

  • A token creates a Query.
  • Other tokens provide Keys.
  • The Query is compared with each Key.
  • Similarity scores are calculated.
  • Scores are normalized into attention weights.
  • Values are combined using those weights.

Simplified:

score = Query · Key weight = softmax(score) output = weighted sum of Values

The actual scaled dot-product attention formula is:

Attention(Q, K, V) = softmax(QKᵀ / √dₖ) V

Meaning:

QKᵀ: compares queries with keys √dₖ: scaling factor to stabilize training softmax: converts scores into probabilities/weights V: values are combined according to attention weights
11
What Is Self-Attention?
Attention inside one sequence.
Must-know

Self-attention means attention within the same sequence.

Each token attends to other tokens in the same input.

Example:

The cat drank the milk because it was hungry.

To understand “it,” the model should attend to “cat.”

Self-attention allows:

it → cat hungry → cat milk → drank cat → drank

So every token gets updated based on relevant tokens around it.

How Self-Attention Works Step by Step

Take a sentence:

The cat sat

Step 1: Convert tokens to embeddings.

The → x1 cat → x2 sat → x3

Step 2: For each embedding, create Query, Key, and Value using learned weight matrices.

Q = XWq K = XWk V = XWv

So each token has:

The: q1, k1, v1 cat: q2, k2, v2 sat: q3, k3, v3

Step 3: Compare each Query with all Keys.

For the token “sat,” compare:

q_sat · k_The q_sat · k_cat q_sat · k_sat

Step 4: Apply softmax to get attention weights.

Example:

sat attends to: The → 0.05 cat → 0.75 sat → 0.20

Step 5: Combine Values.

new representation of "sat" = 0.05 * v_The + 0.75 * v_cat + 0.20 * v_sat

Now “sat” has a contextual representation that includes information from “cat.”

This happens for every token.

Interview answer:

Self-attention updates each token representation by comparing it with all other tokens and taking a weighted combination of their value vectors.

12
Why Self-Attention Is Better Than RNN/LSTM for LLMs
Direct long-range interaction and parallel training.
High value

In RNNs/LSTMs:

information flows sequentially

Example:

token1 → token2 → token3 → token4 → token5

If token 1 needs to influence token 100, the signal must pass through many steps.

In self-attention:

token1 can directly attend to token100

This gives direct access to long-range dependencies.

Also, self-attention allows parallel computation.

RNN:

must process token 1 before token 2 before token 3

Transformer:

can process many tokens in parallel during training

This is one of the biggest reasons transformers scale so well.

Main advantages:

- direct token-to-token interaction - better long-range dependency modeling - parallel training - scalable to large data and large models - better contextual representations
13
Multi-Head Attention
Multiple relationship detectors working in parallel.
Must-know

One attention mechanism may focus on one type of relationship.

But language has many relationships:

- grammar - subject-verb relation - pronoun reference - object relation - position - entity relation - semantic similarity

Multi-head attention runs multiple attention heads in parallel.

Each head has its own Q, K, V projections.

Example:

Head 1: focuses on subject-verb relationship Head 2: focuses on pronoun resolution Head 3: focuses on nearby syntax Head 4: focuses on semantic similarity

Then the outputs of all heads are combined.

Why useful?

Because the model can look at the sentence from multiple perspectives at the same time.

Interview answer:

Multi-head attention allows the model to learn different types of relationships in parallel, making attention richer and more expressive.

14
Attention vs Self-Attention
The general mechanism versus the same-sequence version.
High value

Attention is the general idea of focusing on relevant information.

Self-attention is attention applied within the same sequence.

Difference:

Attention: one sequence attends to another sequence Self-attention: tokens in the same sequence attend to each other

Example of attention in translation:

French decoder attends to English encoder outputs

Example of self-attention:

Words in an English sentence attend to other words in the same sentence

In modern transformers:

encoder self-attention: input tokens attend to input tokens decoder self-attention: generated tokens attend to previous generated tokens cross-attention: decoder attends to encoder outputs

GPT-style LLMs mainly use decoder-only transformer architecture with causal self-attention.

15
Causal self-attentiontyle LLMs
Left-to-right attention for GPT-style generation.
High value

Normal self-attention can allow each token to attend to all tokens.

But GPT-style models generate text left to right.

So while predicting the next token, the model should not look into the future.

Example:

Input: The capital of India is

The model predicts the next token.

During training, for a sequence:

The capital of India is New Delhi

When predicting “India,” the model should not see “New Delhi” yet.

So GPT uses causal masking.

Causal self-attention means:

each token can attend only to previous tokens and itself

Masking pattern:

Token 1 attends to: token 1 Token 2 attends to: token 1, token 2 Token 3 attends to: token 1, token 2, token 3 Token 4 attends to: token 1, token 2, token 3, token 4

This preserves autoregressive generation.

Interview answer:

GPT-style models use causal self-attention so each token can only attend to previous tokens, enabling left-to-right next-token prediction.

16
What Is a Transformer?
The reusable block behind modern language models.
Must-know

A transformer is a neural network architecture built around self-attention.

A transformer block usually has:

- multi-head self-attention - feed-forward neural network - residual connections - layer normalization

Simplified block:

Input embeddings → self-attention → add & normalize → feed-forward network → add & normalize → output hidden states

This block is repeated many times.

Example:

GPT-2 small: 12 layers larger LLMs: many more layers

Each layer refines token representations.

Early layers may learn lower-level patterns like syntax.

Middle layers may capture phrases and relationships.

Higher layers may capture abstract meaning, reasoning patterns, and task behavior.

17
Transformer Encoder, Decoder, and Decoder-only Models
BERT-style, T5-style, and GPT-style architectures.
Must-know

There are different transformer variants.

Encoder-only

Used by models like BERT.

Purpose:

understanding tasks classification search embedding generation

Encoder attention is bidirectional:

each token can attend to all tokens

Good for:

sentiment analysis NER sentence embeddings classification
Encoder-decoder

Used by models like T5 and original Transformer translation models.

Structure:

encoder reads input decoder generates output

Good for:

translation summarization text-to-text tasks
Decoder-only

Used by GPT-style LLMs.

Structure:

previous tokens → predict next token

Uses causal self-attention.

Good for:

chat completion reasoning coding general generation

Most modern chat LLMs are decoder-only or decoder-dominant architectures.

18
Positional informational Information
Why order must be added to attention-based models.
Must-know

Self-attention does not naturally know order.

Without positional information:

Dog bites man. Man bites dog.

would look too similar because the model sees the same set of tokens.

So transformers add position information.

Input becomes:

token embedding + positional embedding

This tells the model:

which token is first which token is second which tokens are nearby which tokens are far apart

Modern models may use:

- learned position embeddings - sinusoidal position encodings - rotary position embeddings - relative position bias

Positional information is essential because language meaning depends heavily on order.

19
Feed-Forward Network in Transformer Blocks
How each contextual token representation is transformed.
Good to know

After attention mixes information across tokens, each token representation passes through a feed-forward neural network.

This FFN is applied independently to each token.

Attention answers:

which tokens should talk to each other?

Feed-forward network answers:

how should each token representation be transformed after receiving context?

Typical FFN:

linear layer → activation function → linear layer

The FFN increases the model’s capacity to transform and store complex patterns.

In modern LLMs, the feed-forward layers often contain a large portion of the model parameters.

Interview answer:

Attention mixes information across tokens, while the feed-forward network transforms each token’s contextual representation.

20
Residual Connections and Layer Normalization
Training stabilizers that make deep transformers possible.
Good to know

Transformers are deep networks. Deep networks are hard to train without stabilizing techniques.

Two important components are:

residual connections layer normalization

Residual connection means:

output = input + transformation(input)

Instead of replacing the input completely, the model adds a learned change to it.

This helps gradients flow through many layers.

Layer normalization stabilizes the distribution of activations, making training more stable.

Together, they allow transformers to scale to many layers.

Interview answer:

Residual connections and layer normalization stabilize transformer training and allow very deep models to learn effectively.

21
How Transformers Become LLMs
Scaling decoder-only transformers into general language models.
Must-know

A transformer becomes an LLM when it is scaled in:

- parameters - training data - compute - context length - training duration

GPT-style LLM training objective:

given previous tokens, predict the next token

Example:

Input: The capital of India is Target: New

Then:

Input: The capital of India is New Target: Delhi

This is repeated over massive text corpora.

Through this objective, the model learns:

- grammar - facts - code patterns - reasoning traces - conversation style - summarization - translation - instruction following

The surprising part is that a simple next-token objective, when scaled massively, leads to general-purpose behavior.

22
Full Evolution: From Word2Vec to LLMs
A clean timeline from sparse features to LLMs.
Good to know

The development path looks like this:

One-hot / TF-IDF: Sparse, no deep meaning Word2Vec: Dense static embeddings RNN/LSTM: Sequential context modeling ELMo: Contextual embeddings using bidirectional LSTMs Attention: Dynamic focus over relevant input parts Self-attention: Every token attends to every other token Transformer: Scalable architecture based on self-attention GPT-style LLM: Decoder-only transformer trained on next-token prediction at massive scale

Each step solved a limitation of the previous step.

Word2Vec solved sparse representation.

ELMo solved static meaning.

Attention solved fixed-vector bottlenecks.

Self-attention solved sequential dependency limitations.

Transformers solved scalability.

LLMs scaled transformers with massive data and compute.

23
Interview Summary
The crisp story to say in an interview.
Must-know

A strong interview answer could be:

Modern LLMs evolved from earlier NLP representations. Traditional methods used sparse features like one-hot vectors and TF-IDF, which could not capture semantic meaning. Word2Vec introduced dense static embeddings, where words appearing in similar contexts had similar vectors. However, Word2Vec gave each word only one representation, so it could not handle context-dependent meanings. ELMo improved this by using bidirectional LSTMs to generate contextual embeddings, where the same word could have different representations depending on the sentence.

Attention was introduced to solve the bottleneck of compressing an entire sequence into a single hidden state. It allowed models to dynamically focus on relevant parts of the input. Self-attention extended this idea by allowing every token in a sequence to attend to every other token. This made it easier to capture long-range dependencies and enabled parallel computation.

The Transformer architecture combined self-attention, multi-head attention, feed-forward networks, residual connections, layer normalization, and positional encoding. Because transformers scale well with data and compute, they became the foundation of modern LLMs. GPT-style LLMs use decoder-only transformers with causal self-attention and are trained using next-token prediction. At scale, this allows them to learn grammar, knowledge, reasoning patterns, and general-purpose language behavior.

The most important line:

Word2Vec made meaning vector-based. ELMo made meaning contextual. Attention made models focus. Self-attention made every token interact. Transformers made it scalable. LLMs made it massive.