stanfordnlp/CoreNLP · error · RuntimeException
datum
Error message
datum
What it means
ensureRealValues validates that all stored feature values are finite real numbers. If datum i has a NaN for some feature it throws, naming the datum and the feature (resolved through featureIndex), because NaN poisons training math and scaling. NaN values usually indicate upstream arithmetic such as 0/0, log(0), or bad parsed input.
Solutions
- Scan the dataset and fix the producing code so NaN never enters values (guard division/logs, replace NaN with 0 or a sentinel)
- Filter out datums with non-finite values before training: check each RVFDatum feature count with Double.isNaN
- If NaN means 'missing', impute a value (mean/zero) during datum construction
- Run ensureRealValues early in your pipeline to fail fast at the data source
Example fix
// before
counter.incrementCount("f1", Math.log(0.0)); // NaN
// after
double v = rawCount == 0.0 ? 0.0 : Math.log(rawCount);
if (Double.isNaN(v) || Double.isInfinite(v)) v = 0.0;
counter.incrementCount("f1", v); Defensive patterns
Strategy: validation
Validate before calling
for (RVFDatum<L,F> d : ds) {
for (Map.Entry<F,Double> e : d.asFeaturesCounter().entrySet()) {
if (Double.isNaN(e.getValue())) throw new IllegalStateException("NaN for feature " + e.getKey());
}
} Type guard
boolean isFiniteValue(double v) { return !Double.isNaN(v) && !Double.isInfinite(v); } Try / catch
try {
ds.ensureRealValues();
} catch (RuntimeException e) {
// message: datum i has a NaN value for feature:F
logger.severe("Bad value: " + e.getMessage());
throw e;
} Prevention
- Guard any log/divide/exp used to compute feature values
- Replace NaN with 0 or a sentinel before incrementing counters
- Call ensureRealValues early, at data-load time
When it happens
Trigger: Calling ensureRealValues (directly or indirectly before training/scaling) on an RVFDataset whose values contain Double.NaN, typically produced by user-supplied feature computation code or parsing that yields NaN.
Common situations: Feature weight functions computing ratios or logs that yield NaN on zero counts; loading numeric data where missing values were encoded as NaN; serialization round-trips that corrupted values.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Not sure if RVFDataset runs correctly in this method…
- minValue for feature
- maxValue for feature
- Bad data format:
- shuffleWithSideInformation: sideInformation not of same…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/786393984a244381.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/classify/RVFDataset.java:235
}
*/
}
/**
* Checks if the dataset has any unbounded values. Always good to use this
* before training a model on the dataset. This way, one can avoid seeing the
* infamous 4's that get printed by the QuasiNewton Method when NaNs exist in
* the data! -Ramesh
*/
public void ensureRealValues() {
double[][] values = getValuesArray();
int[][] data = getDataArray();
for (int i = 0; i < size(); i++) {
for (int j = 0; j < values[i].length; j++) {
if (Double.isNaN(values[i][j])) {
int fID = data[i][j];
F feature = featureIndex.get(fID);
throw new RuntimeException("datum " + i + " has a NaN value for feature:" + feature);
}
if (Double.isInfinite(values[i][j])) {
int fID = data[i][j];
F feature = featureIndex.get(fID);
throw new RuntimeException("datum " + i + " has infinite value for feature:" + feature);
}
}
}
}
/**
* Scales the values of each feature in each linearly using the min and max
* values found in the training set. NOTE1: Not guaranteed to be between 0 and
* 1 for a test datum. NOTE2: Also filters out features from each datum that
* are not seen at training time.
*
* @param dataset
* @return a new datasetView on GitHub (pinned to 1b7edd19c4)