【问题标题】:Spacy DependencyMatcher returning empty valueSpacy DependencyMatcher 返回空值
【发布时间】:2021-03-23 16:35:01
【问题描述】:

教程中的代码:https://spacy.io/usage/rule-based-matching#dependencymatcher

import spacy
import en_core_web_sm
from spacy.matcher import DependencyMatcher
nlp = en_core_web_sm.load()


matcher = DependencyMatcher(nlp.vocab)

pattern = [
    {
        "RIGHT_ID": "anchor_founded",
        "RIGHT_ATTRS": {"ORTH": "founded"}
    },
    {
        "LEFT_ID": "anchor_founded",
        "REL_OP": ">",
        "RIGHT_ID": "founded_subject",
        "RIGHT_ATTRS": {"DEP": "nsubj"},
    },
    {
        "LEFT_ID": "anchor_founded",
        "REL_OP": ">",
        "RIGHT_ID": "founded_object",
        "RIGHT_ATTRS": {"DEP": "dobj"},
    },
    {
        "LEFT_ID": "founded_object",
        "REL_OP": ">",
        "RIGHT_ID": "founded_object_modifier",
        "RIGHT_ATTRS": {"DEP": {"IN": ["amod", "compound"]}},
    }
]

matcher.add("FOUNDED", [pattern])
doc = nlp("Lee, an experienced CEO, has FOUNDED two AI startups.")
matches = matcher(doc)

print(matches) 

结果我应该得到 [(4851363122962674176, [6, 0, 10, 9])] 我得到的是这个[]

我的环境

  • spaCy 版本:3.0.5
  • 平台:Windows-10
  • Python 版本:3.6.13
  • en_core_web_sm = 3.0.0

【问题讨论】:

    标签: python machine-learning nlp spacy


    【解决方案1】:

    您正在使用 ORTH 来查找“founded”。这是区分大小写的。您应该将 ORTH 替换为 LOWER,或者在输入句子中简单地小写 FOUNDED

    【讨论】:

    • 谢谢克里斯!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-07
    • 1970-01-01
    • 2022-01-03
    • 2021-12-21
    • 2015-11-07
    • 2020-05-20
    • 2020-11-08
    相关资源
    最近更新 更多