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文本分析
准备统计和机器学习的文本数据
137
4.7.3
持久地保存结果
最后,我们将完整的数据框保存到
SQLite
。为此,我们需要将提取的列表转化为以
空格分隔的字符串,因为大多数数据库不支持列表:
df[nlp_columns] = df[nlp_columns].applymap(lambda items: ' '.join(items))
con = sqlite3.connect(db_name)
df.to_sql("posts_nlp", con, index=False, if_exists="replace")
con.close()
上述生成的表格为进一步分析提供了坚实且随时可用的基础。实际上,我们将在第
10
章中再次使用该数据,在提取出的词元上训练单词嵌入。当然,预处理的具体步
骤取决于需要处理的数据。我们的解决方案生成的单词集合非常适合基于词频的统
计分析以及基于词袋向量化的机器学习。如果算法需要了解单词序列,则需要调整
相应的步骤。
4.7.4
有关执行时间的注意事项
完整的语言处理非常耗时。实际上,使用
spaCy
处理
1
万个
Reddit
帖子需要花费几
分钟的时间。相比之下,简单的正则表达式分词器只需要几秒钟即可在同一台机器
上完成所有记录的分词。尽管与其他库相比,
spaCy
确实非常快,但是,标注词性、
解析和识别命名实体等步骤的开销非常大。因此,如果你不需要命名实体的话,一
定要禁用解析器和命名实体识别,这样可以节省
60%
以上的运行时间。
使用
nlp.pipe
批量处理数据,以及使用
GPU
是加快 ...
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