2017-04-27 3 views
1

Im essayant mes mains à spacy mais il semble que la documentation est imparfaite. Juste pour commencer, ça m'a pris assez longtemps. La première question que je dû faire face était: -Problèmes avec Spacy en python

import spacy 
nlp = spacy.load("en") 

Warning: no model found for 'en' 
Only loading the 'en' tokenizer. 

Ce que je résolu en important le module

import en_core_web_sm as en_core 
nlp=en_core.load() 

Mais maintenant, quand Im essayant d'exécuter ce code

from numpy import dot 
from numpy.linalg import norm 
from spacy.en import English 
parser = English() 

#Generate word vector of the word - apple 
apple = parser.vocab[u'apple'] 

#Cosine similarity function 
cosine = lambda v1, v2: dot(v1, v2)/(norm(v1) * norm(v2)) 
others = list({w for w in parser.vocab if w.has_vector and w.orth_.islower() and w.lower_ != unicode("apple")}) 

# sort by similarity score 
others.sort(key=lambda w: cosine(w.vector, apple.vector)) 
others.reverse() 


print "top most similar words to apple:" 
for word in others[:10]: 
    print word.orth_ 

Im obtenir

>>top most similar words to apple: 

Alors que je devrais être obtenir

>> top most similar words to apple: 
>> apples iphone fruit juice cherry lemon banana pie mac orange 
+0

Cela fonctionne très bien pour moi. – DhruvPathak

Répondre

2

L'exécution de python -m spacy.en.download en tant qu'administrateur a résolu le problème.