自然语言处理学习 - NLTK 预热篇

  •  NLTK 在NLP上的经典应用: 情感分析、文本相似度、文本分类

  1. 【转载】NLTK 基本功能介绍:python的nltk中文使用和学习资料汇总帮你入门提高 - 作者:糊糊
  2.  文本处理的流程
  3.  TF-IDF 的学习

1) 自带语料库的使用:


#自带语料库使用
from nltk.corpus import brown
brown.categories()
['adventure',
 'belles_lettres',
 'editorial',
 'fiction',
 'government',
 'hobbies',
 'humor',
 'learned',
 'lore',
 'mystery',
 'news',
 'religion',
 'reviews',
 'romance',
 'science_fiction']

2) 文本处理的流程:


    #0, Raw_Text 最初始的文本
    #1, Tokenize 分词或分句
    #2, POS Tag 词形标注
    #3, Lemma/Stemming 提取词干、词形归一
    #4, stopwords 去停词表中的词语
    #5, Word_List
    #6, ML模型:神经网络、SVM、LR、RF、LSTM等等

#### 2.1 Tokenize :断词 - 把长句子拆分为有“意义”的小部件

#https://blog.csdn.net/bentley2010/article/details/79340827#Python数据挖掘-NLTK文本分析+jieba中文文本挖掘
import nltk
sentence = " hello, world"
tokens = nltk.word_tokenize(sentence)
tokens
#中文分词
#import jieba
# 输出:['hello', ',', 'world']
#举例,有时候需要处理一些符号, 表情
from nltk.tokenize import word_tokenize
tweet = 'RT @angelababy: love you baby! :D http://ah.love #168#'
print(word_tokenize(tweet))
#输出:['RT', '@', 'angelababy', ':', 'love', 'you', 'baby', '!', ':', 'D', 'http', ':', '//ah.love', '#', '168', '#']

#### 2.2 正则表达式学习:http://www.regexlab.com/zh/regref.htm 需要研究一下

#### 2.3 词形归一化处理:    Stemming 词干提取;  Lemmatization词形归一

#####  NLTK 实现 Stemming

#Stemming java代码解析:http://qinxuye.me/article/porter-stemmer/
from nltk.stem.porter import PorterStemmer #后缀剥离的词干提取算法:波特词干器
porter_stemmer = PorterStemmer()
print(porter_stemmer.stem('multiply'))
print(porter_stemmer.stem('provision'))
print("***************分割线*************")
from nltk.stem.lancaster import LancasterStemmer
lancaster_stemmer = LancasterStemmer()
print(lancaster_stemmer.stem('multiply'))
print(lancaster_stemmer.stem('provision'))
print("***************分割线*************")
from nltk.stem import SnowballStemmer
snowball_stemmer = SnowballStemmer("english")
print(snowball_stemmer.stem('multiply'))
print(snowball_stemmer.stem('presumably'))
print("***************分割线*************")
from nltk.stem.porter import PorterStemmer
p = PorterStemmer()
print(p.stem('went'))
print(p.stem('wenting'))

输出

multipli
provis
***************分割线*************
multiply
provid
***************分割线*************
multipli
presum
***************分割线*************
went
went

##### NLTK 实现 Lemma

from nltk.stem import WordNetLemmatizer
wordnet_lemmatizer = WordNetLemmatizer()
print("***************分割线*************")
print(wordnet_lemmatizer.lemmatize('dogs'))
print(wordnet_lemmatizer.lemmatize('chhurches'))

输出

***************分割线*************
dog
chhurches
Went
# Lemma小问题: Went ->  它动词可以表示go的过去式, 名词可以表示英文名:温特
# 没有POS Tag, 默认是NN 名词
print(wordnet_lemmatizer.lemmatize('are'))
print(wordnet_lemmatizer.lemmatize('is'))
print("***************分割线*************")
print(wordnet_lemmatizer.lemmatize('are', pos = 'v')) #加上了动词的属性
print(wordnet_lemmatizer.lemmatize('is', pos = 'v'))

输出:

are
is
***************分割线*************
be
be

#### 2.4 通过POS_Tag词性标注

