【问题标题】:Spacy Span as_doc() Loses Components from Original Doc (Benepar)Spacy Span as_doc() 丢失原始文档中的组件(Benepar)
【发布时间】:2022-09-23 20:53:45
【问题描述】:

我有一个字符串,里面有几句话。我想获得每个句子的选区解析。我这样做是通过对完整字符串进行 nlp 解析以获取 spacy Doc,然后循环通过 doc.sents 并使用 span.as_doc() 将 Span 转换为 Docs。但是,当我将 Spans 转换回 Docs 时,似乎并没有保留所有原始数据。具体来说,不再存在 benepar 选区分析。

import spacy
import benepar

nlp = spacy.load(\"en_core_sci_md\", disable=[\"ner\", \"lemmatizer\", \"textcat\"])
nlp.add_pipe(\'benepar\', config={\'model\': BENEPAR_DIR})
nlp_test1 = nlp(\'The quick brown fox jumps over the lazy dog\')
print(list(nlp_test1.sents)[0]._.parse_string) # Uses benepar (works)

nlp_test2 = list(nlp_test1.sents)[0].as_doc()
print(list(nlp_test2.sents)[0]._.parse_string) # No constituency parse found (no benepar)

nlp_test3 = list(nlp_test.sents)[0].as_doc(array_head=nlp_test._get_array_attrs())
print(list(nlp_test3.sents)[0]._.parse_string) # Doesn\'t work either

如何在保留 benepar 选区解析数据的同时将 Span 转换为 Doc?或者这不可能并且 benepar 只解析doc.sents 中的第一个?

    标签: python nlp spacy benepar


    【解决方案1】:

    似乎 as_doc() 没有运行由 nlp.add_pipe() 添加的额外管道。

    代替

    nlp_test2 = list(nlp_test1.sents)[0].as_doc()
    

    nlp_test2 = nlp(list(nlp_test1.sents)[0].text)
    

    所以 nlp_test2 将使用 benepar 管道创建。

    【讨论】:

      猜你喜欢
      • 2019-01-16
      • 2021-12-12
      • 2020-03-11
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      • 2016-02-26
      相关资源
      最近更新 更多