【发布时间】:2021-07-19 00:49:54
【问题描述】:
我正在用gensim 实现一个简单的doc2vec,不是 word2vec
我需要在不丢失正确顺序的情况下删除停用词。
每个列表都是一个文档,正如我对 doc2vec 的理解,模型将输入一个 TaggedDocuments 列表
model = Doc2Vec(lst_tag_documents, vector_size=5, window=2, min_count=1, workers=4)
dataset = [['We should remove the stopwords from this example'],
['Otherwise the algo'],
["will not work correctly"],
['dont forget Gensim doc2vec takes list_of_list' ]]
STOPWORDS = ['we','i','will','the','this','from']
def word_filter(lst):
lower=[word.lower() for word in lst]
lst_ftred = [word for word in lower if not word in STOPWORDS]
return lst_ftred
lst_lst_filtered= list(map(word_filter,dataset))
print(lst_lst_filtered)
输出:
[['we should remove the stopwords from this example'], ['otherwise the algo'], ['will not work correctly'], ['dont forget gensim doc2vec takes list_of_list']]
预期输出:
[[' should remove the stopwords example'], ['otherwise the algo'], [' not work correctly'], ['dont forget gensim doc2vec takes list_of_list']]
-
我的错误是什么以及如何解决?
-
还有其他有效的方法可以解决这个问题而不会丢失 顺序正确吗?
提问前我检查的问题列表:
How to apply a function to each sublist of a list in python?
- 我对此进行了研究并尝试将其应用于我的具体案例
Removing stopwords from list of lists
- 顺序很重要我不能用set
Removing stopwords from a list of text files
- 这可能是一个可能的解决方案,类似于我已实施的解决方案。
- 我不明白这种差异,但我不知道如何处理它。 在我的情况下,文档没有被标记(并且不应该被标记,因为是 doc2vec 而不是 word2vec)
How to remove stop words using nltk or python
- 在这个问题中,SO 处理的是列表而不是列表
【问题讨论】:
标签: python list gensim stop-words