Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中的空间问题_Python_Machine Learning_Nlp_Spacy - Fatal编程技术网

python中的空间问题

python中的空间问题,python,machine-learning,nlp,spacy,Python,Machine Learning,Nlp,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

我在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

作为管理员运行python-mspacy.en.download all解决了这个问题。

这对我来说很好。