stanfordnlp/CoreNLP · error · Exception

Error: incorrect number of tokens in weight specifier, line=

Error message

Error: incorrect number of tokens in weight specifier, line=${currLine} in file ${file}

What it means

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.

Solutions

  1. Fix or regenerate the text classifier file in the expected format (indices, weights, thresholds)
  2. Check for truncated or edited lines around the reported line number
  3. Re-export the classifier from the training tool
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/edu/stanford/nlp/classify/LinearClassifierFactory.java:964 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/1557a30f8bc67370. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/classify/LinearClassifierFactory.java:964

   * Given the path to a file representing the text based serialization of a
   * Linear Classifier, reconstitutes and returns that LinearClassifier.
   *
   * TODO: Leverage Index
   */
  public static LinearClassifier<String, String> loadFromFilename(String file) {
    try {
      BufferedReader in = IOUtils.readerFromString(file);

      // Format: read indices first, weights, then thresholds
      Index<String> labelIndex = HashIndex.loadFromReader(in);
      Index<String> featureIndex = HashIndex.loadFromReader(in);
      double[][] weights = new double[featureIndex.size()][labelIndex.size()];
      int currLine = 1;
      String line = in.readLine();
      while (line != null && line.length()>0) {
        String[] tuples = line.split(LinearClassifier.TEXT_SERIALIZATION_DELIMITER);
        if (tuples.length != 3) {
            throw new Exception("Error: incorrect number of tokens in weight specifier, line="
                + currLine + " in file " + file);
        }
        currLine++;
        int feature = Integer.parseInt(tuples[0]);
        int label = Integer.parseInt(tuples[1]);
        double value = Double.parseDouble(tuples[2]);
        weights[feature][label] = value;
        line = in.readLine();
      }

      // First line in thresholds is the number of thresholds
      int numThresholds = Integer.parseInt(in.readLine());
      double[] thresholds = new double[numThresholds];
      int curr = 0;
      while ((line = in.readLine()) != null) {
        double tval = Double.parseDouble(line.trim());
        thresholds[curr++] = tval;
      }

View on GitHub (pinned to 1b7edd19c4)