2017-04-27 8 views
1

Ich versuche meine Hände auf spacy, aber es scheint, die Dokumentation ist fehlerhaft. Um damit anzufangen brauchte ich ziemlich lange. Die erste Frage, die ich konfrontiert war: -Probleme mit Spacy in Python

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

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

Was ich durch den Import des Moduls

import en_core_web_sm as en_core 
nlp=en_core.load() 

Aber jetzt gelöst, wenn Im Versuch, diesen 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 immer

zu laufen
>>top most similar words to apple: 

Während ich sein sollte bekommen

+0

Das funktioniert gut für mich. – DhruvPathak

Antwort

2

Running python -m spacy.en.download alle als Administrator behoben das Problem.