1
私はこのコードを実行しようとしています。ここでは2つの単語のsynsetを計算し、それらの2つの単語間の類似度を計算します。Python:NLTKはWordNetを使用して計算シナリオにMemoryErrorを与えています
コード:
def wordSim(word1,word2):
maxscore = 0.0
word1_synsets = word1[1]
word2_synsets = word2[1]
for k,j in list(product(*[word1_synsets,word2_synsets])):
score = k.wup_similarity(j) # Wu-Palmer Similarity
maxscore = score if maxscore < score else maxscore
if maxscore >= 0.85:
return True
def genSynsets(wordList):
synsetList = map(lambda x: [x,wn.synsets(x.decode('utf-8'))],wordList)
return synsetList
エラーメッセージ:Python docsから
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/global/python/2.7.5/lib/python2.7/site-packages/nltk/corpus/util.py", line 99, in __getattr__
self.__load()
File "/global/python/2.7.5/lib/python2.7/site-packages/nltk/corpus/util.py", line 67, in __load
corpus = self.__reader_cls(root, *self.__args, **self.__kwargs)
File "/global/python/2.7.5/lib/python2.7/site-packages/nltk/corpus/reader/wordnet.py", line 1045, in __init__
self._load_lemma_pos_offset_map()
File "/global/python/2.7.5/lib/python2.7/site-packages/nltk/corpus/reader/wordnet.py", line 1137, in _load_lemma_pos_offset_map
self._lemma_pos_offset_map[lemma][pos] = synset_offsets
MemoryError