stanfordnlp/CoreNLP · error · IllegalArgumentException

Split weights must total to a positive weight

Error message

Split weights must total to a positive weight

What it means

SplitTrainingSet splits training data into sub-parts proportionally to user-supplied weights. Each weight must be non-negative and their sum strictly positive, because weights are normalized by the total (weight / totalWeight). If totalWeight <= 0.0 the normalization is impossible (division by zero/negative), so the library fails fast with this IllegalArgumentException.

Solutions

  1. Check that all provided split weights are >= 0 and that their sum is > 0 before invoking the split
  2. Correct the weights so they are positive values that sum to a positive number, e.g. '0.8 0.2' for an 80/20 train/dev split
  3. If defaults are expected, omit the weight argument entirely so the library's default SPLIT_WEIGHTS are used

Example fix

// before: weights that total 0
java SplitTrainingSet -weights 0,0
// after
java SplitTrainingSet -weights 0.8,0.2
Defensive patterns

Strategy: validation

Validate before calling

double total = 0; for (double w : weights) { if (w < 0) throw new IllegalArgumentException("negative weight"); total += w; }
if (total <= 0) throw new IllegalArgumentException("Split weights must total to a positive weight");

Type guard

boolean validSplitWeights(double[] w) { double t = 0; for (double x : w) { if (x < 0) return false; t += x; } return t > 0; }

Try / catch

try { splitTrainingSet.run(); } catch (IllegalArgumentException e) { if (e.getMessage().contains("total to a positive weight")) { /* fix weights config */ } else throw e; }

Prevention

When it happens

Trigger: Calling SplitTrainingSet (e.g. via main or the split construction path at SplitTrainingSet.java:80) with a SPLIT_WEIGHTS array whose entries sum to 0 (e.g. all zeros) or to a negative sum, such as providing [] or ['0'] or negative-only weights that pass the individual >= 0 check but total 0.

Common situations: Misconfigured split weights on the command line (e.g. '-1 1' style typos, or passing '0' weights intending 'auto'), empty weight lists after parsing, or users porting older configs where defaults have changed.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/trees/SplitTrainingSet.java:80

  public static void main(String[] args) throws IOException {
    // Parse the arguments
    Properties props = StringUtils.argsToProperties(args);
    ArgumentParser.fillOptions(new Class[]{ArgumentParser.class, SplitTrainingSet.class}, props);

    if (SPLIT_NAMES.length != SPLIT_WEIGHTS.length) {
      throw new IllegalArgumentException("Name and weight arrays must be of the same length");
    }

    double totalWeight = 0.0;
    for (Double weight : SPLIT_WEIGHTS) {
      totalWeight += weight;
      if (weight < 0.0) {
        throw new IllegalArgumentException("Split weights cannot be negative");
      }
    }

    if (totalWeight <= 0.0) {
      throw new IllegalArgumentException("Split weights must total to a positive weight");
    }

    List<Double> splitWeights = new ArrayList<>();
    for (Double weight : SPLIT_WEIGHTS) {
      splitWeights.add(weight / totalWeight);
    }
    logger.info("Splitting into " + splitWeights.size() + " lists with weights " + splitWeights);


    if (SEED == 0L) {
      SEED = System.nanoTime();
      logger.info("Random seed not set by options, using " + SEED);
    }
    Random random = new Random(SEED);

    List<List<Tree>> splits = new ArrayList<>();
    for (Double d : splitWeights) {
      splits.add(new ArrayList<>());

View on GitHub (pinned to 1b7edd19c4)