stanfordnlp/CoreNLP · error · NumberFormatException
Bad number put into wordToNumber. Word is: \"" + input +…
Error message
Bad number put into wordToNumber. Word is: \"" + input + "\", originally part of \"" + originalString + "\", piece # " + curIndex
What it means
NumberNormalizer.parseNumberPart converts a numeric word piece via Long.parseLong/Double.parseDouble after normalizing commas and trailing 's'; if the piece matches no numeric pattern (numPattern / digitsPatternExtended) it throws NumberFormatException naming the input, the original string, and the piece index. It is a guard for non-numeric text routed into numeric parsing inside wordToNumber.
Solutions
- Pre-clean the token so only numeric pieces (digits, commas, periods, optional trailing 's') reach wordToNumber.
- Catch NumberFormatException around the normalizer call and treat the token as non-numeric.
- Check the exact failing word/piece index reported in the message and strip unexpected characters before calling.
Example fix
// before
Number n = NumberNormalizer.wordToNumber("3rd-place");
// after
String token = "3rd-place".split("-")[0]; // pass only numeric piece
Number n = NumberNormalizer.wordToNumber(token); Defensive patterns
Strategy: try-catch
Validate before calling
static boolean isParseableNumberPiece(String s) {
return s != null && s.replaceAll("[,]", "").matches("\\d+(\\.\\d+)?s?");
} Try / catch
try {
Number n = NumberNormalizer.wordToNumber(input);
} catch (NumberFormatException e) {
Number n = null; // treat token as non-numeric
} Prevention
- Pass only clean numeric tokens; strip letters, currency, and stray punctuation first.
- Catch NumberFormatException at mention-normalization boundaries.
- Log the failing word from the message to fix upstream tokenization.
When it happens
Trigger: wordToNumber splitting a string and delegating a piece to parseNumberPart that contains characters beyond the accepted numeric formats (e.g. '1st2', '1.2.3', currency symbols, 'x100').
Common situations: Normalizing extracted mention text containing mixed alphanumeric tokens (like '3x' or 'one-two'), noisy OCR/entity text, or regex changes in numPattern across CoreNLP versions altering which strings parse.
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
- Error in wordToNumber function.
- Bad number put into wordToNumber. Word is: \"" + curPart +…
- ERROR: Invalid line " + lineCount + " in regexner file " +…
- Doesn't do k best yet
- Doesn't do best parses yet
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/1f2ce48eefe3348e.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/NumberNormalizer.java:287
break;
default:
// unknown magnitude! Ignore it.
break;
}
if (digitsPattern.matcher(numPart).matches()) {
return Long.parseLong(numPart) * magnitude;
} else {
return Double.parseDouble(numPart) * magnitude;
}
} else {
if (digitsPattern.matcher(numPart).matches()) {
return Long.parseLong(numPart);
} else {
return Double.parseDouble(numPart);
}
}
} else{
throw new NumberFormatException("Bad number put into wordToNumber. Word is: \"" + input + "\", originally part of \"" + originalString + "\", piece # " + curIndex);
}
}
/**
* Fairly generous utility function to convert a string representing
* a number (hopefully) to a Number.
* Assumes that something else has somehow determined that the string
* makes ONE suitable number.
* The value of the number is determined by:
* 0. Breaking up the string into pieces using whitespace
* (stuff like "and", "-", "," is turned into whitespace);
* 1. Determining the numeric value of the pieces;
* 2. Finding the numeric value of each piece;
* 3. Combining the pieces together to form the overall value:
* a. Find the largest component and its value (X),
* b. Let B = overall value of pieces to the left (recursive),View on GitHub (pinned to 1b7edd19c4)