我编写了此函数,并得到TypeError:不可哈希类型:'list'。我该如何解决?
def get_words(txt):
a=(lambda x: x not in STOP_WORDS), re.findall(r'\b(\w+)\b', txt)
return a
def sentence_words(text):
line = text.strip().lower()
sent_tokenize1=sent_tokenize(line)
sent_wordsmap=list(map(get_words,sent_tokenize1))
return sent_wordsmap
sent_word=sentence_words(text)
model = Word2Vec(sent_word, size=128, window=3, min_count=5, workers=4)
TypeError:不可散列的类型:'列表'
用此替换您的get_words
。
def get_words(txt):
a = list(filter(lambda x: x not in STOP_WORDS, re.findall(r'\b(\w+)\b', txt)))
return a