0

我正在尝试在 python (google-colaboratory) 中为 CountVectorizer() 使用波斯语停用词。我不知道我应该如何将波斯语停用词作为参数提供给函数

例如,是一个波斯语停用词列表,但我不知道如何将列表提供给我的代码

vect = CountVectorizer(stop_words='persian', tokenizer = hazm.word_tokenize).fit(txt)

4

2 回答 2

1

您可以简单地将所有这些停用词放在 python 中list,然后将列表传递给CountVectorizer. 例如:

persian_stop_words = ["در", "این"]
vect = CountVectorizer(stop_words=persian_stop_words)
于 2020-03-13T06:16:09.907 回答
0

您可以使用这个开源存储库来查找波斯语停用词的集合:
https ://github.com/kharazi/persian-stopwords

要加载它们,只需将行复制并粘贴到单个文件中(由新行分隔),然后将其称为“stopwords.data”。然后你可以在你的项目中加载文件并将加载的文件作为你的 CountVectorizer "stop_words" 参数:

persian_stop_words = loadtxt('stopwords.dat', dtype=str, delimiter='\n')
vect = CountVectorizer(stop_words=persian_stop_words)
于 2021-05-10T06:17:44.980 回答