Skip to content

Instantly share code, notes, and snippets.

@dimazest
Created April 11, 2015 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimazest/0d7ce274fa8f6582eda2 to your computer and use it in GitHub Desktop.
Save dimazest/0d7ce274fa8f6582eda2 to your computer and use it in GitHub Desktop.
Semantic similarity
import pandas as pd
from gensim.models.word2vec import Word2Vec
words = pd.read_csv('wordsim.txt', header=None, names=('word1', 'word2', 'phonetic similarity'))
model = Word2Vec.load_word2vec_format('/GoogleNews-vectors-negative300.bin', binary=True)
def similarity(r):
try:
return model.similarity(r['word1'], r['word2'])
except KeyError:
pass
words['semantic similarity'] = words.apply(
similarity,
axis=1
)
words.to_csv('wordsim-semantic.txt', index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment