2011-07-04 13 views
13

最後のバージョンのスタンフォードNLPツールでcorefリゾルバに加えられた変更を理解するのに問題があります。私はこれらの数字の意味を理解してわからないスタンフォードコアNLP - コアリファレンスの解決

The atom is a basic unit of matter, it consists of a dense central nucleus surrounded by a cloud of negatively charged electrons. 

{1=[1 1, 1 2], 5=[1 3], 7=[1 4], 9=[1 5]} 

: 例として、以下の文とそれに対応するCorefChainAnnotationです。ソースを見ても本当に助けにはならない。

は、SieveCoreferenceSystem#coref(Document)のソースコードを参照して最初の数は(同じエンティティを表すトークンを表す)のクラスタIDであるあなた

答えて

7

ありがとう。ペア番号)(CorefChain#のtoStringのoutoutです:

位置は(彼らは CorefChain.getCorefMentions()を使用取得するために)言及するエンティティのpostionペアのセットです
public String toString(){ 
    return position.toString(); 
} 

。ここでは位置からトークンを取得する方法を示しています(groovyで)完全なコードの例です。

class Example { 
    public static void main(String[] args) { 
     Properties props = new Properties(); 
     props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref"); 
     props.put("dcoref.score", true); 
     pipeline = new StanfordCoreNLP(props); 
     Annotation document = new Annotation("The atom is a basic unit of matter, it consists of a dense central nucleus surrounded by a cloud of negatively charged electrons."); 

     pipeline.annotate(document); 
     Map<Integer, CorefChain> graph = document.get(CorefChainAnnotation.class); 

     println aText 

     for(Map.Entry<Integer, CorefChain> entry : graph) { 
      CorefChain c = entry.getValue();     
      println "ClusterId: " + entry.getKey(); 
      CorefMention cm = c.getRepresentativeMention(); 
      println "Representative Mention: " + aText.subSequence(cm.startIndex, cm.endIndex); 

      List<CorefMention> cms = c.getCorefMentions(); 
      println "Mentions: "; 
      cms.each { it -> 
       print aText.subSequence(it.startIndex, it.endIndex) + "|"; 
      }   
     } 
    } 
} 

出力は(「s」はどこから来るのか私は理解していない):

The atom is a basic unit of matter, it consists of a dense central nucleus surrounded by a cloud of negatively charged electrons. 
ClusterId: 1 
Representative Mention: he 
Mentions: he|atom |s| 
ClusterId: 6 
Representative Mention: basic unit 
Mentions: basic unit | 
ClusterId: 8 
Representative Mention: unit 
Mentions: unit | 
ClusterId: 10 
Representative Mention: it 
Mentions: it | 
+0

ps。私はデフォルトの設定(モデル)があなたのドメインで動作するとは思わない。スタンフォードコアnlpは、ニュース、記事などからセマンティックを抽出するのに適しているようです。例えば、スタンフォードNER(コアNLPの一部)は、CoNLL 2002および2003コーパスで訓練され、精巣を鍛えられました。 – Skarab

+0

このアルゴリズムは部分的に便利で、適切なアルゴリズムに導かれましたが、ここでの出力は文に適していません。文中に "he"がなく、 "s"と "it"コアリファレンス分解のポイント。 – user1084563

+0

'startIndex'と' endIndex'を文字インデックス(0ベース)のように見なしていますが、それらはトークンインデックス(1ベース)です。また、あなたは 'aText'を定義しませんでした。アノテーションのテキストを "he"(文字1と2)ではなく "アトム"(単語1と2)などにする必要があると仮定します。 –

16

私はcoferenceの依存関係のグラフを使って作業していましたが、私はこの質問に対するもう一つの答えを使って始めました。しばらくすると、私は上記のアルゴリズムが正確ではないことに気付きました。それが作り出した出力は、私が持っている変更されたバージョンにも近くない。

この記事を使用している他の人は、すべての代表批判にも言及し、多くの言及が自分自身を参照するだけなので、自己引用をフィルタリングするアルゴリズムを紹介します。

Map<Integer, CorefChain> coref = document.get(CorefChainAnnotation.class); 

for(Map.Entry<Integer, CorefChain> entry : coref.entrySet()) { 
    CorefChain c = entry.getValue(); 

    //this is because it prints out a lot of self references which aren't that useful 
    if(c.getCorefMentions().size() <= 1) 
     continue; 

    CorefMention cm = c.getRepresentativeMention(); 
    String clust = ""; 
    List<CoreLabel> tks = document.get(SentencesAnnotation.class).get(cm.sentNum-1).get(TokensAnnotation.class); 
    for(int i = cm.startIndex-1; i < cm.endIndex-1; i++) 
     clust += tks.get(i).get(TextAnnotation.class) + " "; 
    clust = clust.trim(); 
    System.out.println("representative mention: \"" + clust + "\" is mentioned by:"); 

    for(CorefMention m : c.getCorefMentions()){ 
     String clust2 = ""; 
     tks = document.get(SentencesAnnotation.class).get(m.sentNum-1).get(TokensAnnotation.class); 
     for(int i = m.startIndex-1; i < m.endIndex-1; i++) 
      clust2 += tks.get(i).get(TextAnnotation.class) + " "; 
     clust2 = clust2.trim(); 
     //don't need the self mention 
     if(clust.equals(clust2)) 
      continue; 

     System.out.println("\t" + clust2); 
    } 
} 

そして、あなたの例文のための最終的な出力は以下の通りです:

representative mention: "a basic unit of matter" is mentioned by: 
The atom 
it 

通常「原子」代表言及されて終わるが、場合には、驚くべきことではないん。もう少し正確な出力が得られるもう1つの例は、次のような文章です。

革命的な戦争は1700年代に起こり、米国で最初の戦争でした。

は、次の出力を生成します。

representative mention: "The Revolutionary War" is mentioned by: 
it 
the first war in the United States 
0

これらは、注釈者からの最近の結果です。

  1. [1、1] 1原子
  2. 物の[1,2] 1基本単位は、
  3. [1、3] 1この
  4. [1,6] 6つの負に帯電した電子
  5. [1、5] 5

マーキング通りである負に帯電した電子の雲は、以下:

[Sentence number,'id'] Cluster_no Text_Associated 

同じクラスタに属するテキストは、同じコンテキストを参照します。