{"record":{"id":"a8ab2c46c20e9e24","repo":"stanfordnlp/CoreNLP","slug":"could-not-find-sentiment-score-for-phrase-id-p","errorCode":null,"errorMessage":"Could not find sentiment score for phrase id \" + phraseId","messagePattern":"Could not find sentiment score for phrase id \" \\+ phraseId","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/sentiment/ReadSentimentDataset.java","lineNumber":277,"sourceCode":"      List<Tree> leaves = subtrees[i].getLeaves();\n      List<String> words = CollectionUtils.transformAsList(leaves, TRANSFORM_TREE_TO_WORD);\n      // First we look for a copy of the phrase with -LRB- -RRB-\n      // instead of ().  The sentiment trees sometimes have both, and\n      // the escaped versions seem to have more reasonable scores.\n      // If a particular phrase doesn't have -LRB- -RRB- we fall back\n      // to the unescaped versions.\n      Integer phraseId = phraseIds.get(CollectionUtils.transformAsList(words, TRANSFORM_PARENS));\n      if (phraseId == null) {\n        phraseId = phraseIds.get(words);\n      }\n      if (phraseId == null) {\n        throw new RuntimeException(\"Could not find phrase id for phrase \" + sentence);\n      }\n      // TODO: should we make this an option?  Perhaps we want cases\n      // where the trees have the phrase id and not their class\n      Double score = sentimentScores.get(phraseId);\n      if (score == null) {\n        throw new RuntimeException(\"Could not find sentiment score for phrase id \" + phraseId);\n      }\n\n      int classLabel = Math.round((float) Math.floor(score * (float) 5));\n      if (classLabel > 4 || classLabel < 0) {\n        throw new RuntimeException(\"Unexpected class label: score \" + score + \" became \" + classLabel);\n      }\n      subtrees[i].label().setValue(Integer.toString(classLabel));\n    }\n\n    for (int i = 0; i < sentence.size(); ++i) {\n      Tree leaf = subtrees[i].children()[0];\n      for (Pair<String, String> replacement : singleWordReplacements) {\n        if (leaf.label().value().equals(replacement.first)) {\n          leaf.label().setValue(replacement.second);\n        }\n      }\n      leaf.label().setValue(escaper.escapeString(leaf.label().value()));\n    }","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/sentiment/ReadSentimentDataset.java#L259-L295","documentation":"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.","triggerScenarios":"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.","commonSituations":"Partial/corrupted sentiment_labels.txt, custom datasets with dictionary ids but no sentiment annotations, file mix-ups between dataset versions.","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"],"exampleFix":"// before: labels file truncated at 100000 lines\n// after: complete file\nwc -l sentiment_labels.txt  # must equal number of phrases in dictionary.txt","handlingStrategy":"validation","validationCode":"for (Integer id : usedPhraseIds) if (!sentimentScores.containsKey(id)) throw new IllegalStateException(\"Missing sentiment score for id \" + id);","typeGuard":null,"tryCatchPattern":"try { convertTree(...); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Could not find sentiment score\")) { logMissingId(extractId(e)); } else throw e; }","preventionTips":["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"],"tags":["dataset","lookup-miss"],"backgroundTag":"resource-not-found","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}