Python - 单词标记化

Python - 单词标记化 首页 / 数据科学入门教程 / Python - 单词标记化

单词标签化是将大量文本样本拆分为单词的过程,这是自然语言处理任务的要求,其中每个单词都需要捕获并接受以便进一步分析,如对特定情感进行分类和计数等,自然语言工具包(NLTK)是用于实现此目的的库,在继续进行python之前安装NLTK 单词标签化程序。

conda install -c anaconda 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', 'new', 'skills', 'from', 'the',
'comforts', 'of', 'their', 'drawing', 'rooms']

标签化句子

也可以像标签词一样标签段落中的句子,使用方法 sent_tokenize 实现此目的,下面是一个示例。

import nltk
sentence_data = "Sun rises in the east. Sun sets in the west."
nltk_tokens = nltk.sent_tokenize(sentence_data)
print (nltk_tokens)

当无涯教程执行上面的代码时,它将产生以下输出。

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/python-data-science/python-word-tokenization.html

来源:LearnFk无涯教程网

['Sun rises in the east.', 'Sun sets in the west.']

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Service Mesh实践指南 -〔周晶〕

从0开始做增长 -〔刘津〕

Python核心技术与实战 -〔景霄〕

高并发系统设计40问 -〔唐扬〕

Java业务开发常见错误100例 -〔朱晔〕

软件设计之美 -〔郑晔〕

攻克视频技术 -〔李江〕

React Native 新架构实战课 -〔蒋宏伟〕

遗留系统现代化实战 -〔姚琪琳〕

好记忆不如烂笔头。留下您的足迹吧 :)