其他分享
首页 > 其他分享> > 词性标注的简单综述

词性标注的简单综述

作者:互联网

今天总结一下自然语言处理之词性标注,后附现有比较好的开源实现工具(基于python实现包)~~~


词性定义

词性标注就是在给定句子中判定每个词的语法范畴,确定其词性并加以标注的过程,这也是自然语言处理中一项非常重要的基础性工作,所有对于词性标注的研究已经有较长的时间,在研究者长期的研究总结中,发现汉语词性标注中面临了许多棘手的问题。


中文词性标注的难点

词性标注常见方法

基于规则的词性标注方法

import nltk
nltk.download("punkt")
nltk.download("averaged_perceptron_tagger")
nltk.download('tagsets')
s = "i enjoy playing the piano"
tokens = nltk.word_tokenize(s)
tags = nltk.pos_tag(tokens)
print(tags)

 

基于统计模型的词性标注方法(又称为基于随机的词性标注法)

  

基于统计方法与规则方法相结合的词性标注方法

基于深度学习的词性标注方法

**词性标注任务数据集 **

import spacy
nlp = spacy.load('en_core_web_sm')
doc = nlp(u"ans so i said i'm going to play the piano for the paly tonight")
for token in doc:
    print(doc.text,token.pos_,token.tag_)

分块标记

分块就是根据句子中的词和词性,按照某种规则组合在一起形成一个个分块,每个分块代表一个实体。常见的实体包括:组织、人员、地点、日期、时间

以上面的例子为例,首先我们做名词短语分块(NP-chunking),比如:技术问题。名词短语分块通过词性标记和一些规则就可以识别出来,也可以通过机器学习的方法识别

除了名词短语分块还有很多其他分块:介词短语(PP,比如:以我……)、动词短语(VP,比如:打人)、句子(S,我是人)

import nltk
rule = r"""Noun Phrase:{<DT>?<JJ>*<NN>}"""
chunkparse = nltk.RegexpParser(rule)
chunked = chunkparse.parse(nltk.pos_tag(nltk.word_tokenize("and so i said i am going to play the piano tonight for the play tonight")))
chunked.draw()
print(chunked)

         加缝是把分块的内容提取出来其他的内容认为不重要被忽视

         如下面的代码是提取名词

import nltk
rule = r"""Chink: {<.*>+}
}<VB.?|CC|RB|JJ|IN|DT|TO|>+{"""
chunkparse = nltk.RegexpParser(rule)
chunked = chunkparse.parse(nltk.pos_tag(nltk.word_tokenize("and so i said i am going to play the piano tonight for the play tonight")))
chunked.draw()
print(chunked)

 

                           

词性标注工具推荐

最新研究进展看这里https://github.com/sebastianruder/NLP-progress/blob/master/english/part-of-speech_tagging.md


本文转自:tps://www.jianshu.com/p/940464a662b0

标签:词性,综述,https,com,nltk,词类,标注
来源: https://www.cnblogs.com/henuliulei/p/13737190.html