在SpaCy中,您可以像这样设置文档的扩展名:
Doc.set_extension('chapter_id', default='')
doc = nlp('This is my text')
doc._.chapter_id = 'This is my ID'但是,我有数以千计的文本文件需要由NLP处理。SpaCy建议使用pipe实现这一点:
docs = nlp.pipe(array_of_texts)如何在pipe期间应用我的扩展值
发布于 2018-08-25 21:48:48
您可能希望在nlp.pipe上启用as_tuples关键字参数,该参数允许您传入(text, context)元组列表,并将生成(doc, context)元组。所以你可以这样做:
data = [('Some text', 1), ('Some other text', 2)]
def process_text(data):
for doc, chapter_id in nlp.pipe(data, as_tuples=True):
doc._.chapter_id = chapter_id
yield dochttps://stackoverflow.com/questions/52016425
复制相似问题