Подтвердить что ты не робот

Стэнфордский ядерный НЛП - понимание разрешения когерентности

У меня возникли проблемы с пониманием изменений, внесенных в преобразователь coref в последней версии инструментов Stanford NLP. В качестве примера ниже приведено предложение и соответствующая CorefChainAnnotation:

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]}

Я не уверен, что понимаю смысл этих чисел. И смотреть на источник тоже не помогает.

Спасибо

4b9b3361

Ответ 1

Первое число - это идентификатор кластера (представляющий токены, которые обозначают один и тот же объект), см. исходный код SieveCoreferenceSystem#coref(Document). Номера пары находятся вне CorefChain # toString():

public String toString(){
    return position.toString();
}

где position представляет собой набор пар позиционирования упоминания объекта (чтобы заставить их использовать CorefChain.getCorefMentions()). Ниже приведен пример полного кода (в 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) + "|"; 
          }         
        }
    }
}

Выход (я не понимаю, откуда '):

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 |

Ответ 2

Я работал с графиком зависимости ядра и начал использовать другой ответ на этот вопрос. Через некоторое время, хотя я понял, что этот алгоритм выше не совсем корректен. Вывод, который он произвел, даже не близок к модифицированной версии.

Для всех, кто использует эту статью, вот алгоритм, в котором я закончил, который также отфильтровывает собственные ссылки, потому что каждое представительство также упоминает себя, и многие упоминания ссылаются только на себя.

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

Обычно "атом" оказывается репрезентативным, но в этом случае это не удивительно. Другой пример с несколько более точным выходом - это следующее предложение:

Революционная война произошла в 1700-х годах, и это была первая война в Соединенных Штатах.

выводит следующий результат:

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

Ответ 3

Это последние результаты аннотатора.

  • [1, 1] 1 Атом
  • [1, 2] 1 базовая единица материи
  • [1, 3] 1 it
  • [1, 6] 6 отрицательно заряженных электронов
  • [1, 5] 5 облако отрицательно заряженных электронов

Маркировка выглядит следующим образом:

[Sentence number,'id']  Cluster_no  Text_Associated

Текст, принадлежащий тому же кластеру, относится к одному и тому же контексту.