Nlp 在词性标注之前,我们需要使用停止词过滤吗?

Nlp 在词性标注之前,我们需要使用停止词过滤吗?,nlp,text-mining,pos-tagger,Nlp,Text Mining,Pos Tagger,我不熟悉文本挖掘和NLP相关的东西。我正在从事一个小项目,试图从一些文档中提取信息。我基本上是在做词性标注,然后使用chunker根据标注的单词找出模式。在做词性标注之前,我需要使用Stopwords吗?使用Stopwords会影响我的词性吗tagger的准确度?什么是@lenz说的。不要在标记之前删除stopwords,或者在进行块处理之前删除stopwords,除非您正在训练一个块处理程序,并且您决定在清理的文本上训练它(然后使用它)。但我也不建议这样做。停止词删除适用于像TF-IDF这样的

我不熟悉文本挖掘和NLP相关的东西。我正在从事一个小项目,试图从一些文档中提取信息。我基本上是在做词性标注,然后使用chunker根据标注的单词找出模式。在做词性标注之前,我需要使用Stopwords吗?使用Stopwords会影响我的词性吗tagger的准确度?

什么是@lenz说的。不要在标记之前删除stopwords,或者在进行块处理之前删除stopwords,除非您正在训练一个块处理程序,并且您决定在清理的文本上训练它(然后使用它)。但我也不建议这样做。停止词删除适用于像TF-IDF这样的词包过程,但像限定词和介词这样的常用词提供了有关句子结构以及词性的基本线索。如果要检测句子单位,请不要删除它们

但为什么要相信我的话呢?你可以很容易地检查自己,采取一点标记的数据,并评估你的标记器和分块器与否停止字删除。我建议您在管道的其余部分都这样做。

让我们以培训/测试标记器为例:

>>> uni_tag = UnigramTagger(train_set)
首先获取语料库和停止列表

>>> import nltk
>>> nltk.download('stopwords')
>>> nltk.download('cess_esp')
在NLTK中加载包装器

>>> from nltk.corpus import cess_esp as cess
>>> from nltk.corpus import stopwords

# Import the function to train a tagger.
>>> from nltk import UnigramTagger, BigramTagger
# Load the Spanish stopwords
>>> stoplist = stopwords.words('spanish')
# Load the Spanish tagger
>>> cess_sents = cess.tagged_sents()
将语料库拆分为训练集/测试集

>>> len(cess_sents)
6030
>>> test_set = cess_sents[-int(6030/10):]
>>> train_set = cess_sents[:-int(6030/10)]
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(10)[-2:]
[8, 9]
>>> range(10)[:-2]
[0, 1, 2, 3, 4, 5, 6, 7]
创建一个无停止字的备用列车集

>>> train_set_nostop = [[(word,tag) for word, tag in sent if word.lower() not in stoplist] for sent in train_set]
请看区别:

