stanfordnlp/CoreNLP · error · IllegalArgumentException

Bad data format:

Error message

Bad data format: 

What it means

When parsing an SVM-light format line, every token after the label must be 'feature:value'. If any token splits on ':' into other than exactly 2 parts, svmLightLineToRVFDatum throws IllegalArgumentException("Bad data format: " + wholeLine). It signals malformed input format rather than an I/O problem.

Solutions

  1. Inspect the line printed in the message and fix the offending token to 'feature:numericValue' format
  2. Remove or escape colons in feature names (rename features, e.g. replace ':' with '_') before export
  3. Ensure the file is genuinely in SVM-light format: label first, then 'feat:value' pairs, '# comment' trailing only
  4. Pre-validate lines in your pipeline with a regex like ^\S+(\s+[^:\s]+:[0-9.eE+-]+)*$ before calling the reader

Example fix

// before
// file line: label f1 f2:3
label f1 f2:3
// after
// each feature must carry a value
label f1:1 f2:3
Defensive patterns

Strategy: validation

Validate before calling

Pattern svmLine = Pattern.compile("^\\S+(\\s+[^:\\s]+:[0-9.eE+-]+)*(\\s*#.*)?$");
try (BufferedReader r = new BufferedReader(new FileReader(path))) {
  String line; int n = 0;
  while ((line = r.readLine()) != null) {
    if (!line.trim().isEmpty() && !svmLine.matcher(line).matches())
      throw new IllegalStateException("Malformed SVMLight line " + (n+1) + ": " + line);
    n++;
  }
}

Try / catch

try {
  RVFDataset<String,String> ds = new RVFDataset<>(path, -1);
} catch (IllegalArgumentException e) {
  logger.severe("SVMLight parse failure: " + e.getMessage()); // message includes the bad line
  throw e;
}

Prevention

When it happens

Trigger: Reading an SVMLight file where a feature token lacks ':value' (bare feature id), has extra colons (e.g. 'f1:2:3' or URLs as feature names), or the line has stray tokens such as malformed comments not stripped by the leading '#' rule.

Common situations: Hand-edited SVM-light files; exporting from another tool with different feature naming containing colons; Windows line endings or trailing comments misformatted; accidentally passing a non-SVMLight file (e.g. ARFF or CSV) to the reader.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/classify/RVFDataset.java:779

          lines.add(line);
        dataset.add(svmLightLineToRVFDatum(line));
      }
    } catch (IOException e) {
      throw new RuntimeIOException(e);
    } finally {
      IOUtils.closeIgnoringExceptions(in);
    }
    return dataset;
  }

  public static RVFDatum<String, String> svmLightLineToRVFDatum(String l) {
    l = l.replaceFirst("#.*$", ""); // remove any trailing comments
    String[] line = l.split("\\s+");
    ClassicCounter<String> features = new ClassicCounter<>();
    for (int i = 1; i < line.length; i++) {
      String[] f = line[i].split(":");
      if (f.length != 2) {
        throw new IllegalArgumentException("Bad data format: " + l);
      }
      double val = Double.parseDouble(f[1]);
      features.incrementCount(f[0], val);
    }
    return new RVFDatum<>(features, line[0]);
  }

  // todo [cdm 2012]: This duplicates the functionality of the methods above. Should be refactored.
  /**
   * Read SVM-light formatted data into this dataset.
   *
   * A strict SVM-light format is expected, where labels and features are both
   * encoded as integers. These integers are converted into the dataset label
   * and feature types using the indexes stored in this dataset.
   *
   * @param file The file from which the data should be read.
   */
  public void readSVMLightFormat(File file) {

View on GitHub (pinned to 1b7edd19c4)