{"record":{"id":"1557a30f8bc67370","repo":"stanfordnlp/CoreNLP","slug":"error-incorrect-number-of-tokens-in-weight-specif","errorCode":null,"errorMessage":"Error: incorrect number of tokens in weight specifier, line=${currLine} in file ${file}","messagePattern":"Error: incorrect number of tokens in weight specifier, line=(.+?) in file (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/classify/LinearClassifierFactory.java","lineNumber":964,"sourceCode":"   * Given the path to a file representing the text based serialization of a\n   * Linear Classifier, reconstitutes and returns that LinearClassifier.\n   *\n   * TODO: Leverage Index\n   */\n  public static LinearClassifier<String, String> loadFromFilename(String file) {\n    try {\n      BufferedReader in = IOUtils.readerFromString(file);\n\n      // Format: read indices first, weights, then thresholds\n      Index<String> labelIndex = HashIndex.loadFromReader(in);\n      Index<String> featureIndex = HashIndex.loadFromReader(in);\n      double[][] weights = new double[featureIndex.size()][labelIndex.size()];\n      int currLine = 1;\n      String line = in.readLine();\n      while (line != null && line.length()>0) {\n        String[] tuples = line.split(LinearClassifier.TEXT_SERIALIZATION_DELIMITER);\n        if (tuples.length != 3) {\n            throw new Exception(\"Error: incorrect number of tokens in weight specifier, line=\"\n                + currLine + \" in file \" + file);\n        }\n        currLine++;\n        int feature = Integer.parseInt(tuples[0]);\n        int label = Integer.parseInt(tuples[1]);\n        double value = Double.parseDouble(tuples[2]);\n        weights[feature][label] = value;\n        line = in.readLine();\n      }\n\n      // First line in thresholds is the number of thresholds\n      int numThresholds = Integer.parseInt(in.readLine());\n      double[] thresholds = new double[numThresholds];\n      int curr = 0;\n      while ((line = in.readLine()) != null) {\n        double tval = Double.parseDouble(line.trim());\n        thresholds[curr++] = tval;\n      }","sourceCodeStart":946,"sourceCodeEnd":982,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/classify/LinearClassifierFactory.java#L946-L982","documentation":"Error in LinearClassifierFactory.loadFromFilename when a line of the text-format classifier file has the wrong number of whitespace-separated tokens (expected featureIndex labelIndex value). The model file is malformed at that line.","triggerScenarios":"Thrown at src/edu/stanford/nlp/classify/LinearClassifierFactory.java:964 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix or regenerate the text classifier file in the expected format (indices, weights, thresholds)","Check for truncated or edited lines around the reported line number","Re-export the classifier from the training tool"],"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"}