【问题标题】:spaCy issue with 'Vocab' or 'StringStore''Vocab' 或 'StringStore' 的 spaCy 问题
【发布时间】:2020-02-10 14:08:18
【问题描述】:

我正在使用 spaCy 为管道训练 Rasa NLU,但是当我尝试训练它时,我从 spaCy 收到此错误:

KeyError: "[E018] Can't retrieve string for hash '18446744072967274715'. This usually refers to an issue with the `Vocab` or `StringStore`."

我有 python 3.7.3,spaCy 版本是 2.2.3,rasa 版本是 1.6.1

有人知道如何解决这个问题吗?

【问题讨论】:

标签: python-3.x spacy rasa-nlu rasa


【解决方案1】:

这听起来像是一个命名错误,我猜你为另一个文本应用了匹配器,并且 matcher_id 变得不同,所以这很混乱。 要解决它,请确保您对相同的文本使用相同的匹配器,如下所示:

执行标准导入、重置 nlp 、 PhraseMatcher 库

import spacy
nlp = spacy.load('en_core_web_sm')
from spacy.matcher import PhraseMatcher
matcher = PhraseMatcher(nlp.vocab)
dd = 'refers to the economic policies  associated with supply-side economics, voodoo economics'
doc3 = nlp(dd) # convert string to spacy.tokens.doc.Doc

首先,创建一个匹配短语列表:

phrase_list = ['voodoo economics', 'supply-side economics', 'free-market economics']

接下来,将每个短语转换为 Doc 对象:

phrase_patterns = [nlp(text) for text in phrase_list]

将每个 Doc 对象传递给匹配器(注意星号的使用!):

matcher.add('VoodooEconomics', None, *phrase_patterns)

建立匹配列表:

matches = matcher(doc3)
matches #(match_id, start, end)

查看比赛:

for match_id, start, end in matches: # the matcher have to be the same one that we build on this text
     string_id = nlp.vocab.strings[match_id] 
     span = doc3[start:end]                   
     print(match_id, string_id, start, end, span.text)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    • 2018-11-23
    • 2017-09-24
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多