{"record":{"id":"8c7ca627848db3df","repo":"stanfordnlp/CoreNLP","slug":"size-of-labels-array-does-not-match-dataset-size","errorCode":null,"errorMessage":"size of labels array does not match dataset size","messagePattern":"size of labels array does not match dataset size","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/classify/Dataset.java","lineNumber":723,"sourceCode":"        //System.out.println(pNot+\" \"+(Math.log(pNot)/Math.log(2)));\n\n      }\n\n        //logger.info(pFeature+\" * \"+sumFeature+\" = +\"+);\n        //logger.info(\"^ \"+pNotFeature+\" \"+sumNotFeature);\n\n      ig[i] += pFeature*sumFeature + pNotFeature*sumNotFeature;\n      /* earlier the line above used to be: ig[i] = pFeature*sumFeature + pNotFeature*sumNotFeature;\n       * This completely ignored the entropy term computed above. So added the \"+=\" to take that into account.\n       * -Ramesh (nmramesh@cs.stanford.edu)\n       */\n    }\n    return ig;\n  }\n\n  public void updateLabels(int[] labels) {\n    if (labels.length != size())\n      throw new IllegalArgumentException(\n          \"size of labels array does not match dataset size\");\n\n    this.labels = labels;\n  }\n\n  @Override\n  public String toString() {\n    return \"Dataset of size \" + size;\n  }\n\n  public String toSummaryString() {\n    StringWriter sw = new StringWriter();\n    PrintWriter pw = new PrintWriter(sw);\n    pw.println(\"Number of data points: \" + size());\n    pw.println(\"Number of active feature tokens: \" + numFeatureTokens());\n    pw.println(\"Number of active feature types:\" + numFeatureTypes());\n    return pw.toString();\n  }","sourceCodeStart":705,"sourceCodeEnd":741,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/classify/Dataset.java#L705-L741","documentation":"IllegalArgumentException from Dataset.updateLabels(int[]) when the labels array length differs from the number of datums currently in the dataset. The caller passed a label assignment that cannot be aligned element-wise with existing examples.","triggerScenarios":"Thrown at src/edu/stanford/nlp/classify/Dataset.java:723 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure labels.length equals dataset.size() before calling updateLabels","Rebuild the labels array from the same data source used to build the dataset","Log both sizes to find where they diverge"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}