stanfordnlp/CoreNLP · error · RuntimeException

maxValue for feature

Error message

maxValue for feature 

What it means

Companion check to the minValue failure: maxValues[f] starts at -Infinity and is updated while scanning values. If a feature exists in featureIndex but never appears in any datum's values, its max stays -Infinity and scaleFeatures throws, since scaling to [0,1] needs a defined maximum. The message identifies the offending feature index.

Solutions

  1. Verify each featureIndex entry is present with a value in at least one datum before scaling
  2. Compute scaling on the whole dataset once via scaleFeatures rather than per-datum scaleDatum calls with uninitialized bounds
  3. Rebuild the dataset with a featureIndex derived only from observed features
  4. Skip or prune unused features before scaling

Example fix

// before
featureIndex.add("unusedFeature"); // never appears in any datum
ds.scaleFeatures(); // throws: maxValue not assigned
// after
// only add features as they occur
for (String f : datumFeatures) featureIndex.add(f);
ds.scaleFeatures();
Defensive patterns

Strategy: validation

Validate before calling

for (int f = 0; f < ds.featureIndex().size(); f++) {
  boolean observed = false;
  for (int i = 0; i < ds.size() && !observed; i++) observed = ds.getDatum(i).asFeatures().contains(ds.featureIndex().get(f));
  if (!observed) throw new IllegalStateException("maxValue unassigned for feature " + f);
}

Try / catch

try {
  ds.scaleFeatures();
} catch (RuntimeException e) {
  if (e.getMessage().startsWith("maxValue")) {
    logger.warning("Feature never observed; prune featureIndex and rebuild");
  } else throw e;
}

Prevention

When it happens

Trigger: Calling scaleFeatures (or scaleDatum which triggers it) on an RVFDataset containing features in featureIndex with no observed values anywhere in the dataset, leaving maxValues[f] unassigned.

Common situations: Datasets constructed programmatically with features added to the index but not used in datums; featureIndex locked/extended out-of-band; datums with empty feature maps; copied datasets sharing a stale featureIndex.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

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

    // first identify the max and min values for each feature.
    // System.out.printf("number of datums: %d dataset size: %d\n",data.length,size());
    for (int i = 0; i < size(); i++) {
      // System.out.printf("datum %d length %d\n", i,data[i].length);
      for (int j = 0; j < data[i].length; j++) {
        int f = data[i][j];
        if (values[i][j] < minValues[f])
          minValues[f] = values[i][j];
        if (values[i][j] > maxValues[f])
          maxValues[f] = values[i][j];
      }
    }

    for (int f = 0; f < featureIndex.size(); f++) {
      if (minValues[f] == Double.POSITIVE_INFINITY)
        throw new RuntimeException("minValue for feature " + f + " not assigned. ");
      if (maxValues[f] == Double.NEGATIVE_INFINITY)
        throw new RuntimeException("maxValue for feature " + f + " not assigned.");
    }

    // now scale each value such that it's between 0 and 1.
    for (int i = 0; i < size(); i++) {
      for (int j = 0; j < data[i].length; j++) {
        int f = data[i][j];
        if (minValues[f] != maxValues[f])// the equality can happen for binary
                                         // features which always take the value
                                         // of 1.0
          values[i][j] = (values[i][j] - minValues[f]) / (maxValues[f] - minValues[f]);
      }
    }

    /*
    for(int f = 0; f < featureIndex.size(); f++){
      if(minValues[f] == maxValues[f])
        throw new RuntimeException("minValue for feature "+f+" is equal to maxValue:"+minValues[f]);
    }

View on GitHub (pinned to 1b7edd19c4)