【问题标题】:Dependency parsing of noun chunks in spacyspacy中名词块的依赖解析
【发布时间】:2023-03-15 13:00:01
【问题描述】:

有一个coupleof 存在关于在spacy 中获取名词块的问题,即relatively straightforward

我感兴趣的是将依赖解析复制到句子中预先指定的 ngram 之上。如下例所示,来自this spacy talk,其中Alex SmithEast London 在依赖项解析中被视为单个标记。

【问题讨论】:

    标签: nlp spacy


    【解决方案1】:

    这可能是通过您指定的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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 2021-09-06
      • 2019-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多