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)

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

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

来源:LearnFk无涯教程网

['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)

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

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

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

技术教程推荐

软件测试52讲 -〔茹炳晟〕

透视HTTP协议 -〔罗剑锋(Chrono)〕

Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕

后端技术面试 38 讲 -〔李智慧〕

SRE实战手册 -〔赵成〕

手把手教你玩音乐 -〔邓柯〕

如何讲好一堂课 -〔薛雨〕

零基础学Python(2023版) -〔尹会生〕

云原生架构与GitOps实战 -〔王炜〕

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