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文本分析
特征工程与句法相似性
143
常简单,而且本身的计算非常快,因此首先我们就来看一看这些映射,并将这些单
词作为特征使用。
在第一个案例中,我们将重点介绍这些方法,因此我们使用数据集的是查尔斯
·
更斯所著的一部小说《双城记》(
https://oreil.ly/rfmPH
)中的一些句子。我们将使
用下列句子:
It was the best of times.
It was the worst of times.
It was the age of wisdom.
It was the age of foolishness.
5.3
案例:构建自己的向量化器
由于向量化文档是本书所有后续章节的基础,因此我们来深入一下研究
向量化器的工作方式。而最好的方式莫过于构建自己的向量化器。如果
你需要在自己的项目中实现自定义的向量化器,则可以使用本节介绍的方法;或者
你也可以改编某个已有的向量化器,以满足自己的需求。
为了尽量简单,我们来实现一个“
one-hot
向量化器”。这个向量化器会创建文档的
二元向量:如果某个单词出现在文档中,则为
1
,否则为
0
首先,我们来创建一个词汇表,并为这些单词指定数字;然后执行向量化;最后在
这个二元空间中分析相似性。
5.3.1
枚举词汇表
首先,为了将单词作为特征,我们需要找到一种方法将单词转化成向量的维度。从
文本中提取单词的工作可以通过分词完成,请参见第
2
章的介绍。
2
由于我们只对某个单词是否出现在文档中感兴趣,因此可以直接枚举每个单词:
2 有很多更复杂的确定词汇表的方法,例如 ...
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