当前位置: 首页 > news >正文

上海嘉定网站有趣的软文

上海嘉定网站,有趣的软文,网站开发大牛,企业vi设计全套包括一、文本的基本单位 1、Token 定义:文本的最小单位,例如单词、标点符号。 示例: 原句: "I love NLP." 分词结果: [I, love, NLP, .] 2、语法与语义 语法:词的结构和句子的组合规则。 语义&a…

一、文本的基本单位

1、Token

定义:文本的最小单位,例如单词、标点符号。

示例:

原句: "I love NLP."

分词结果: ['I', 'love', 'NLP', '.']

2、语法与语义

语法:词的结构和句子的组合规则。

语义:词的含义和上下文理解。

示例:

句子 "Time flies like an arrow." 有多重解释:

时间像箭一样飞逝。

像箭一样的飞虫在时间中飞翔。

二、基本的文本预处理

1、分词(Tokenization)

  • 英文分词:基于空格或标点分隔。
  • 中文分词:基于统计和规则的方法,如 Jieba。

2、去停用词

停用词:意义较小或频率过高的词,例如 "the", "is", "and"。

3、词干化

将词语削减为根形式,例如 running → run。

4、词形还原

考虑语法规则还原为词的基本形式,例如 mice → mouse。

三、用nltk库做文本预处理

NLTK(Natural Language Toolkit) 是一个功能强大、 灵活性高的开源 Python 库, 专为自然

语言处理(NLP) 领域的研究和开发而设计。 NLTK 提供了一套丰富的工具和资源, 适合处

理、分析和理解人类语言文本。

1、文本预处理包

  • 分词: nltk.tokenize.word_tokenize
  • 停用词库: nltk.corpus.stopwords
  • 词干化: nltk.stem.PorterStemmer
  • 词形还原: nltk.stem.WordNetLemmatizer

2、案例

使用 Python 对自己的文本数据进行分词、去停用词操作,并计算剩余单词的数量

文本如下:

"Dr. Smith's favorite movie in 2024 is 'Inception'; he rates it 9/10 stars! Isn't that amazing? Let's analyze this #text with NLP techniques: @homework1.py, line 42."

代码如下:

from nltk import pos_tag
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
from nltk.stem import PorterStemmer,WordNetLemmatizerfrom src.common import utildef text_prepare(text):#分词print(f"原始文本:{text}")tokens = word_tokenize(text)print(f"分词后:{tokens}")#去除停用词en_stopwords  = stopwords.words('english') #获取英文停用词表print(f"去除停用词前文本长度:{len(tokens)}")filter_stop_words = []for token in tokens:token = token.lower()if token not in en_stopwords:filter_stop_words.append(token)print(f"去除停用词后文本:{filter_stop_words}")print(f"去除停用词后文本长度:{len(filter_stop_words)}")#词干化prepare_stem = []porter_stemmer = PorterStemmer()for token in filter_stop_words:token = porter_stemmer.stem(token)prepare_stem.append(token)print(f"词干化后:{prepare_stem}")#词性标注tagged_pos = pos_tag(filter_stop_words)print(f"词性标注后:{tagged_pos}")#词形还原prepare_lemma = []wordnetLemma = WordNetLemmatizer()for word, pos in tagged_pos:prepare_lemma.append(wordnetLemma.lemmatize(word,util.get_wordnet_pos(pos)))print(f"词形还原后:{prepare_lemma}")def main():file_path = "example"with(open(file_path, "r", encoding="utf-8")) as file:text = file.read()text_prepare(text)if __name__ == '__main__':main()

运行结果:

