Created
April 11, 2015 15:46
-
-
Save dimazest/0d7ce274fa8f6582eda2 to your computer and use it in GitHub Desktop.
Semantic similarity
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
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