text = nltk.word_tokenize('what does the cat say')
print(text)
print(nltk.pos_tag(text))
['what', 'does', 'the', 'cat', 'say']
[('what', 'WDT'), ('does', 'VBZ'), ('the', 'DT'), ('cat', 'NNS'), ('say', 'VBP')]

#### 2.5 去除Stopwords :https://www.ranks.nl/stopwords
from nltk.corpus import stopwords
from nltk.tokenize import sent_tokenize,word_tokenize
example_text = 'In 2008, Facebook set up its international headquarters in Ireland to take advantage of the country\'s low corporate tax rates but it also meant all users outside the US and Canada were protected by European regulations.' 
#导入英文停止词,set()集合函数消除重复词
list_stopWords = list(set(stopwords.words('english')))
#分句
list_sentences = sent_tokenize(example_text)
#分词
list_words = word_tokenize(example_text)
#过滤停止词语
filtered_words = [w for w in list_words if not w in list_stopWords]
filtered_words
['In',
 '2008',
 ',',
 'Facebook',
 'set',
 'international',
 'headquarters',
 'Ireland',
 'take',
 'advantage',
 'country',
 "'s",
 'low',
 'corporate',
 'tax',
 'rates',
 'also',
 'meant',
 'users',
 'outside',
 'US',
 'Canada',
 'protected',
 'European',
 'regulations',
 '.']

## 3)TF-IDF

【转】基于TF-IDF算法抽取文章关键词

【转】 TF-IDF算法解析与Python实现(基于sklearn)





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 自然语言处理(Natural Language Processing,简称NLP)是计算机科学与人工智能领域的一个重要研究方向,目的是让计算机能够理解、处理和生成人类的自然语言。NLP-100例是一份经典的NLP问题集合,包含了各种与自然语言处理相关的问题和挑战。 这份NLP-100例涵盖了从基础的文本处理到更高级的自然语言理解和生成的问题。例如,其中包括了文本预处理、词频统计、语法分析、词性标注、实体识别、情感分析、机器翻译等任务。 NLP-100例的目的是帮助研究者和开发者更好地理解NLP领域的核心问题和技术,同时提供一些典型的案例和数据集供实践和研究使用。通过完成这些例题,可以锻炼自己在NLP领域的能力和技术,提高对自然语言的处理和理解能力。 此外,NLP-100例也为研究者提供了一个可以与其他人交流和探讨的平台。研究者可以使用相同的数据集和问题进行实验和评估,从而更好地了解NLP技术的优劣和进展。 总之,NLP-100例是一个对NLP进行实践和研究的重要资源。通过解决这些例题,可以深入理解自然语言处理的基础和技术,掌握各种NLP任务的方法和技巧。同时,它也是一个促进交流和合作的平台,为NLP研究者提供了一个共同的基础和语言。 ### 回答2: 自然语言处理(Natural Language Processing,简称NLP)是研究计算机与人类自然语言之间的交互的一门学科。NLP-100例指的是日本的一个NLP入门教程,包含了100个常见的NLP问题和对应的解答。 NLP-100例涵盖了从文本处理到语义理解等多个方面的问题。其中,一些例子包括:文本的分词、词性标注、句法分析、语义角色标注和文本分类等。 以分词为例,分词是将一段连续的文本分割成词语的过程。在NLP-100例中,可以通过使用Python中的分词工具NLTK(Natural Language Toolkit)来实现分词功能。 另外,对于文本的词性标注,NLP-100例提供了使用POS(Part-Of-Speech)标记对文本中的每个词进行词性标注的方法。可以使用NLTK提供的POS标注工具来实现。 此外,NLP-100例还包括了语义角色标注的问题,语义角色标注是为了确定句子中的谓语动词所承担的语义角色,如施事者、受事者、时间等。可以使用Stanford CoreNLP工具包来实现语义角色标注。 最后,NLP-100例还介绍了文本分类的问题,文本分类是将文本划分到预定义的类别中。可以使用机器学习算法,如朴素贝叶斯或支持向量机(SVM)等来进行文本分类。 通过学习NLP-100例,我们可以了解到自然语言处理的基本方法和技术,并且可以利用这些技术来解决相关的自然语言处理问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值