原始文本:"Dr. Smith's favorite movie in 2024 is 'Inception'; he rates it 9/10 stars! Isn't that amazing? Let's analyze this #text with NLP techniques: @homework1.py, line 42."分词后:['``', 'Dr.', 'Smith', "'s", 'favorite', 'movie', 'in', '2024', 'is', "'Inception", "'", ';', 'he', 'rates', 'it', '9/10', 'stars', '!', 'Is', "n't", 'that', 'amazing', '?', 'Let', "'s", 'analyze', 'this', '#', 'text', 'with', 'NLP', 'techniques', ':', '@', 'homework1.py', ',', 'line', '42', '.', "''"]去除停用词前文本长度:40去除停用词后文本:['``', 'dr.', 'smith', "'s", 'favorite', 'movie', '2024', "'inception", "'", ';', 'rates', '9/10', 'stars', '!', "n't", 'amazing', '?', 'let', "'s", 'analyze', '#', 'text', 'nlp', 'techniques', ':', '@', 'homework1.py', ',', 'line', '42', '.', "''"]
去除停用词后文本长度:32词干化后:['``', 'dr.', 'smith', "'s", 'favorit', 'movi', '2024', "'incept", "'", ';', 'rate', '9/10', 'star', '!', "n't", 'amaz', '?', 'let', "'s", 'analyz', '#', 'text', 'nlp', 'techniqu', ':', '@', 'homework1.pi', ',', 'line', '42', '.', "''"]词性标注后:[('``', '``'), ('dr.', 'NN'), ('smith', 'NN'), ("'s", 'POS'), ('favorite', 'JJ'), ('movie', 'NN'), ('2024', 'CD'), ("'inception", 'NN'), ("'", "''"), (';', ':'), ('rates', 'NNS'), ('9/10', 'CD'), ('stars', 'NNS'), ('!', '.'), ("n't", 'RB'), ('amazing', 'VBG'), ('?', '.'), ('let', 'NN'), ("'s", 'POS'), ('analyze', 'JJ'), ('#', '#'), ('text', 'JJ'), ('nlp', 'NN'), ('techniques', 'NNS'), (':', ':'), ('@', 'NN'), ('homework1.py', 'NN'), (',', ','), ('line', 'NN'), ('42', 'CD'), ('.', '.'), ("''", "''")]词形还原后:['``', 'dr.', 'smith', "'s", 'favorite', 'movie', '2024', "'inception", "'", ';', 'rate', '9/10', 'star', '!', "n't", 'amaze', '?', 'let', "'s", 'analyze', '#', 'text', 'nlp', 'technique', ':', '@', 'homework1.py', ',', 'line', '42', '.', "''"]

http://www.hkea.cn/news/137174/

相关文章:

  • 网站做cdn怎么弄百度推广怎么推广
  • 光谷做网站推广竞价服务托管公司
  • 网上商城网站建设方案书公众号seo排名
  • wordpress内网访问泰州百度关键词优化
  • 做淘客网站用备案网络营销计划书怎么写
  • 网站 公安 备案深圳百度推广客服电话多少
  • 北京米兰广告设计有限公司广州优化疫情防控举措
  • 汕头个人建站模板网站推广计划方法
  • php企业网站无限制源码网络营销方案设计
  • 动漫网站开发与建设百度网盘网页版入口官网
  • 咸阳做网站长沙网络营销外包哪家好
  • 专门做私人定制旅游的网站搜索引擎营销方法
  • 注册安全工程师管理系统网奇seo赚钱培训
  • 武汉市住房和城乡建设厅官方网站生猪价格今日猪价
  • 住房和城乡建设部网站诚信评价搜索引擎优化人员优化
  • 网站制作 太原网络营销专业课程
  • 做网站去哪个公司网络营销策划书的结构
  • 个人无网站怎样做cps广告深圳全网推广公司
  • 中国人可以做的c2c网站上海网站排名推广
  • 网站建设目标定位公司员工培训方案
  • 美工培训班学百度自然搜索排名优化
  • 网站建设自学多长时间搜索引擎营销的过程
  • 做cpa的网站源码seo的外链平台有哪些
  • 那个网站做外贸最好成都网站建设方案外包
  • 企业网站建设效益分析联合早报 即时消息
  • html5网页成品代码自媒体seo优化
  • 门户网站建设招投标网络seo啥意思
  • 游戏币销售网站建设百度热搜seo
  • 线上投票链接怎么做厦门搜索引擎优化
  • 网页设计课程主要内容seo学校