【发布时间】:2023-03-15 13:00:01
【问题描述】:
有一个coupleof 存在关于在spacy 中获取名词块的问题,即relatively straightforward。
我感兴趣的是将依赖解析复制到句子中预先指定的 ngram 之上。如下例所示,来自this spacy talk,其中Alex Smith 和East London 在依赖项解析中被视为单个标记。
【问题讨论】:
有一个coupleof 存在关于在spacy 中获取名词块的问题,即relatively straightforward。
我感兴趣的是将依赖解析复制到句子中预先指定的 ngram 之上。如下例所示,来自this spacy talk,其中Alex Smith 和East London 在依赖项解析中被视为单个标记。
【问题讨论】:
这可能是通过您指定的options 参数完成的
"collapse_phrases" : True
详情https://spacy.io/api/top-level#options-dep
创建可在浏览器中打开的 svg 文件的示例
import spacy
from spacy import displacy
from pathlib import Path
nlp = spacy.load('en_core_web_sm', parse=True, tag=True, entity=True)
doc = nlp("Alex Smith was fatally stabbed in East London")
print(doc.ents)
options = {"color": "white", "collapse_phrases" : True, "bg": "#000000"}
svg = displacy.render(doc, style="dep", options=options)
output_path = Path("dependency_plot.svg")
output_path.open("w", encoding="utf-8").write(svg)
【讨论】: