stanfordnlp/CoreNLP · error · RuntimeException
Not sure if RVFDataset runs correctly in this method…
Error message
Not sure if RVFDataset runs correctly in this method. Please update this code if it does.
What it means
NaiveBayesClassifierFactory.trainClassifier(GeneralDataset) only supports count-based (CDF-style) datasets, not ones holding real-valued feature counts. When handed an RVFDataset it refuses to proceed because the training path assumes binary/presence features and has not been verified for real values. The library throws this as a guard so silent mis-training cannot happen.
Solutions
- Convert the RVFDataset to a count-based dataset before training, e.g. new Dataset(labelIndex, featureIndex, data) or dataset as classic Dataset via RVFDataset -> binarize thresholding each count to presence
- Use a classifier that supports real values (e.g. LogisticRegressionClassifier or SVMLight via trainClassifier with weights) instead of this NaiveBayes factory method
- If NaiveBayes on counts is acceptable, build your data as Dataset (not RVFDataset) from the start with add(new ClassicDatum...)/add(presence features)
- If you verified it works with RVF data, edit the source to remove the check and re-test accuracy
Example fix
// before RVFDataset<L,F> ds = loadRealValuedData(); NaiveBayesClassifier<L,F> clf = new NaiveBayesClassifierFactory<L,F>().trainClassifier(ds); // throws // after Dataset<L,F> binarized = new Dataset<>(ds.size(), ds.labelIndex(), ds.featureIndex()); for (RVFDatum<L,F> d : ds) binarized.add(new BasicDatum<>(d.asFeatures(), d.label())); NaiveBayesClassifier<L,F> clf = new NaiveBayesClassifierFactory<L,F>().trainClassifier(binarized);
Defensive patterns
Strategy: validation
Validate before calling
if (dataset instanceof RVFDataset) {
throw new IllegalArgumentException("NaiveBayesClassifierFactory requires a count-based Dataset; convert the RVFDataset first");
} Type guard
boolean isCountBased(GeneralDataset<?,?> ds) { return !(ds instanceof RVFDataset); } Try / catch
try {
NaiveBayesClassifier<L,F> clf = factory.trainClassifier(dataset);
} catch (RuntimeException e) {
if (e.getMessage().contains("RVFDataset")) {
dataset = binarizeDataset((RVFDataset<L,F>) dataset);
clf = factory.trainClassifier(dataset);
} else throw e;
} Prevention
- Keep count-based data in Dataset and real-valued data in RVFDataset as separate pipeline stages
- Check dataset type before passing to any trainer
- Prefer classifiers documented to accept RVF data when your features are real-valued
When it happens
Trigger: Calling NaiveBayesClassifierFactory.trainClassifier(dataset) where dataset is an RVFDataset (created with RVFDataset API, from real-valued features, or via scaleDatum/scaleFeatures). Any pipeline that mixes RVF datums with this factory hits it immediately.
Common situations: Developers converting code from LogisticRegressionClassifier (which accepts RVF datasets) to NaiveBayes, or loading SVMLight/real-valued data and reusing the same GeneralDataset reference with a NaiveBayes trainer. Also common after reading datasets from files that produce RVFDataset by default.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- minValue for feature
- maxValue for feature
- datum
- Bad data format:
- shuffleWithSideInformation: sideInformation not of same…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/d1eb0df15ae0900f.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/classify/NaiveBayesClassifierFactory.java:348
//
// }
// System.out.println("Unconstrained conditional likelihood no prior :");
// for (int j = 0; j < 100; j++) {
// NaiveBayesClassifier<String, Integer> classifier = new NaiveBayesClassifierFactory<String, Integer>(0.1, 0.01, 0.6, LogPrior.LogPriorType.NULL.ordinal(), NaiveBayesClassifierFactory.UCL).trainClassifier(train);
// classifier.print();
// //now classify
//
// float accTrain = classifier.accuracy(train.iterator());
// log.info("training accuracy " + accTrain);
// float accTest = classifier.accuracy(test.iterator());
// log.info("test accuracy " + accTest);
// }
// }
@Override
public NaiveBayesClassifier<L, F> trainClassifier(GeneralDataset<L, F> dataset) {
if(dataset instanceof RVFDataset){
throw new RuntimeException("Not sure if RVFDataset runs correctly in this method. Please update this code if it does.");
}
return trainClassifier(dataset.getDataArray(), dataset.labels, dataset.numFeatures(),
dataset.numClasses(), dataset.labelIndex, dataset.featureIndex);
}
}
View on GitHub (pinned to 1b7edd19c4)