{"record":{"id":"6ff1c2d606e5c111","repo":"stanfordnlp/CoreNLP","slug":"unexpected-class-label-score-score-became","errorCode":null,"errorMessage":"Unexpected class label: score \" + score + \" became \" + classLabel","messagePattern":"Unexpected class label: score \" \\+ score \\+ \" became \" \\+ classLabel","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/sentiment/ReadSentimentDataset.java","lineNumber":282,"sourceCode":"      // 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    }\n\n    for (int i = 0; i < transformations.length; ++i) {\n      root = Tsurgeon.processPattern(transformations[i].tregex,\n                                     transformations[i].surgery, root);\n    }","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/sentiment/ReadSentimentDataset.java#L264-L300","documentation":"Class labels are computed by flooring score*5 and rounding to an integer that must be in [0,4]. A score outside the expected [0,1] range (or a malformed one) produces a label outside that range, so the converter throws RuntimeException.","triggerScenarios":"sentiment_labels.txt containing values >1 or <0 (e.g. raw counts instead of probabilities, or a mis-parsed column), leading floor(score*5) to yield -1 or 5+.","commonSituations":"Hand-edited label files, using the wrong column of sentiment_labels.txt, joining label data from a different corpus with a different score scale.","solutions":["Ensure sentiment scores are probabilities in [0,1]; fix or regenerate sentiment_labels.txt","Verify the parser reads the score column, not an id column","Clamp/validate scores in preprocessing: score = Math.max(0, Math.min(1, score))"],"exampleFix":"// before\nscore = Double.parseDouble(fields[2]); // wrong column\n// after\nscore = Double.parseDouble(fields[1]);","handlingStrategy":"validation","validationCode":"double score = sentimentScores.get(phraseId);\nif (score < 0.0 || score > 1.0) throw new IllegalArgumentException(\"Score out of [0,1]: \" + score);","typeGuard":null,"tryCatchPattern":"try { label = Math.round((float) Math.floor(score * 5f)); } catch (RuntimeException e) { /* clamp: */ score = Math.max(0, Math.min(1, score)); }","preventionTips":["Validate scores are in [0,1] when loading sentiment_labels.txt","Clamp scores in preprocessing","Parse the correct column of the labels file"],"tags":["data-validation","dataset"],"backgroundTag":"value-out-of-range","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"}