Jupyter Notebook中的模块'spacy.util'没有属性'filter_spans' [英] Module 'spacy.util' has no attribute 'filter_spans' in Jupyter Notebook
本文介绍了Jupyter Notebook中的模块'spacy.util'没有属性'filter_spans'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有spacy版本2.2.4(也已在2.1.4中尝试过).
I have spacy version 2.2.4 (also tried with 2.1.4).
import spacy
...
result = spacy.util.filter_spans(spans)
错误:模块'spacy.util'没有属性'filter_spans'
我正在从虚拟环境中运行jupyter笔记本,并且还在其中安装了spacy.该文档说应该包括过滤器跨度: https://spacy.io/api/top-level#util.filter_spans
I am running jupyter notebook from a virual environment and installed spacy inside it too. The documentation says filter spans shoud be included: https://spacy.io/api/top-level#util.filter_spans
上下文:尝试从
感谢任何帮助.
推荐答案
自己定义函数并使用它:
Define the function by yourself and use it:
def filter_spans(spans):
# Filter a sequence of spans so they don't contain overlaps
# For spaCy 2.1.4+: this function is available as spacy.util.filter_spans()
get_sort_key = lambda span: (span.end - span.start, -span.start)
sorted_spans = sorted(spans, key=get_sort_key, reverse=True)
result = []
seen_tokens = set()
for span in sorted_spans:
# Check for end - 1 here because boundaries are inclusive
if span.start not in seen_tokens and span.end - 1 not in seen_tokens:
result.append(span)
seen_tokens.update(range(span.start, span.end))
result = sorted(result, key=lambda span: span.start)
return result
这篇关于Jupyter Notebook中的模块'spacy.util'没有属性'filter_spans'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文