2017-04-27 5 views
1

나는 손을 잡기 위해 노력하고 있지만 문서에 결함이있는 것 같습니다. 시작하려면 꽤 오래 걸렸습니다. 내가 직면 한 첫 번째 문제는했다 : - 나는 모듈Python에서 Spacy와 관련된 문제

import en_core_web_sm as en_core 
nlp=en_core.load() 

을 가져하지만 지금 해결

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

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

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을 실행하면 문제가 해결되었습니다.