【发布时间】:2017-07-28 14:02:38
【问题描述】:
我想使用 spaCy 解析文档并应用令牌过滤器,以便最终的 spaCy 文档不包含过滤后的令牌。我知道我可以过滤令牌序列,但我对拥有实际的Doc 结构很感兴趣。
text = u"This document is only an example. " \
"I would like to create a custom pipeline that will remove specific tokesn from the final document."
doc = nlp(text)
def keep_token(tok):
# This is only an example rule
return tok.pos_ not not in {'PUNCT', 'NUM', 'SYM'}
final_tokens = list(filter(keep_token, doc))
# How to get a spacy.Doc from final_tokens?
我试图从令牌列表中重建一个新的 spaCy Doc,但 API 不清楚如何做到这一点。
【问题讨论】: