{"record":{"id":"b76f65555d19f4d4","repo":"stanfordnlp/CoreNLP","slug":"split-weights-must-total-to-a-positive-weight","errorCode":null,"errorMessage":"Split weights must total to a positive weight","messagePattern":"Split weights must total to a positive weight","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/SplitTrainingSet.java","lineNumber":80,"sourceCode":"  public static void main(String[] args) throws IOException {\n    // Parse the arguments\n    Properties props = StringUtils.argsToProperties(args);\n    ArgumentParser.fillOptions(new Class[]{ArgumentParser.class, SplitTrainingSet.class}, props);\n\n    if (SPLIT_NAMES.length != SPLIT_WEIGHTS.length) {\n      throw new IllegalArgumentException(\"Name and weight arrays must be of the same length\");\n    }\n\n    double totalWeight = 0.0;\n    for (Double weight : SPLIT_WEIGHTS) {\n      totalWeight += weight;\n      if (weight < 0.0) {\n        throw new IllegalArgumentException(\"Split weights cannot be negative\");\n      }\n    }\n\n    if (totalWeight <= 0.0) {\n      throw new IllegalArgumentException(\"Split weights must total to a positive weight\");\n    }\n\n    List<Double> splitWeights = new ArrayList<>();\n    for (Double weight : SPLIT_WEIGHTS) {\n      splitWeights.add(weight / totalWeight);\n    }\n    logger.info(\"Splitting into \" + splitWeights.size() + \" lists with weights \" + splitWeights);\n\n\n    if (SEED == 0L) {\n      SEED = System.nanoTime();\n      logger.info(\"Random seed not set by options, using \" + SEED);\n    }\n    Random random = new Random(SEED);\n\n    List<List<Tree>> splits = new ArrayList<>();\n    for (Double d : splitWeights) {\n      splits.add(new ArrayList<>());","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/SplitTrainingSet.java#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check that all provided split weights are >= 0 and that their sum is > 0 before invoking the split","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","If defaults are expected, omit the weight argument entirely so the library's default SPLIT_WEIGHTS are used"],"exampleFix":"// before: weights that total 0\njava SplitTrainingSet -weights 0,0\n// after\njava SplitTrainingSet -weights 0.8,0.2","handlingStrategy":"validation","validationCode":"double total = 0; for (double w : weights) { if (w < 0) throw new IllegalArgumentException(\"negative weight\"); total += w; }\nif (total <= 0) throw new IllegalArgumentException(\"Split weights must total to a positive weight\");","typeGuard":"boolean validSplitWeights(double[] w) { double t = 0; for (double x : w) { if (x < 0) return false; t += x; } return t > 0; }","tryCatchPattern":"try { splitTrainingSet.run(); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"total to a positive weight\")) { /* fix weights config */ } else throw e; }","preventionTips":["Always validate weight arrays sum to > 0 before invoking the split","Avoid all-zero weights; use defaults when unsure","Log the weight array and its sum in config loading"],"tags":["validation","nlp","argument"],"backgroundTag":"invalid-argument-value","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"}