【发布时间】:2019-12-17 01:14:10
【问题描述】:
我正在使用 spacy 的 PhraseMatcher 来识别用户 cmets 中的药物名称。当应用程序服务器启动时,我正在从一个大文件中预加载名称,但不想在每个文档进程中都这样做,因为这需要一段时间。 在处理新文档时,我想将识别的新药物添加到短语匹配器中,以便它识别新名称。但是,spacy 不会接受具有相同 match_id 的新药。任何帮助将不胜感激。
# Global preload when application server starts
import spacy
from spacy.matcher import PhraseMatcher
nlp = spacy.blank("en")
drug_list = [] # file import with 15k drug names
phrasematcher = PhraseMatcher(nlp.vocab, attr='LOWER')
phrasematcher.add('drug', [nlp(itm) for itm in drug_list])
# The above process takes about couple of seconds to load so this process cannot run everytime
# Post process new documents
phrasematcher.add('drug', [nlp(itm) for itm in ['new drug 1', 'new drug 2']])
我收到以下错误。
span = Span(doc_pm, start, end, label=match_id)
File "span.pyx", line 118, in spacy.tokens.span.Span.__cinit__
ValueError: [E084] Error assigning label ID 16065740214838660377 to span: not in StringStore.
当我使用 match_id 查找哈希然后使用它时,我得到一个不同的错误。
phrasematcher.add(phrasematcher.vocab.strings['drug'], [nlp(itm) for itm in ['new drug 1', 'new drug 2']])
错误:
File "phrasematcher.pyx", line 222, in spacy.matcher.phrasematcher.PhraseMatcher.add
TypeError: an integer is required
Spacy 2.2 Ubuntu 16 Python 3.6
【问题讨论】:
标签: python-3.x spacy