stanfordnlp/CoreNLP · error · RuntimeException
Could not find sentiment score for phrase id " + phraseId
Error message
Could not find sentiment score for phrase id " + phraseId
What it means
After resolving a phrase id, the converter looks up its sentiment score in the sentimentScores map (from sentiment_labels.txt). A missing entry means the score file does not cover that phrase id, so the class label cannot be computed and a RuntimeException is thrown.
Solutions
- Regenerate or re-download sentiment_labels.txt from the full SST release
- Verify sentiment_labels.txt contains a line for the reported phraseId
- If building custom data, assign a score to every phrase id before conversion
Example fix
// before: labels file truncated at 100000 lines // after: complete file wc -l sentiment_labels.txt # must equal number of phrases in dictionary.txt
Defensive patterns
Strategy: validation
Validate before calling
for (Integer id : usedPhraseIds) if (!sentimentScores.containsKey(id)) throw new IllegalStateException("Missing sentiment score for id " + id); Try / catch
try { convertTree(...); } catch (RuntimeException e) { if (e.getMessage().startsWith("Could not find sentiment score")) { logMissingId(extractId(e)); } else throw e; } Prevention
- Verify line counts of sentiment_labels.txt match dictionary.txt
- Keep dataset files from one release together
- Pre-load and diff phrase-id key sets before conversion
When it happens
Trigger: sentiment_labels.txt missing entries for phrase ids present in dictionary.txt, or loading the wrong label file (e.g. binary vs fine-grained distribution files) whose keys don't align.
Common situations: Partial/corrupted sentiment_labels.txt, custom datasets with dictionary ids but no sentiment annotations, file mix-ups between dataset versions.
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
- Could not find phrase id for phrase " + sentence
- Found line with label " + line + " but no tokens to…
- Gold Quote List size doesn't match quote list size!
- LogisticClassifier is only for binary classification!
- Quotes size and gold size don't match!
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/a8ab2c46c20e9e24.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/sentiment/ReadSentimentDataset.java:277
List<Tree> leaves = subtrees[i].getLeaves();
List<String> words = CollectionUtils.transformAsList(leaves, TRANSFORM_TREE_TO_WORD);
// First we look for a copy of the phrase with -LRB- -RRB-
// instead of (). The sentiment trees sometimes have both, and
// the escaped versions seem to have more reasonable scores.
// If a particular phrase doesn't have -LRB- -RRB- we fall back
// to the unescaped versions.
Integer phraseId = phraseIds.get(CollectionUtils.transformAsList(words, TRANSFORM_PARENS));
if (phraseId == null) {
phraseId = phraseIds.get(words);
}
if (phraseId == null) {
throw new RuntimeException("Could not find phrase id for phrase " + sentence);
}
// TODO: should we make this an option? Perhaps we want cases
// where the trees have the phrase id and not their class
Double score = sentimentScores.get(phraseId);
if (score == null) {
throw new RuntimeException("Could not find sentiment score for phrase id " + phraseId);
}
int classLabel = Math.round((float) Math.floor(score * (float) 5));
if (classLabel > 4 || classLabel < 0) {
throw new RuntimeException("Unexpected class label: score " + score + " became " + classLabel);
}
subtrees[i].label().setValue(Integer.toString(classLabel));
}
for (int i = 0; i < sentence.size(); ++i) {
Tree leaf = subtrees[i].children()[0];
for (Pair<String, String> replacement : singleWordReplacements) {
if (leaf.label().value().equals(replacement.first)) {
leaf.label().setValue(replacement.second);
}
}
leaf.label().setValue(escaper.escapeString(leaf.label().value()));
}View on GitHub (pinned to 1b7edd19c4)