【问题标题】:Basic and enhanced dependencies give different results in Stanford coreNLP基础依赖和增强依赖在斯坦福 coreNLP 中给出不同的结果
【发布时间】:2017-08-29 06:41:34
【问题描述】:

我正在为我的一个项目使用 coreNLP 的依赖项解析。基本依赖和增强依赖是特定依赖的不同结果。 我使用以下代码来获得增强的依赖关系。

val lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz")
lp.setOptionFlags("-maxLength", "80")
val rawWords = edu.stanford.nlp.ling.Sentence.toCoreLabelList(tokens_arr:_*)
val parse = lp.apply(rawWords)
val tlp = new PennTreebankLanguagePack()
val gsf:GrammaticalStructureFactory = tlp.grammaticalStructureFactory()
val gs:GrammaticalStructure = gsf.newGrammaticalStructure(parse)
val tdl = gs.typedDependenciesCCprocessed()

对于以下示例,

Account name of ramkumar.

我使用简单的 API 来获取基本依赖项。我之间的依赖关系 (帐户,名称)是(复合)。但是当我使用上面的代码来获得增强的依赖关系时,我得到(帐户,名称)之间的关系为(dobj)。

对此有什么解决办法?这是一个错误还是我做错了什么?

【问题讨论】:

    标签: parsing nlp stanford-nlp dependency-parsing


    【解决方案1】:

    当我运行这个命令时:

    java -Xmx8g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,parse -file example.txt -outputFormat json
    

    在文件example.txt 中使用您的示例文本,我将compound 视为这两种依赖类型的这两个词之间的关系。

    我也用simple API 进行了尝试,得到了相同的结果。

    您可以看到simple 使用此代码产生了什么:

    package edu.stanford.nlp.examples;
    
    import edu.stanford.nlp.semgraph.SemanticGraphFactory;
    import edu.stanford.nlp.simple.*;
    
    import java.util.*;
    
    public class SimpleDepParserExample {
    
      public static void main(String[] args) {
        Sentence sent = new Sentence("...example text...");
        Properties props = new Properties();
        // use sent.dependencyGraph() or sent.dependencyGraph(props, SemanticGraphFactory.Mode.ENHANCED) to see enhanced dependencies
        System.out.println(sent.dependencyGraph(props, SemanticGraphFactory.Mode.BASIC));
      }
    
    }
    

    我对斯坦福 CoreNLP 的任何 Scala 接口一无所知。我还应该注意我的结果是使用来自 GitHub 的最新代码,尽管我认为 Stanford CoreNLP 3.8.0 也会产生类似的结果。如果您使用的是旧版本的 Stanford CoreNLP,这可能是导致错误的潜在原因。

    但是使用 Java 以各种方式运行此示例,我没有看到您遇到的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多