2017-04-27 77 views
1

我试着在spacy手中,但似乎文档有缺陷。刚开始使用它花了我很长时间。我面临的第一个问题是: -蟒蛇中的Spacy的问题

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

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

其中我解决了导入模块

import en_core_web_sm as en_core 
nlp=en_core.load() 

但现在当我试着运行这段代码

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_ 

即时得到

>>top most similar words to apple: 

虽然我应该得到

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

这对我来说很好。 – DhruvPathak

回答

2

运行python -m spacy.en.download all作为管理员解决了问题。