如何使用 python 在 spaCy 中执行预处理步骤,例如停用词删除、标点符号删除、词干提取和词形还原。
我在 csv 文件中有文本数据,如段落和句子。我想做文本清理。
请通过在 pandas 数据框中加载 csv 来举例说明
最佳答案
这可能有帮助:
import spacy #load spacy
nlp = spacy.load("en", disable=['parser', 'tagger', 'ner'])
stops = stopwords.words("english")
def normalize(comment, lowercase, remove_stopwords):
if lowercase:
comment = comment.lower()
comment = nlp(comment)
lemmatized = list()
for word in comment:
lemma = word.lemma_.strip()
if lemma:
if not remove_stopwords or (remove_stopwords and lemma not in stops):
lemmatized.append(lemma)
return " ".join(lemmatized)
Data['Text_After_Clean'] = Data['Text'].apply(normalize, lowercase=True, remove_stopwords=True)
关于python - 如何使用 spaCy 进行文本预处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45605946/