{"record":{"id":"493a36c4a19f51b6","repo":"stanfordnlp/CoreNLP","slug":"split-weights-cannot-be-negative","errorCode":null,"errorMessage":"Split weights cannot be negative","messagePattern":"Split weights cannot be negative","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/SplitTrainingSet.java","lineNumber":75,"sourceCode":"    }\n    return weights.size() - 1;\n  }\n\n  @SuppressWarnings(\"unused\")\n  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    }","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/SplitTrainingSet.java#L57-L93","documentation":"SplitTrainingSet validates that each split weight is non-negative; after summing SPLIT_WEIGHTS in main, a weight below 0.0 triggers this IllegalArgumentException. Weights define the proportional size of each named split, so negatives are meaningless.","triggerScenarios":"Passing -splitWeights with a negative number (e.g. -0.1) or a value parsed as negative due to a stray minus sign/typo in the properties file.","commonSituations":"Hand-edited config files where a dash from surrounding text got into the numbers; experimenting with 'negative weights' to shrink a split instead of removing it; copy-paste mistakes.","solutions":["Replace any negative value in -splitWeights with a zero or positive weight (use 0 to exclude a split's content rather than a negative number).","Ensure all weights together total a positive value, since the following check also requires totalWeight > 0.","Validate the properties file values before running the tool."],"exampleFix":"// before\n-splitNames train,holdout -splitWeights 0.9,-0.1\n// after\n-splitNames train,holdout -splitWeights 0.9,0.1","handlingStrategy":"validation","validationCode":"double[] ws = Arrays.stream(props.getProperty(\"splitWeights\").split(\",\"))\n                    .mapToDouble(Double::parseDouble).toArray();\nfor (double w : ws)\n  if (w < 0.0) throw new IllegalArgumentException(\"Negative split weight: \" + w);\nif (Arrays.stream(ws).sum() <= 0.0)\n  throw new IllegalArgumentException(\"Split weights must total positive\");","typeGuard":null,"tryCatchPattern":"try {\n  SplitTrainingSet.main(args);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"cannot be negative\")) {\n    log.error(\"Config error: splitWeights must all be >= 0 and sum > 0\");\n  } else throw e;\n}","preventionTips":["Validate weight strings with a regex like ^\\d+(\\.\\d+)?$ before passing them.","Use 0.0 (not negative values) to effectively exclude a split.","Keep weights in a reviewed config file rather than typing them inline on the command line."],"tags":["cli","configuration","argument-validation","dataset-split"],"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"}