>>> train_set[0]
[(u'El', u'da0ms0'), (u'grupo', u'ncms000'), (u'estatal', u'aq0cs0'), (u'Electricit\xe9_de_France', u'np00000'), (u'-Fpa-', u'Fpa'), (u'EDF', u'np00000'), (u'-Fpt-', u'Fpt'), (u'anunci\xf3', u'vmis3s0'), (u'hoy', u'rg'), (u',', u'Fc'), (u'jueves', u'W'), (u',', u'Fc'), (u'la', u'da0fs0'), (u'compra', u'ncfs000'), (u'del', u'spcms'), (u'51_por_ciento', u'Zp'), (u'de', u'sps00'), (u'la', u'da0fs0'), (u'empresa', u'ncfs000'), (u'mexicana', u'aq0fs0'), (u'Electricidad_\xc1guila_de_Altamira', u'np00000'), (u'-Fpa-', u'Fpa'), (u'EAA', u'np00000'), (u'-Fpt-', u'Fpt'), (u',', u'Fc'), (u'creada', u'aq0fsp'), (u'por', u'sps00'), (u'el', u'da0ms0'), (u'japon\xe9s', u'aq0ms0'), (u'Mitsubishi_Corporation', u'np00000'), (u'para', u'sps00'), (u'poner_en_marcha', u'vmn0000'), (u'una', u'di0fs0'), (u'central', u'ncfs000'), (u'de', u'sps00'), (u'gas', u'ncms000'), (u'de', u'sps00'), (u'495', u'Z'), (u'megavatios', u'ncmp000'), (u'.', u'Fp')]
>>> train_set_nostop[0]
[(u'grupo', u'ncms000'), (u'estatal', u'aq0cs0'), (u'Electricit\xe9_de_France', u'np00000'), (u'-Fpa-', u'Fpa'), (u'EDF', u'np00000'), (u'-Fpt-', u'Fpt'), (u'anunci\xf3', u'vmis3s0'), (u'hoy', u'rg'), (u',', u'Fc'), (u'jueves', u'W'), (u',', u'Fc'), (u'compra', u'ncfs000'), (u'51_por_ciento', u'Zp'), (u'empresa', u'ncfs000'), (u'mexicana', u'aq0fs0'), (u'Electricidad_\xc1guila_de_Altamira', u'np00000'), (u'-Fpa-', u'Fpa'), (u'EAA', u'np00000'), (u'-Fpt-', u'Fpt'), (u',', u'Fc'), (u'creada', u'aq0fsp'), (u'japon\xe9s', u'aq0ms0'), (u'Mitsubishi_Corporation', u'np00000'), (u'poner_en_marcha', u'vmn0000'), (u'central', u'ncfs000'), (u'gas', u'ncms000'), (u'495', u'Z'), (u'megavatios', u'ncmp000'), (u'.', u'Fp')]
>>>
训练一个贴标签的人:

>>> uni_tag = UnigramTagger(train_set)
用语料库训练一个不带停止词的标记者:

>>> uni_tag_nostop = UnigramTagger(train_set_nostop)
将测试集拆分为单词和标记:

>>> test_words, test_tags = zip(*[zip(*sent) for sent in test_set])
标记测试句子:

>>> uni_tag.tag_sents(test_words)
>>> uni_tag_nostop.tag_sents(test_words)
评估准确度(现在让我们做真正的正面评估):

请注意,当您在培训标记员之前删除stopwords时,这里有很多不公平的地方,而不是穷尽:

  • 你的训练集自然会变小,因为去掉停止词后句子中的单词数量会变小

  • 标记器不会学习stopwords的标记,因此会为所有stopwords返回None,这会降低标记器的准确性,因为测试集确实包含stopwords

  • 当训练一个高阶的ngram时,如果没有停止词,它可能毫无意义。语法性或敏感性并不能解释准确性(特别是在今天的NLP中)。例如,“猫在桌子上”->“猫在桌子上”,没有停止词

  • >>> train_set_nostop = [[(word,tag) for word, tag in sent if word.lower() not in stoplist] for sent in train_set]
    

但正如@alexia所指出的,对于基于单词包的向量空间模型(又名分布式模型,又名“你可以通过它的邻居知道一个单词”模型,又名非神经预测嵌入模型),删除停止词可能会在准确性方面给你带来一些好处。但是,(统计上)神奇的是,stopwords将自动具有较低的TF-IDF分数,因为它们在大多数文档中出现得太频繁了,这不会使它们具有较少的歧视性属性,从而使每个文档变得不同(因此它们并不那么重要,是IDF部分发挥了神奇的作用).

我建议您在删除停止词之前使用词性标记,因为词性标记是作为序列分类执行的,因此通过删除停止词来更改序列很可能会影响剩余单词的词性标记。

词性标记是作为序列分类执行的,因此,通过删除stopwords来更改序列很可能会更改其余单词的POS标记。POS标记员通常接受包括停止词在内的完整文本的培训。