Lecture#14
Lecture#14
by
What is Word Embedding?
A word embedding is a learned representation for text
where words that have the same meaning have a
similar representation.
One of the benefits of using dense and low-
dimensional vectors is computational: the majority of
neural network toolkits do not play well with very high-
dimensional, sparse vectors. … The main benefit of
the dense representations is generalization power: if
we believe some features may provide similar clues, it
is worthwhile to provide a representation that is able to
capture these similarities.
Word Embedding in NLP
The continuous bag-of-words (CBOW) model is a neural network
for natural languages processing tasks such as language translation
and text classification. It predicts a target word based on
the context of the surrounding words and is trained on a large
dataset of text using an optimization algorithm such as stochastic
gradient descent. Once trained, the CBOW model generates
numerical vectors, known as word embeddings, which capture the
semantics of words in a continuous vector space and can be used in
various NLP tasks. It is often combined with other techniques and
models, such as the skip-gram model, and can be implemented
using libraries like gensim in python.
Word embeddings Application
Word
Embedding
Frequency Prediction
based based
•BOW •word2Vc
•TFIDF
Word2vec
Word2vec is a widely used natural language processing
technique that uses a neural network to learn distributed
representations of words, also known as word embeddings.
These embeddings capture the semantics of a word in a
continuous vector space, such that similar words are close
together in the vector space. Word2vec has two main model
architectures: continuous bag-of-words (CBOW) and skip-gram.
CBOW predicts the current word based on the context of the
surrounding words, while skip-gram predicts the surrounding
words given the current word. Word2vec can be trained on a large
text dataset and is commonly used in various natural language
processing tasks, such as language translation, text classification,
and information retrieval.
Why Word2Vec
https://colab.research.google.com/dri...
https://github.com/campusx-official/g...
Let’s see an example
• Julie loves John more than Linda loves John
• Jane loves John more than Julie loves John
Item 1: [2, 0, 1, 1, 0, 2, 1, 1]
Item 2: [2, 1, 1, 0, 1, 1, 1, 1]
King Queen Man Women Monkey
Gender 1 0 1 0 1
Male
Wealth 1 1 0.7 0.3 0
Power 1 0.7 0.6 0.5 0
Weight 0.7 0.5 0.6 0.5 0.3
Speak 1 1 1 1 0
King-man+women
1-1+0=0
1-0.7+0.3=0.6
1-0.6+0.4=0.8
Why Cosine Similarity
• Count the common words or Euclidean distance is
the general approach used to match similar
documents which are based on counting the number
of common words between the documents.
Word2Vec
CBOW Skipgram
Word2Vec
Word2Vec is a statistical method for efficiently learning
a standalone word embedding from a text corpus.It
was developed by Tomas Mikolov, et al. at Google in
2013 as a response to make the neural-network-based
training of the embedding more efficient and since
then has become the de facto standard for developing
pre-trained word embedding.
•Continuous Bag-of-Words, or CBOW model.
•Continuous Skip-Gram Model.
CBOW tries to predict a word on the basis of its
neighbors, while Skip Gram tries to predict the
neighbors of a word.
• Word2Vec will set the windoe first:
• If window size is 3.
___Target____
• If window size is 5.
____,_____, Target,_____,_____
• If window size is 7.
• ____,____,____,Target,____,_____,_____
What is a Continuous Bag of Words (CBOW)?