stanfordnlp/CoreNLP · error · RuntimeException
No label for '" + text + "'
Error message
No label for '" + text + "'
What it means
ParseAndSetLabels attaches predicted labels to tree nodes using a text->label map; when a tree node's text has no entry in the labelMap and the MissingLabels policy is FAIL, it throws a RuntimeException with the unmatched text. This is a hard-fail mode so unmapped nodes are never silently mislabeled.
Solutions
- Add the missing text 'X' to the labels file so the map covers all inputs
- Run with a tolerant policy (-missingLabelsOptions defaultLabel=NONE or keepOriginal) if strict failure is not needed
- Normalize tokenization/casing so tree text matches label keys
- Diff the set of tree texts against the label map keys before running to find gaps
Example fix
// before // java ParseAndSetLabels -labels labels.txt -missingLabels FAIL ... // after // java ParseAndSetLabels -labels labels.txt -missingLabels defaultLabel=UNKNOWN ...
Defensive patterns
Strategy: validation
Validate before calling
java.util.Set<String> texts = collectTreeTexts(trees);
java.util.Set<String> keys = labelMap.keySet();
texts.removeAll(keys);
if (!texts.isEmpty()) throw new IllegalStateException("texts missing from label map: " + texts); Try / catch
try {
tool.run();
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().startsWith("No label for")) {
System.err.println("Extend your labels file for: " + e.getMessage());
}
throw e;
} Prevention
- Precompute coverage of all tree texts against the label map
- Use a tolerant missing-labels policy for production runs
- Keep tokenization identical between label extraction and tree processing
When it happens
Trigger: Running ParseAndSetLabels with -missingLabels FAIL (the strict default) while the labels file lacks an entry for a token that appears in the trees/sentences being processed — e.g. the quoted string in "No label for 'X'" names the missing text.
Common situations: Labels file built from a different corpus than the input trees; tokenization differences producing unseen surface forms; case/whitespace mismatches between keys and tree text; OOV words at test time.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Only operates on CoreLabels
- Unknown minimizer
- Unknown clique: " + clique
- Bad number put into wordToNumber. Word is: \"" + input +…
- Error in wordToNumber function.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/96c93d2b7c93dc2d.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java:74
FAIL, DEFAULT, KEEP_ORIGINAL
}
private ParseAndSetLabels() {} // static methods
public static void setLabels(Tree tree, Map<String, String> labelMap,
MissingLabels missing, String defaultLabel,
Set<String> unknowns) {
if (tree.isLeaf()) {
return;
}
String text = SentenceUtils.listToString(tree.yield());
String label = labelMap.get(text);
if (label != null) {
tree.label().setValue(label);
} else {
switch (missing) {
case FAIL:
throw new RuntimeException("No label for '" + text + "'");
case DEFAULT:
tree.label().setValue(defaultLabel);
unknowns.add(text);
break;
case KEEP_ORIGINAL:
// do nothing
break;
default:
throw new IllegalArgumentException("Unknown MissingLabels mode " + missing);
}
}
for (Tree child : tree.children()) {
setLabels(child, labelMap, missing, defaultLabel, unknowns);
}
}
public static Set<String> setLabels(List<Tree> trees, Map<String, String> labelMap,
MissingLabels missing, String defaultLabel) {View on GitHub (pinned to 1b7edd19c4)