Python数据操作—单词标记化

单词标记是将大量文本样本分解为单词的过程。 这是自然语言处理任务中的一项要求,每个单词需要被捕获并进行进一步的分析,如对特定情感进行分类和计数等。自然语言工具包(NLTK)是用于实现这一目的的库。 在继续使用python程序进行字词标记之前,先安装NLTK。
命令:
conda install -c anaconda nltk
nltk.download('punkt')

当出现下面这种,表示安装nltk成功,
这里写图片描述

下面就可以使用word_tokenize方法将段落拆分为单个单词,代码:

#拆分单词
import nltk
word_data = "It originated from the idea that there are readers who prefer learning new skills from the comforts of their drawing rooms"
nltk_tokens = nltk.word_tokenize(word_data)
print (nltk_tokens)

结果:

['It', 'originated', 'from', 'the', 'idea', 'that', 'there', 'are', 'readers', 
'who', 'prefer', 'learning'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值