【问题标题】:NLP: Compare these two sentences. Is this a misclassification?NLP:比较这两个句子。这是错误分类吗?
【发布时间】:2020-08-04 03:40:28
【问题描述】:

我正在使用 spacy 的依赖解析。我对这两个非常相似的句子感到困惑。

第 1 句:

text='He noted his father was a nice guy.'

请注意,这句话中的“father”显然是“father was a nice guy”的主语:

[(0, 'He', '-PRON-', 'PRON', 'PRP', 'nsubj'), (1, 'noted', 'note', 'VERB', 'VBD', 'ROOT'), (2, 'his', '-PRON-', 'DET', 'PRP$', 'poss'), (3, 'father', 'father', 'NOUN', 'NN', 'nsubj'), (4, 'was', 'be', 'VERB', 'VBD', 'ccomp'), (5, 'a', 'a', 'DET', 'DT', 'det'), (6, 'nice', 'nice', 'ADJ', 'JJ', 'amod'), (7, 'guy', 'guy', 'NOUN', 'NN', 'attr'), (8, '.', '.', 'PUNCT', '.', 'punct')]

        noted              
  ________|_____            
 |   |         was         
 |   |     _____|___        
 |   |  father     guy     
 |   |    |      ___|___    
 He  .   his    a      nice

for child in the_verb.children:
    print(child,child.dep_)
    
>> father nsubj
>> guy attr

for ancestor in the_verb.ancestors:
    print(ancestor,ancestor.dep_)
    
>> noted ROOT

第二句:

text='He noted his father, as \"a man with different attributes\", was a nice guy.'

这是上一句的一个小变化。 “父亲”不再是主语了。

[(0, 'He', '-PRON-', 'PRON', 'PRP', 'nsubj'), (1, 'noted', 'note', 'VERB', 'VBD', 'ROOT'), (2, 'his', '-PRON-', 'DET', 'PRP$', 'poss'), (3, 'father', 'father', 'NOUN', 'NN', 'dobj'), (4, ',', ',', 'PUNCT', ',', 'punct'), (5, 'as', 'as', 'ADP', 'IN', 'prep'), (6, '"', '"', 'PUNCT', '``', 'punct'), (7, 'a', 'a', 'DET', 'DT', 'det'), (8, 'man', 'man', 'NOUN', 'NN', 'pobj'), (9, 'with', 'with', 'ADP', 'IN', 'prep'), (10, 'different', 'different', 'ADJ', 'JJ', 'amod'), (11, 'attributes', 'attribute', 'NOUN', 'NNS', 'pobj'), (12, '"', '"', 'PUNCT', "''", 'punct'), (13, ',', ',', 'PUNCT', ',', 'punct'), (14, 'was', 'be', 'VERB', 'VBD', 'conj'), (15, 'a', 'a', 'DET', 'DT', 'det'), (16, 'nice', 'nice', 'ADJ', 'JJ', 'amod'), (17, 'guy', 'guy', 'NOUN', 'NN', 'attr'), (18, '.', '.', 'PUNCT', '.', 'punct')]

                noted                                 
  ________________|____________________________        
 |   |   |   |    |         as                 |      
 |   |   |   |    |         |                  |       
 |   |   |   |    |        man                 |      
 |   |   |   |    |      ___|______            |       
 |   |   |   |    |     |   |     with        was     
 |   |   |   |    |     |   |      |           |       
 |   |   |   |  father  |   a  attributes     guy     
 |   |   |   |    |     |   |      |        ___|___    
 He  ,   ,   .   his    "   "  different   a      nice


the_verb=spacy_doc[14]

for child in the_verb.children:
    print(child,child.dep_)
    
>> guy attr

for ancestor in the_verb.ancestors:
    print(ancestor,ancestor.dep_)
    
>> noted ROOT

我试图了解 spacy 如何对句子进行分类。第二种情况是错误分类错误吗?我的意思是“父亲”仍然应该是主题?

【问题讨论】:

    标签: python-3.x nlp spacy dependency-parsing


    【解决方案1】:

    我想知道您是否正在考虑使用解析树而不是依赖树...

    老实说,我一直对依赖树感到困惑。它们擅长识别结构之间的相对连接,但我认为它们不擅长确定绝对语义结构。短语结构规则非常擅长确定具体名词、动词及其成分的绝对词性;虽然仍然不完美。虽然依赖解析器可用于检测名词块、介词短语和推断动词短语,但我认为这不是它的主要功能。这解析树的主要功能。

    回到你的问题:

    您将“父亲”作为主题的方式听起来像是您试图理解深层句法结构(绝对),但使用的是相对模型(依赖解析器)。

    从本质上讲,我相信“作为一个具有不同属性的人”这句话是在向依赖关系树添加层。这些层将实际主语“他的父亲”与动词短语“是个好人”分开。我想它为逗号添加了一层,为引号添加了另一层,为 as 子句添加了另一层。直到最终,依赖解析器应该确定的相对关系“太过分了”。

    句法分析只能与生成它们的模型一样好。事实上,您会看到 SpaCy 有 2 个 POS 指示符,它们都尝试执行句法分析。一个由依赖解析器生成(在 token.dep_ 下可用),另一个由统计模型生成(在 token.pos_ 下可用)。您还会看到,由于预测它们的模型的不精确性,这些 POS 指标并不总是匹配。

    出于兴趣,我相信NLTK 有一个更传统的基于短语结构规则的解析树可用;尽管这些也有局限性。如果您想要深入,对现实生活中的句子进行核心句法分析,您可能想尝试Head-driven phrase structure grammar (HPSG) 之类的方法,但您会发现事情开始变得只是一点 有点技术性。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多