python – Spacy PhraseMatcher值错误模式长度(11)> = phrase_matcher.max_length(10)

初始化带有术语列表的新PhraseMatcher时出现以下错误:

ValueError: Pattern length (11) >= phrase_matcher.max_length (10).
Length can be set on initialization, up to 10.

patterns = [nlp(org) for org in fields]
        self.matcher = PhraseMatcher(nlp.vocab)
        self.matcher.add('FIELD', None, *patterns)

解决方法:

目前,单个规则的长度不能超过10个令牌:

# Allowed
'one two three four five six seven eight nine ten'
# Not Allowed
'one two three four five six seven eight nine ten eleven'

您可以尝试将限制设置得更高,即:self.matcher = PhraseMatcher(nlp.vocab,max_length = 20),但当前版本的SpaCy 10中的iirc是硬限制.

请参阅https://spacy.io/api/phrasematcher#init的相关文档和https://github.com/explosion/spacy/blob/master/spacy/matcher.pyx#L452的源文档

上一篇:Haproxy搭建web群集


下一篇:python – Spacy:保存已解析的模型