stanfordnlp/CoreNLP · error · IllegalArgumentException

size of labels array does not match dataset size

Error message

size of labels array does not match dataset size

What it means

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.

Solutions

  1. Ensure labels.length equals dataset.size() before calling updateLabels
  2. Rebuild the labels array from the same data source used to build the dataset
  3. Log both sizes to find where they diverge
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/edu/stanford/nlp/classify/Dataset.java:723 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/8c7ca627848db3df. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/classify/Dataset.java:723

        //System.out.println(pNot+" "+(Math.log(pNot)/Math.log(2)));

      }

        //logger.info(pFeature+" * "+sumFeature+" = +"+);
        //logger.info("^ "+pNotFeature+" "+sumNotFeature);

      ig[i] += pFeature*sumFeature + pNotFeature*sumNotFeature;
      /* earlier the line above used to be: ig[i] = pFeature*sumFeature + pNotFeature*sumNotFeature;
       * This completely ignored the entropy term computed above. So added the "+=" to take that into account.
       * -Ramesh (nmramesh@cs.stanford.edu)
       */
    }
    return ig;
  }

  public void updateLabels(int[] labels) {
    if (labels.length != size())
      throw new IllegalArgumentException(
          "size of labels array does not match dataset size");

    this.labels = labels;
  }

  @Override
  public String toString() {
    return "Dataset of size " + size;
  }

  public String toSummaryString() {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    pw.println("Number of data points: " + size());
    pw.println("Number of active feature tokens: " + numFeatureTokens());
    pw.println("Number of active feature types:" + numFeatureTypes());
    return pw.toString();
  }

View on GitHub (pinned to 1b7edd19c4)