Skip to content

Commit bfc1fda

Browse files
committed
add figure for word2vec
1 parent e9a7ac2 commit bfc1fda

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

images/fig_nlp_word2vec.png

164 KB
Loading

notebooks/24_NLP_4_ngrams_word_vectors.ipynb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,16 +2028,26 @@
20282028
"\n",
20292029
"### Word2Vec\n",
20302030
"\n",
2031-
"The fundamental idea behind Word2Vec is to use the context in which words appear to learn their meanings. As shown in the {numref}`fig_word2vec_sliding_window`, a sliding window of a fixed size (in this case, 5) moves across the sentence \"The customer likes cake with a cappuccino.\" At each step, the algorithm selects a target word and its surrounding context words. The goal is to predict the target word based on its context or vice versa.\n",
2031+
"The fundamental idea behind Word2Vec is to use the context in which words appear to learn their meanings. As shown in the {numref}`fig_word2vec_sliding_window`, a sliding window of a fixed size (here, 5) moves over the sentence \n",
20322032
"\n",
2033-
"For example, in the phrase \"the customer likes,\" the target word is \"the,\" and the context words are \"customer\" and \"likes.\" This process is repeated for each possible position in the sentence. These word-context pairs are fed into the Word2Vec model, which learns to map each word to a unique vector in such a way that words appearing in similar contexts have similar vectors. This vector representation captures semantic similarities, meaning that words with similar meanings or usages are positioned closer together in the vector space. Word2Vec thus enables various applications such as sentiment analysis, machine translation, and recommendation systems by providing a mathematical representation of words that reflects their meanings and relationships.\n",
2033+
"> \"The customer likes cake with a cappuccino.\"\n",
20342034
"\n",
2035-
"Word2Vec models can be trained using two main methods: Continuous Bag of Words (CBOW) and Skip-Gram. In CBOW, the model predicts a target word based on its surrounding context words, focusing on understanding the word's context to infer its meaning. Conversely, the Skip-Gram model predicts the surrounding context words given a target word, emphasizing the ability to generate context from a single word {cite}`mikolov_distributed_2013`{cite}`mikolov_efficient_2013`.\n",
2035+
"At each position, the algorithm selects the central word as **target** treats the remaining words in the window as its **context**. For example, in the phrase \"the customer likes,\" the target word is \"the,\" and the context words are \"customer\" and \"likes.\" This process is repeated for each possible position in the sentence. \n",
2036+
"\n",
2037+
"These word-context pairs are fed into the Word2Vec model, which learns to map each word to a unique vector in such a way that words appearing in similar contexts have similar vectors. This vector representation captures semantic similarities, meaning that words with similar meanings or usages are positioned closer together in the vector space. Word2Vec thereby enables various applications such as sentiment analysis, machine translation, and recommendation systems by providing a mathematical representation of words that reflects their meanings and relationships.\n",
20362038
"\n",
20372039
"```{figure} ../images/fig_word2vec_sliding_window.png\n",
20382040
":name: fig_word2vec_sliding_window\n",
20392041
"\n",
20402042
"Techniques such as Word2Vec learn vector representations of individual words based on their \"context\", which is given by the neighboring words. \n",
2043+
"```\n",
2044+
"\n",
2045+
"Word2Vec models can be trained using two main methods: Continuous Bag of Words (CBOW) and Skip-Gram. In CBOW, the model predicts a target word based on its surrounding context words, focusing on understanding the word's context to infer its meaning (see {numref}`fig_nlp_word2vec`). Conversely, the Skip-Gram model predicts the surrounding context words given a target word, emphasizing the ability to generate context from a single word {cite}`mikolov_distributed_2013`{cite}`mikolov_efficient_2013`.\n",
2046+
"\n",
2047+
"```{figure} ../images/fig_nlp_word2vec.png\n",
2048+
":name: fig_nlp_word2vec\n",
2049+
"\n",
2050+
"The aim of a Word2Vec model is typically to learn vector representations of individual words based on some context words. This is done in such a way that the very large (and very sparse) input vectors are converted into highly compressed float vectors. In this example figure, the context words are \"cherry\", \"is\", \"and\", \"sweet\", and the target word would be \"red\".\n",
20412051
"```\n"
20422052
]
20432053
},
@@ -2657,7 +2667,8 @@
26572667
"\n",
26582668
"Very good starting points for going deeper are:\n",
26592669
"- The book \"Speech and Language Processing\" by Jurafsky and Martin {cite}`jurafsky2024speech`, see [link to the book](https://web.stanford.edu/~jurafsky/slp3/).\n",
2660-
"- \"Natural language processing with transformers\" by Tunstall, von Werra, and Wolf {cite}`tunstall2022natural`"
2670+
"- \"Natural language processing with transformers\" by Tunstall, von Werra, and Wolf {cite}`tunstall2022natural`\n",
2671+
"- Another free online course with Python code material: [nlp planet](https://www.nlplanet.org/course-practical-nlp/)."
26612672
]
26622673
},
26632674
{

0 commit comments

Comments
 (0)