Skip to Content
Python文本分析
book

Python文本分析

by Jens Albrecht, Sidharth Ramachandran, Christian Winkler
August 2022
Intermediate to advanced
441 pages
11h 26m
Chinese
China Electric Power Press Ltd.
Content preview from Python文本分析
24
1
NLTK spaCy 的停用词列表都包含“I”和“don
t”(“do not”也一样)。
如果你删除这两个停用词,那么就只剩下“like ice cream.”。这种预处理会对
情感分析造成严重的影响。本节后面介绍的 TF-IDF 加权会自动降低频繁出现
的单词的权重,但依然会将这些词条保留在词汇表中。
另外,我们可以将
80%
以上的文档中出现的单词视为停用词,这些单词可以作为固
定停用词列表的补充,也可以代替停用词列表。这些常见词会导致区分内容的难度
加大。向量化器
scikit-learn
的参数
max_df
可以做这样的处理,详情请参见第
5
的介绍。还有一种方法是根据单词的类型(词性)进行过滤。我们将在第
4
章中详
细解释这个概念。
1.5.3
通过一行代码处理流水线
我们再来看一看包含语料库文档的数据框。我们想新建一个名叫
tokens
的列,其中
包含分词后的小写文本,而且每个文档都没有停用词。为此,我们来进一步扩展处
理流水线。在这个例子中,我们将所有文本转换成小写,然后进行分词,最后再删
除停用词。我们只需简单地扩展流水线即可添加其他操作:
pipeline = [str.lower, tokenize, remove_stop]
def prepare(text, pipeline):
tokens = text
for transform in pipeline:
tokens = transform(tokens)
return tokens
如果我们将上述所有代码放到一个函数中,就会非常适合 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

精益AI

精益AI

Lomit Patel
构建知识图谱

构建知识图谱

Jesus Barrasa, Jim Webber
写给系统管理员的Python脚本编程指南

写给系统管理员的Python脚本编程指南

Posts & Telecom Press, Ganesh Sanjiv Naik

Publisher Resources

ISBN: 9787519864446