stanfordnlp/CoreNLP · error · IllegalArgumentException
Can only create a model using this method if…
Error message
Can only create a model using this method if combineClassification and simplifiedModel are turned on
What it means
SentimentModel.modelFromMatrices builds a model assuming the simplified single binary-transform/tensor layout keyed by "", "". The library throws this IllegalArgumentException because if RNNOptions.combineClassification or RNNOptions.simplifiedModel is off, the model would need per-label-category matrices that this factory method cannot derive from the given W/Wcat/Wt.
Solutions
- Set combineClassification=true and simplifiedModel=true on the RNNOptions before calling modelFromMatrices
- If you need non-simplified options, construct the SentimentModel via a constructor that reads real trees/options instead of modelFromMatrices
Example fix
// before RNNOptions op = new RNNOptions(); op.simplifiedModel = false; SentimentModel model = SentimentModel.modelFromMatrices(W, Wcat, Wt, wordVectors, op); // after RNNOptions op = new RNNOptions(); op.combineClassification = true; op.simplifiedModel = true; SentimentModel model = SentimentModel.modelFromMatrices(W, Wcat, Wt, wordVectors, op);
Defensive patterns
Strategy: validation
Validate before calling
if (!op.combineClassification || !op.simplifiedModel) {
throw new IllegalArgumentException("modelFromMatrices requires combineClassification and simplifiedModel");
}
SentimentModel model = SentimentModel.modelFromMatrices(W, Wcat, Wt, wordVectors, op); Try / catch
try {
model = SentimentModel.modelFromMatrices(W, Wcat, Wt, wordVectors, op);
} catch (IllegalArgumentException e) {
op.combineClassification = true;
op.simplifiedModel = true;
model = SentimentModel.modelFromMatrices(W, Wcat, Wt, wordVectors, op);
} Prevention
- Always build RNNOptions for modelFromMatrices with both flags explicitly set to true
- Centralize option construction in one factory so flags are never forgotten
- Never reuse options objects configured for full-grammar training with this method
When it happens
Trigger: Calling SentimentModel.modelFromMatrices(W, Wcat, Wt, wordVectors, op) where the passed RNNOptions has combineClassification=false or simplifiedModel=false.
Common situations: Converting a model trained with the original Matlab code into a Java SentimentModel while reusing options configured for full (non-simplified) training; copying op from a serialized/props-based pipeline that disabled simplifiedModel.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Cannot create random word vectors for an unknown numHid
- Not a valid ellipses style
- Not a valid dashes style
- SpanishLexer: Invalid option value in constructor
- Not yet implemented
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/16fd9e0d7b9068d3.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/sentiment/SentimentModel.java:216
binaryTransform.replaceAll(x -> new SimpleMatrix(x));
binaryTensors.replaceAll(x -> new SimpleTensor(x));
binaryClassification.replaceAll(x -> new SimpleMatrix(x));
unaryClassification.replaceAll((x, y) -> new SimpleMatrix(y));
wordVectors.replaceAll((x, y) -> new SimpleMatrix(y));
}
*/
/**
* Given single matrices and sets of options, create the
* corresponding SentimentModel. Useful for creating a Java version
* of a model trained in some other manner, such as using the
* original Matlab code.
*/
static SentimentModel modelFromMatrices(SimpleMatrix W, SimpleMatrix Wcat, SimpleTensor Wt, Map<String, SimpleMatrix> wordVectors, RNNOptions op) {
if (!op.combineClassification || !op.simplifiedModel) {
throw new IllegalArgumentException("Can only create a model using this method if combineClassification and simplifiedModel are turned on");
}
TwoDimensionalMap<String, String, SimpleMatrix> binaryTransform = TwoDimensionalMap.treeMap();
binaryTransform.put("", "", W);
TwoDimensionalMap<String, String, SimpleTensor> binaryTensors = TwoDimensionalMap.treeMap();
binaryTensors.put("", "", Wt);
TwoDimensionalMap<String, String, SimpleMatrix> binaryClassification = TwoDimensionalMap.treeMap();
Map<String, SimpleMatrix> unaryClassification = Generics.newTreeMap();
unaryClassification.put("", Wcat);
return new SentimentModel(binaryTransform, binaryTensors, binaryClassification, unaryClassification, wordVectors, op);
}
public SentimentModel(TwoDimensionalMap<String, String, SimpleMatrix> binaryTransform,
TwoDimensionalMap<String, String, SimpleTensor> binaryTensors,
TwoDimensionalMap<String, String, SimpleMatrix> binaryClassification,View on GitHub (pinned to 1b7edd19c4)