【问题标题】:Make spacy nlp.pipe process tuples of text and additional information to add as document features?让 spacy nlp.pipe 处理文本元组和附加信息以添加为文档功能?
【发布时间】:2019-07-18 04:44:50
【问题描述】:

显然for doc in nlp.pipe(sequence) 比运行for el in sequence: doc = nlp(el) .. 快得多

我遇到的问题是我的序列实际上是一个元组序列,其中包含用于 spacy 转换为文档的文本,还有我想作为文档属性进入 spacy 文档的附加信息(我将注册 Doc)。

我不确定如何修改 spacy 管道,以便第一阶段真正从元组中选择一个项目来运行标记器并获取文档,然后让其他一些函数使用元组中的剩余项目来将功能添加到现有文档。

【问题讨论】:

    标签: spacy


    【解决方案1】:

    听起来您可能正在寻找nlp.pipeas_tuples 参数?如果您设置as_tuples=True,您可以传入(text, context) 元组流,spaCy 将产生(doc, context) 元组(而不仅仅是Doc 对象)。然后,您可以使用上下文并将其添加到自定义属性等。

    这是一个例子:

    data = [
      ("Some text to process", {"meta": "foo"}),
      ("And more text...", {"meta": "bar"})
    ]
    
    for doc, context in nlp.pipe(data, as_tuples=True):
        # Let's assume you have a "meta" extension registered on the Doc
        doc._.meta = context["meta"]
    

    【讨论】:

    • 谢谢 - 但是没有办法访问在执行 nlp.pipe 时运行的管道中的上下文?我最初的想法是通过将我自己的处理器添加到管道中来完成所有处理,但这样我将不得不通过多个管道。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-08
    • 2021-10-19
    • 2017-08-09
    • 2021-09-10
    • 2016-06-20
    相关资源
    最近更新 更多