stanfordnlp/CoreNLP · error · RuntimeException

Cannot find gold mention with ID=

Error message

Cannot find gold mention with ID={originalRef}

What it means

extractGoldLinks resolves each mention's originalRef (gold antecedent mention ID) against the positions map and throws RuntimeException("Cannot find gold mention with ID=...") when the referenced mention ID does not exist. It indicates a broken or out-of-order gold annotation where a coref link points to an unknown mention.

Solutions

  1. Validate the gold key file — every COREF REF must point to an earlier, existing mention ID
  2. Re-obtain a clean version of the MUC/CoNLL gold file
  3. Check for truncation or malformed SGML tags in the source document
  4. If preprocessing gold data, ensure mention IDs are preserved and registered in positions

Example fix

// before
<COREF ID="5" REF="99">he</COREF> <!-- REF 99 does not exist -->
// after
<COREF ID="5" REF="3">he</COREF> <!-- REF points to an earlier valid mention -->
Defensive patterns

Strategy: validation

Validate before calling

// validate gold key: every REF must reference an earlier COREF ID
Set<Integer> seen = new HashSet<>();
Matcher m = Pattern.compile("<COREF ID=\"(\\d+)\"(.*?REF=\"(\\d+)\")?").matcher(mucFileText);
while (m.find()) {
    int id = Integer.parseInt(m.group(1));
    if (m.group(3) != null && !seen.contains(Integer.parseInt(m.group(3)))) {
        throw new IllegalStateException("REF points to unknown mention: " + m.group(3));
    }
    seen.add(id);
}

Try / catch

try {
    doc.extractGoldLinks();
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Cannot find gold mention")) {
        log.error("Malformed gold key: " + e.getMessage());
    }
    throw e;
}

Prevention

When it happens

Trigger: extractGoldLinks processes gold mentions and a mention's originalRef is >= 0 but positions.get(m.originalRef) is null — i.e. the antecedent mention was never registered, typically due to malformed MUC/CoNLL gold key data.

Common situations: Corrupted or hand-edited gold key files, SGML MUC files with COREF REF attributes pointing to mentions outside the document or appearing later than expected, or gold annotations truncated mid-document.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/5dd97c789245d15e. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/dcoref/Document.java:545

        IntTuple pos = new IntTuple(2);
        pos.set(0, i);
        pos.set(1, j);
        positions.put(id, pos);
        antecedents.put(id, new ArrayList<>());
      }
    }

//    SieveCoreferenceSystem.debugPrintMentions(System.err, "", goldOrderedMentionsBySentence);
    for (List<Mention> mentions : goldOrderedMentionsBySentence) {
      for (Mention m : mentions) {
        int id = m.mentionID;
        IntTuple src = positions.get(id);

        assert (src != null);
        if (m.originalRef >= 0) {
          IntTuple dst = positions.get(m.originalRef);
          if (dst == null) {
            throw new RuntimeException("Cannot find gold mention with ID=" + m.originalRef);
          }

          // to deal with cataphoric annotation
          while (dst.get(0) > src.get(0) || (dst.get(0) == src.get(0) && dst.get(1) > src.get(1))) {
            Mention dstMention = goldOrderedMentionsBySentence.get(dst.get(0)).get(dst.get(1));
            m.originalRef = dstMention.originalRef;
            dstMention.originalRef = id;

            if (m.originalRef < 0) break;
            dst = positions.get(m.originalRef);
          }
          if (m.originalRef < 0) continue;

          // A B C: if A<-B, A<-C => make a link B<-C
          for (int k = dst.get(0); k <= src.get(0); k++) {
            for (int l = 0; l < goldOrderedMentionsBySentence.get(k).size(); l++) {
              if (k == dst.get(0) && l < dst.get(1)) continue;
              if (k == src.get(0) && l > src.get(1)) break;

View on GitHub (pinned to 1b7edd19c4)