stanfordnlp/CoreNLP · error · IllegalArgumentException

TokensRegexNERAnnotator ERROR: Invalid weight in line in…

Error message

TokensRegexNERAnnotator ERROR: Invalid weight in line  in regexner file : ""!

What it means

When the header defines a 'weight' column, each line's weight is parsed with Double.parseDouble; a non-numeric value throws IllegalArgumentException showing line number, mapping file, and line text. Weights feed pattern scoring and must be valid doubles.

Solutions

  1. Replace the weight on the reported line with a plain double such as 0.0 or 2.5.
  2. Delete the weight column from both header and rows if weights aren't used.
  3. Use '.' decimal separator and no units/symbols ('%', 'N/A').
  4. Verify row alignment — ensure each row's column count matches the header so cells don't shift.

Example fix

// before
[ { word:/CFO/ } ]	PERSON	strong
// after
[ { word:/CFO/ } ]	PERSON	2.0
Defensive patterns

Strategy: validation

Validate before calling

for (String[] row : rows) {
  String w = row[iWeight];
  if (w != null && !w.trim().isEmpty()) Double.parseDouble(w.trim()); // fail early with row context
}

Try / catch

try { annotator = new TokensRegexNERAnnotator(name, props); } catch (IllegalArgumentException e) { if (e.getMessage().contains("Invalid weight")) { fixWeightOnLine(e.getMessage()); } else throw e; }

Prevention

When it happens

Trigger: A weight column holding non-numeric text such as 'strong', 'N/A', '1,5' (comma decimal), or a percent sign; a shifted row so a non-weight cell lands in the weight column.

Common situations: Hand-edited mapping files with descriptive weights; spreadsheet exports adding 'N/A' for missing values; column misalignment after inserting a column without updating all rows.

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/8eeb76b2720e8ade. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/TokensRegexNERAnnotator.java:787

      } else {
        overwritableTypes = Collections.emptySet();
      }
      if (iPriority >= 0 && split.length > iPriority) {
        try {
          priority = Double.parseDouble(split[iPriority].trim());
        } catch (NumberFormatException e) {
          throw new IllegalArgumentException("TokensRegexNERAnnotator " + annotatorName
              + " ERROR: Invalid priority in line " + lineCount
              + " in regexner file " + mappingFilename + ": \"" + line + "\"!", e);
        }
      }

      double weight = 0.0;
      if (iWeight >= 0 && split.length > iWeight) {
        try {
          weight = Double.parseDouble(split[iWeight].trim());
        } catch (NumberFormatException e) {
          throw new IllegalArgumentException("TokensRegexNERAnnotator " + annotatorName
              + " ERROR: Invalid weight in line " + lineCount
              + " in regexner file " + mappingFilename + ": \"" + line + "\"!", e);
        }
      }
      int annotateGroup = 0;
      // Get annotate group from input....
      if (iGroup>= 0 && split.length > iGroup) {
        // Which group to take (allow for context)
        String context = split[iGroup].trim();
        try {
          annotateGroup = Integer.parseInt(context);
        } catch (NumberFormatException e) {
          throw new IllegalArgumentException("TokensRegexNERAnnotator " + annotatorName
              + " ERROR: Invalid group in line " + lineCount
              + " in regexner file " + mappingFilename + ": \"" + line + "\"!", e);
        }
      }

View on GitHub (pinned to 1b7edd19c4)