Skip to content

Instantly share code, notes, and snippets.

@roopalgarg
Last active November 20, 2017 23:50
Show Gist options
  • Save roopalgarg/fa4555519ec17291c5a6261f1511e751 to your computer and use it in GitHub Desktop.
Save roopalgarg/fa4555519ec17291c5a6261f1511e751 to your computer and use it in GitHub Desktop.
Word Embeddings for bigrams using gensim
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