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 实现此目的,下面是一个示例。

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

来源:LearnFk无涯教程网

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

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

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

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

技术教程推荐

设计模式之美 -〔王争〕

摄影入门课 -〔小麥〕

RPC实战与核心原理 -〔何小锋〕

技术管理案例课 -〔许健〕

Spark性能调优实战 -〔吴磊〕

爆款文案修炼手册 -〔乐剑峰〕

Web漏洞挖掘实战 -〔王昊天〕

JavaScript进阶实战课 -〔石川〕

程序员职业规划手册 -〔雪梅〕

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