jinzishuai / learn2deeplearn

A repository of codes in learning deep learning
GNU General Public License v3.0
13 stars 1 forks source link

Word2Vec #49

Open jinzishuai opened 6 years ago

jinzishuai commented 6 years ago

This is the assignment of https://github.com/jinzishuai/learn2deeplearn/tree/master/google_dl_udacity/lesson5

Word2Vec has two algorithms:

But first, what is word2vec? what does it try to achieve?

jinzishuai commented 6 years ago

word2vec

https://en.wikipedia.org/wiki/Word2vec

jinzishuai commented 6 years ago

The Skip Gram Algorithm

ref: https://en.wikipedia.org/wiki/N-gram#Skip-gram

A k-skip-n-gram is a length-n subsequence where the components occur at distance at most k from each other. It has two parameters

jinzishuai commented 6 years ago

https://towardsdatascience.com/word2vec-skip-gram-model-part-1-intuition-78614e4d6e0b

image

Embedding Lookup

embed = tf.nn.embedding_lookup(embeddings, train_dataset)

How is embedding lookup different from a normal MatMul?

They are equivalent. But with embedding lookup, we don't have a construct a matrix of "one-hot" columns from the train_dataset. We can simply look it up since it just returns a row in that particular location where it is 1 in the "one-hot" vector.

Note that We use Nagative Sampling

 loss = tf.reduce_mean(
    tf.nn.sampled_softmax_loss(weights=softmax_weights, biases=softmax_biases, inputs=embed,
                               labels=train_labels, num_sampled=num_sampled, num_classes=vocabulary_size))