Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 空间短语匹配器值错误模式长度(11)>;=短语匹配器最大长度(10)_Python_Spacy - Fatal编程技术网

Python 空间短语匹配器值错误模式长度(11)>;=短语匹配器最大长度(10)

Python 空间短语匹配器值错误模式长度(11)>;=短语匹配器最大长度(10),python,spacy,Python,Spacy,使用术语列表初始化新的短语匹配器时,我遇到以下错误: ValueError:图案长度(11)>=短语匹配器最大长度(10)。 可以在初始化时设置长度,最多为10 目前,单个规则的长度不能超过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' 您可以尝试将限制设置得更高,

使用术语列表初始化新的短语匹配器时,我遇到以下错误:

ValueError:图案长度(11)>=短语匹配器最大长度(10)。 可以在初始化时设置长度,最多为10


目前,单个规则的长度不能超过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是一个硬限制


请参阅和上的相关文档,您可以尝试将类定义为实体匹配器,并在各种模式/字段上循环

  class EntityMatcher(object):
       name = 'entity_matcher' 

  def __init__(self, nlp, terms, label): 
      patterns = [nlp(text) for text in terms] 
      self.matcher = PhraseMatcher(nlp.vocab) 
      self.matcher.add(label, None, *patterns) 

  def __call__(self, doc): 
      matches = self.matcher(doc) 
      for match_id, start, end in matches: 
      span = Span(doc, start, end, label = match_id) 
      doc.ents = list(doc.ents) 

  return doc  

在spacy 2.1.4版本中,短语匹配器的上述值错误已得到解决。如果您遇到此类错误,请更新spacy版本。
请参阅:

以便您可以向构造函数传递不同的参数,但这并不重要,因为内部硬编码限制为10?:-下面是塔希尔·艾哈迈德的真实答案。这应该是选择的答案。绝对不要这样做。
  class EntityMatcher(object):
       name = 'entity_matcher' 

  def __init__(self, nlp, terms, label): 
      patterns = [nlp(text) for text in terms] 
      self.matcher = PhraseMatcher(nlp.vocab) 
      self.matcher.add(label, None, *patterns) 

  def __call__(self, doc): 
      matches = self.matcher(doc) 
      for match_id, start, end in matches: 
      span = Span(doc, start, end, label = match_id) 
      doc.ents = list(doc.ents) 

  return doc