【问题标题】:spacy noun-chunking creates unexpected lemma, pos, tag, and depspacy noun-chunking 创建了意想不到的引理、pos、tag 和 dep
【发布时间】:2019-08-26 13:24:44
【问题描述】:

我正在使用 spacy 来解析文档,不幸的是,我无法按照我期望的方式处理名词块。以下是我的代码:

# Import spacy
import spacy
nlp = spacy.load("en_core_web_lg")

# Add noun chunking to the pipeline
merge_noun_chunks = nlp.create_pipe("merge_noun_chunks")
nlp.add_pipe(merge_noun_chunks)

# Process the document
docs = nlp.pipe(["The big dogs chased the fast cat"])

# Print out the tokens
for doc in docs:
    for token in doc:
        print("text: {}, lemma: {}, pos: {}, tag: {}, dep: {}".format(tname, token.text, token.lemma_, token.pos_, token.tag_, token.dep_))

我得到的输出如下:

text: The big dogs, lemma: the, pos: NOUN, tag: NNS, dep: nsubj
text: chased, lemma: chase, pos: VERB, tag: VBD, dep: ROOT
text: the fast cat, lemma: the, pos: NOUN, tag: NN, dep: dobj

问题出在输出的第一行,其中“the big dogs”以一种意想不到的方式被解析:它创建了一个“the”的“引理”,并指出它是“NOUN”的一个“pos”, “NNS”的“标签”和“nsubj”的“dep”。

我希望得到的输出如下:

text: The big dogs, lemma: the big dog, pos: NOUN, tag: NNS, dep: nsubj
text: chased, lemma: chase, pos: VERB, tag: VBD, dep: ROOT
text: the fast cat, lemma: the fast cat, pos: NOUN, tag: NN, dep: dobj

我预计“引理”将是短语“the big dog”,复数形式变为单数,短语将是“名词”的“pos”,“NNS”的“tag”和“dep” ”的“nsubj”。

这是正确的行为,还是我错误地使用了 spacy?如果我错误地使用 spacy,请告诉我执行此任务的正确方式。

【问题讨论】:

    标签: nlp spacy


    【解决方案1】:

    这里有几点需要考虑

    1. 词形还原是基于令牌的
    2. POS 标记和依赖解析具有预测性

    如果您为每个令牌使用lemma_ 属性,您可能会得到the big dog。它不会更新您使用该属性的令牌位置。

    此外,由于依赖解析和词性标注是在预测模型中训练的,因此不能保证从人类语言的角度来看总是“正确”的。

    除了引理问题,您似乎使用的是 spacy 正确

    【讨论】:

      猜你喜欢
      • 2020-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-04
      相关资源
      最近更新 更多