hesamation commited on
Commit
d8283b1
·
1 Parent(s): 099cdb9

Update bibliography and index.html to reflect new title and description for the LLM embeddings guide, add a new citation for word2vec, and enhance image alt texts for better clarity.

Browse files
assets/images/word2vec_tfep.jpg ADDED

Git LFS Details

  • SHA256: d9f4fc0688c293fc5bc9a9b4fe007baa180bc506c7355bd0f111d07766112807
  • Pointer size: 131 Bytes
  • Size of remote file: 230 kB
src/bibliography.bib CHANGED
@@ -61,3 +61,12 @@
61
  url={https://github.com/chrishayuk/embeddings/tree/main},
62
  publisher={GitHub}
63
  }
 
 
 
 
 
 
 
 
 
 
61
  url={https://github.com/chrishayuk/embeddings/tree/main},
62
  publisher={GitHub}
63
  }
64
+
65
+ @misc{Mikolov_Chen_Corrado_Dean_2013,
66
+ title={Efficient estimation of word representations in vector space},
67
+ url={https://arxiv.org/abs/1301.3781},
68
+ journal={arXiv.org},
69
+ author={Mikolov, Tomas and Chen, Kai and Corrado, Greg and Dean, Jeffrey},
70
+ year={2013},
71
+ month=jan
72
+ }
src/index.html CHANGED
@@ -8,15 +8,15 @@
8
  <meta name="viewport" content="width=device-width, initial-scale=1">
9
  <meta charset="utf8">
10
  <base target="_blank">
11
- <title>A Primer on LLM Embeddings: The Semantic Backbone of AI</title>
12
  <link rel="stylesheet" href="style.css">
13
  </head>
14
 
15
  <body>
16
  <d-front-matter>
17
  <script id='distill-front-matter' type="text/json">{
18
- "title": "A Primer on LLM Embeddings: The Semantic Backbone of AI",
19
- "description": "The role of embeddings in traditional NLP, and their application to LLMs.",
20
  "published": "Mar 18, 2025",
21
  "affiliation": {
22
  "name": "University of Bologna"
@@ -36,7 +36,7 @@
36
  </script>
37
  </d-front-matter>
38
  <d-title>
39
- <h1 class="l-page" style="text-align: center;">A Primer on LLM Embeddings:<br>The Semantic Backbone of AI</h1>
40
  <div id="title-plot" class="main-plot-container l-screen" style="overflow-x: hidden; width: 100%; text-align: center;">
41
  <div style="display: flex; justify-content: center; position: relative;">
42
  {{{fragment-banner}}}
@@ -71,6 +71,10 @@
71
  </div>
72
  <figcaption>Figure 1: Overview of different word embedding techniques.</figcaption>
73
  </figure>
 
 
 
 
74
 
75
  <h2>What Makes a Good Embedding?</h2>
76
 
@@ -86,9 +90,6 @@
86
 
87
  <p>What should be the size of an embedding vector, 15, 50, 300? Striking the right balance is key. Smaller vectors (lower dimensions) are more efficient to keep in memory or to process, while bigger vectors (higher dimensions) can capture intricate relationships, but are prone to overfitting. For reference, GPT-2 model family has an embedding size of at least 768.</p>
88
 
89
- <aside>
90
- <span style="font-style: italic; font-weight: bold;">NOTE:</span> When reading about embeddings you may come across static vs. dynamic/contextualized embeddings. Static embeddings have a fixed representation for each word or token, regardless of the context it appears in. For example, the word "tear" has very different meanings in "Tears fell down from her eyes" and "tearing the page out", but dynamic embeddings change this representation based on the context of the word or token.
91
- </aside>
92
 
93
  <h2>Traditional Embedding Techniques</h2>
94
 
@@ -158,7 +159,7 @@
158
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center;">
159
  {{{fragment-tfidf-emb}}}
160
  </div>
161
- <figcaption>TF-IDF example</figcaption>
162
  </figure>
163
 
164
  <p>There are two things noticeable about this embedding space:</p>
@@ -172,13 +173,13 @@
172
 
173
  <h2>word2vec</h2>
174
 
175
- <p>A deep-learning based approach that is more modern than TF-IDF is word2vec. As can be assumed by the name, it is a network that aims to convert words into embedding vectors. It achieves this by defining a side goal, something to optimize the network for. For example, in CBOW (continuous bag of words), the word2vec network is trained to predict a missing word when its given the neighbors of that word as input. The intuition is that you can infer the embeddings of a word given the words around it.</p>
176
 
177
  <p>The word2vec architecture is pretty simple: one hidden layer that we extract the embeddings from, and one output layer which predicts the probabilities of all words in the vocabulary. On the surface, the network is trained to predict the right missing word given its neighbors, but in reality, this is an excuse to train the hidden layer of the network and find the right embeddings for each word. After the network is trained, the last layer can be tossed out the window because figuring out the embeddings is the real goal of the network.</p>
178
 
179
  <figure class="fullscreen">
180
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center;">
181
- <img src="assets/images/word2vec.png" alt="word2vec architecture diagram">
182
  </div>
183
  <figcaption>word2vec architecture showing the input layer, hidden layer (embeddings), and output layer</figcaption>
184
  </figure>
@@ -191,7 +192,7 @@
191
 
192
  <figure class="fullscreen">
193
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center;">
194
- <img src="assets/images/word2vec2.png" alt="word2vec visualization">
195
  </div>
196
  <figcaption>word2vec embeddings visualization</figcaption>
197
  </figure>
@@ -209,8 +210,19 @@
209
  </div>
210
  </details>
211
 
 
 
212
  <p>The semantic relationship is a fun topic to explore and word2vec is a simple setup for your experiments. You can explore the biases of society or the data, or explore how words have evolved overtime by studying the embeddings of older manuscripts.</p>
213
 
 
 
 
 
 
 
 
 
 
214
  <h2>BERT (Bidirectional encoder representations from transformers)</h2>
215
 
216
  <p>Wherever you look in the world of NLP, you will see BERT. It's a good idea to do yourself a favor and learn about BERT once and for all, as it is the source of many ideas and techniques when it comes to LLMs. Here's a good video to get started. <d-cite bibtex-key="codeemporium2020bert"></d-cite></p>
@@ -237,7 +249,7 @@
237
 
238
  <figure class="fullscreen">
239
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center;">
240
- <img src="assets/images/BERT.png" alt="BERT architecture visualization">
241
  </div>
242
  <figcaption>BERT architecture overview. (Image source: <d-cite bibtex-key="devlin2018bert"></d-cite>)</figcaption>
243
  </figure>
@@ -261,7 +273,7 @@
261
 
262
  <figure class="fullscreen">
263
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center; width: 70%;">
264
- <img src="assets/images/llm_embedding_overview.png" alt="Overview of embeddings in LLMs">
265
  </div>
266
  <figcaption>Overview of how embeddings fit into the LLM architecture</figcaption>
267
  </figure>
@@ -276,7 +288,7 @@
276
 
277
  <figure class="fullscreen">
278
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center;">
279
- <img src="assets/images/embedding_layer.png" alt="Embedding layer visualization">
280
  </div>
281
  <figcaption>Visualization of how the embedding layer works as a lookup table. (Image source: <d-cite bibtex-key="manning2024llm"></d-cite>)</figcaption>
282
  </figure>
@@ -285,7 +297,7 @@
285
 
286
  <figure class="fullscreen">
287
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center;">
288
- <img src="assets/images/emb_lookup.jpg" alt="Embedding lookup table visualization">
289
  </div>
290
  <figcaption>Visualization of the embedding lookup process. (Image source: <d-cite bibtex-key="manning2024llm"></d-cite>)</figcaption>
291
  </figure>
@@ -461,10 +473,10 @@
461
  <h3 id="citation">Citation</h3>
462
  <p>For attribution in academic contexts, please cite this work as</p>
463
  <pre
464
- class="citation short">"A Primer on LLM Embeddings: The Semantic Backbone of AI", 2025.</pre>
465
  <p>BibTeX citation</p>
466
- <pre class="citation long">@misc{a_primer_on_llm_embeddings,
467
- title={A Primer on LLM Embeddings: The Semantic Backbone of AI},
468
  author={Hesam Sheikh Hessani},
469
  year={2025},
470
  }</pre>
 
8
  <meta name="viewport" content="width=device-width, initial-scale=1">
9
  <meta charset="utf8">
10
  <base target="_blank">
11
+ <title>LLM Embeddings Explained: A Visual and Intuitive Guide</title>
12
  <link rel="stylesheet" href="style.css">
13
  </head>
14
 
15
  <body>
16
  <d-front-matter>
17
  <script id='distill-front-matter' type="text/json">{
18
+ "title": "LLM Embeddings Explained: A Visual and Intuitive Guide",
19
+ "description": "How Language Models Turn Text into Meaning, From Traditional Embeddings to Modern LLMs",
20
  "published": "Mar 18, 2025",
21
  "affiliation": {
22
  "name": "University of Bologna"
 
36
  </script>
37
  </d-front-matter>
38
  <d-title>
39
+ <h1 class="l-page" style="text-align: center;">LLM Embeddings Explained:<br>A Visual and Intuitive Guide</h1>
40
  <div id="title-plot" class="main-plot-container l-screen" style="overflow-x: hidden; width: 100%; text-align: center;">
41
  <div style="display: flex; justify-content: center; position: relative;">
42
  {{{fragment-banner}}}
 
71
  </div>
72
  <figcaption>Figure 1: Overview of different word embedding techniques.</figcaption>
73
  </figure>
74
+
75
+ <p>When reading about embeddings you may come across static vs. dynamic/contextualized embeddings. Static embeddings have a fixed representation for each word or token, regardless of the context they appear in.</p>
76
+
77
+ <p>Embeddings are the semantic backbone of LLMs because they work as the initial transformation from raw tokens into numeric vectors that models can understand. However, it's important to distinguish between token embeddings—which are the fixed vectors assigned to input tokens at the very beginning—and the contextual representations produced by the deeper layers of the model. While both are technically embeddings, token embeddings are static, whereas the intermediate hidden states evolve as they pass through each layer, incorporating the full context of the input. In some literature, these contextual outputs are also referred to as "embeddings," which can be confusing.</p>
78
 
79
  <h2>What Makes a Good Embedding?</h2>
80
 
 
90
 
91
  <p>What should be the size of an embedding vector, 15, 50, 300? Striking the right balance is key. Smaller vectors (lower dimensions) are more efficient to keep in memory or to process, while bigger vectors (higher dimensions) can capture intricate relationships, but are prone to overfitting. For reference, GPT-2 model family has an embedding size of at least 768.</p>
92
 
 
 
 
93
 
94
  <h2>Traditional Embedding Techniques</h2>
95
 
 
159
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center;">
160
  {{{fragment-tfidf-emb}}}
161
  </div>
162
+ <figcaption>TF-IDF example showing word embeddings plotted in 2D space after dimensionality reduction</figcaption>
163
  </figure>
164
 
165
  <p>There are two things noticeable about this embedding space:</p>
 
173
 
174
  <h2>word2vec</h2>
175
 
176
+ <p>Originally proposed in <d-cite bibtex-key="Mikolov_Chen_Corrado_Dean_2013"></d-cite>, is a more modern technique than TF-IDF. As can be assumed by the name, it is a network that aims to convert words into embedding vectors. It achieves this by defining a side goal, something to optimize the network for. For example, in CBOW (continuous bag of words), the word2vec network is trained to predict a missing word when its given the neighbors of that word as input. The intuition is that you can infer the embeddings of a word given the words around it.</p>
177
 
178
  <p>The word2vec architecture is pretty simple: one hidden layer that we extract the embeddings from, and one output layer which predicts the probabilities of all words in the vocabulary. On the surface, the network is trained to predict the right missing word given its neighbors, but in reality, this is an excuse to train the hidden layer of the network and find the right embeddings for each word. After the network is trained, the last layer can be tossed out the window because figuring out the embeddings is the real goal of the network.</p>
179
 
180
  <figure class="fullscreen">
181
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center;">
182
+ <img src="assets/images/word2vec.png" alt="Diagram showing word2vec architecture with input layer, hidden layer (embeddings), and output layer. Input words are encoded as one-hot vectors, passed through a hidden layer to generate embeddings, and finally through an output layer that predicts probabilities for each word in vocabulary.">
183
  </div>
184
  <figcaption>word2vec architecture showing the input layer, hidden layer (embeddings), and output layer</figcaption>
185
  </figure>
 
192
 
193
  <figure class="fullscreen">
194
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center;">
195
+ <img src="assets/images/word2vec2.png" alt="Visualization of word2vec embeddings in 2D space, showing how semantically similar words cluster together. Words with related meanings appear closer to each other in the embedding space.">
196
  </div>
197
  <figcaption>word2vec embeddings visualization</figcaption>
198
  </figure>
 
210
  </div>
211
  </details>
212
 
213
+ <p>To train word2vec efficiently, especially with large vocabularies, an optimization technique called negative sampling is used. Instead of computing the full softmax over the entire vocabulary (which is computationally expensive), negative sampling simplifies the task by updating only a small number of negative examples (i.e., randomly selected words not related to the context) along with the positive ones. This makes training faster and more scalable.</p>
214
+
215
  <p>The semantic relationship is a fun topic to explore and word2vec is a simple setup for your experiments. You can explore the biases of society or the data, or explore how words have evolved overtime by studying the embeddings of older manuscripts.</p>
216
 
217
+ <p>You can actually visualize and play with word2vec embeddings with <a href="https://projector.tensorflow.org/">Tensorflow Embedding Projector</a>.</p>
218
+
219
+ <figure class="fullscreen">
220
+ <div id="image-as-graph" style="display: grid; position: relative; justify-content: center;">
221
+ <img src="assets/images/word2vec_tfep.jpg" alt="Screenshot of TensorFlow Embedding Projector showing interactive 3D visualization of word2vec embeddings, allowing exploration of semantic relationships between words in the embedding space.">
222
+ </div>
223
+ <figcaption>TensorFlow Embedding Projector's interactive exploration of word2vec embeddings in 3D/2D space.</figcaption>
224
+ </figure>
225
+
226
  <h2>BERT (Bidirectional encoder representations from transformers)</h2>
227
 
228
  <p>Wherever you look in the world of NLP, you will see BERT. It's a good idea to do yourself a favor and learn about BERT once and for all, as it is the source of many ideas and techniques when it comes to LLMs. Here's a good video to get started. <d-cite bibtex-key="codeemporium2020bert"></d-cite></p>
 
249
 
250
  <figure class="fullscreen">
251
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center;">
252
+ <img src="assets/images/BERT.png" alt="BERT architecture diagram showing the model's components: input layer with tokenization, embedding layer, multiple transformer encoder blocks with self-attention mechanisms, and task-specific output heads. Special tokens [CLS] and [SEP] are highlighted.">
253
  </div>
254
  <figcaption>BERT architecture overview. (Image source: <d-cite bibtex-key="devlin2018bert"></d-cite>)</figcaption>
255
  </figure>
 
273
 
274
  <figure class="fullscreen">
275
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center; width: 70%;">
276
+ <img src="assets/images/llm_embedding_overview.png" alt="Diagram showing how embeddings fit into LLM architecture: input text is tokenized, converted to token embeddings, combined with positional embeddings, and processed through transformer layers to generate contextual representations.">
277
  </div>
278
  <figcaption>Overview of how embeddings fit into the LLM architecture</figcaption>
279
  </figure>
 
288
 
289
  <figure class="fullscreen">
290
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center;">
291
+ <img src="assets/images/embedding_layer.png" alt="Illustration of embedding layer as a lookup table: input tokens are mapped to their corresponding embedding vectors through a matrix multiplication operation. Shows how token IDs index into rows of the embedding matrix.">
292
  </div>
293
  <figcaption>Visualization of how the embedding layer works as a lookup table. (Image source: <d-cite bibtex-key="manning2024llm"></d-cite>)</figcaption>
294
  </figure>
 
297
 
298
  <figure class="fullscreen">
299
  <div id="image-as-graph" style="display: grid; position: relative; justify-content: center;">
300
+ <img src="assets/images/emb_lookup.jpg" alt="Detailed visualization of embedding lookup process: shows how token IDs are used to select specific rows from the embedding weight matrix, resulting in embedding vectors for each input token.">
301
  </div>
302
  <figcaption>Visualization of the embedding lookup process. (Image source: <d-cite bibtex-key="manning2024llm"></d-cite>)</figcaption>
303
  </figure>
 
473
  <h3 id="citation">Citation</h3>
474
  <p>For attribution in academic contexts, please cite this work as</p>
475
  <pre
476
+ class="citation short">"LLM Embeddings Explained: A Visual and Intuitive Guide", 2025.</pre>
477
  <p>BibTeX citation</p>
478
+ <pre class="citation long">@misc{llm_embeddings_explained,
479
+ title={LLM Embeddings Explained: A Visual and Intuitive Guide},
480
  author={Hesam Sheikh Hessani},
481
  year={2025},
482
  }</pre>