Last active
November 20, 2017 23:50
-
-
Save roopalgarg/fa4555519ec17291c5a6261f1511e751 to your computer and use it in GitHub Desktop.
Word Embeddings for bigrams using gensim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gensim.models import word2vec | |
bigram_to_search = "hello_there" | |
def bigram2vec(unigrams, bigram_to_search): | |
bigrams = Phrases(unigrams) | |
model = word2vec.Word2Vec(bigrams[unigrams]) | |
if bigram_to_search in model.vocab.keys(): | |
return model[bigram_to_search] | |
else: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment