【问题标题】:removing stopwords after word tokenizing and lower casing [duplicate]在单词标记和小写后删除停用词[重复]
【发布时间】:2019-04-08 13:11:21
【问题描述】:

我是 NLP 新手,在执行以下任务时面临一些挑战。 我想执行这些任务顺序。 1.Sentence Tokenize 2.对每个句子进行词标记 3.小写 4.停止词删除 5.对每个单词进行词形还原

我试图写一个函数来完成上述任务

import nltk
import numpy as np
import random
import string
from nltk.corpus import stopwords

def text_processing(input_str):
    tokens = nltk.sent_tokenize(input_str)#sentence tokenizing
    for words in tokens:
        each_word = nltk.word_tokenize(words)#word tokeninzing
        for i in each_word:
            lower_words = i.lower()
            stopwords_removed = [w for w in lower_words if not w in stopwords]
            print(stopwords_removed)

当我调用上述函数时

text_processing(new_doc)

我收到此错误:TypeError:“LazyCorpusLoader”类型的参数不可迭代。如何克服这个错误。

【问题讨论】:

标签: python nltk


【解决方案1】:

您不能直接使用停用词。
相反,您应该首先通过在 Jupyter 或终端中输入以下内容来下载资源:

nltk.download()

然后会出现下载器,选择语料库 -> 停用词,然后下载。

然后你可以这样使用停用词:

my_stopwords = set(stopwords.words('english'))

参考:
https://www.geeksforgeeks.org/removing-stop-words-nltk-python/
NLTK and Stopwords Fail #lookuperror

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 2021-08-18
    • 2013-07-11
    • 2015-05-25
    • 1970-01-01
    • 1970-01-01
    • 2013-06-10
    相关资源
    最近更新 更多