stanfordnlp/CoreNLP · error · IllegalArgumentException
TokensRegexNERAnnotator ERROR: Invalid group in line in…
Error message
TokensRegexNERAnnotator ERROR: Invalid group in line in regexner file : ""!
What it means
When the header defines a 'group' column, each line's group value is parsed with Integer.parseInt; a non-integer throws IllegalArgumentException showing line number, mapping file, and line text. The group selects which capture group of the pattern gets annotated and must be a plain integer.
Solutions
- Replace the group value on the reported line with a plain integer (e.g. 0 or 1).
- Remove the group column from header and rows if you want the default group 0.
- Fix row alignment so each cell sits in its intended column.
- Ensure the integer stays within the pattern's group count (see the related 'Invalid match group' runtime error).
Example fix
// before
([ { word:/Dr\./ } ]) ([ { ner:PERSON } ]) TITLE person first
// after
([ { word:/Dr\./ } ]) ([ { ner:PERSON } ]) TITLE person 2 Defensive patterns
Strategy: validation
Validate before calling
for (String[] row : rows) {
String g = row[iGroup];
if (g != null && !g.trim().isEmpty()) Integer.parseInt(g.trim()); // throws NumberFormatException early with context
} Try / catch
try { annotator = new TokensRegexNERAnnotator(name, props); } catch (IllegalArgumentException e) { if (e.getMessage().contains("Invalid group")) { fixGroupOnLine(e.getMessage()); } else throw e; } Prevention
- Write group values as plain integers, never words or decimals
- Omit the group column entirely when using the default group
- Verify row alignment after header edits so string columns don't shift under 'group'
When it happens
Trigger: A group column containing text like 'first', 'g1', '2.0', or an empty/whitespace value; a shifted row putting another cell (e.g. a description) into the group column.
Common situations: Hand-written mapping files with descriptive group names; copy-paste rows where the group cell was lost; rows misaligned after header changes so a string column lands under 'group'.
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
- TokensRegexNERAnnotator ERROR: Invalid priority in line in…
- TokensRegexNERAnnotator ERROR: Invalid weight in line in…
- Duplicate header field:
- Invalid match group for entry
- TokensRegexNERAnnotator ERROR: Header does not contain…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/56a2d65ed92e4155.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/pipeline/TokensRegexNERAnnotator.java:800
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);
}
}
// Print some warnings about the type
for (int i = 0; i < types.length; i++) {
String type = types[i];
// TODO: Have option to allow commas in types
int commaPos = type.indexOf(',');
if (commaPos > 0) {
// Strip the "," and just take first type
String newType = type.substring(0, commaPos).trim();
logger.warn(annotatorName + ": Entry has multiple types for " +
annotationFieldnames[i] + ": " + line + ". Taking type to be " + newType);
types[i] = newType;
}
}View on GitHub (pinned to 1b7edd19c4)