{"record":{"id":"16fd9e0d7b9068d3","repo":"stanfordnlp/CoreNLP","slug":"can-only-create-a-model-using-this-method-if-combi","errorCode":null,"errorMessage":"Can only create a model using this method if combineClassification and simplifiedModel are turned on","messagePattern":"Can only create a model using this method if combineClassification and simplifiedModel are turned on","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/sentiment/SentimentModel.java","lineNumber":216,"sourceCode":"\n    binaryTransform.replaceAll(x -> new SimpleMatrix(x));\n    binaryTensors.replaceAll(x -> new SimpleTensor(x));\n    binaryClassification.replaceAll(x -> new SimpleMatrix(x));\n    unaryClassification.replaceAll((x, y) -> new SimpleMatrix(y));\n    wordVectors.replaceAll((x, y) -> new SimpleMatrix(y));\n  }\n  */\n\n\n  /**\n   * Given single matrices and sets of options, create the\n   * corresponding SentimentModel.  Useful for creating a Java version\n   * of a model trained in some other manner, such as using the\n   * original Matlab code.\n   */\n  static SentimentModel modelFromMatrices(SimpleMatrix W, SimpleMatrix Wcat, SimpleTensor Wt, Map<String, SimpleMatrix> wordVectors, RNNOptions op) {\n    if (!op.combineClassification || !op.simplifiedModel) {\n      throw new IllegalArgumentException(\"Can only create a model using this method if combineClassification and simplifiedModel are turned on\");\n    }\n    TwoDimensionalMap<String, String, SimpleMatrix> binaryTransform = TwoDimensionalMap.treeMap();\n    binaryTransform.put(\"\", \"\", W);\n\n    TwoDimensionalMap<String, String, SimpleTensor> binaryTensors = TwoDimensionalMap.treeMap();\n    binaryTensors.put(\"\", \"\", Wt);\n\n    TwoDimensionalMap<String, String, SimpleMatrix> binaryClassification = TwoDimensionalMap.treeMap();\n\n    Map<String, SimpleMatrix> unaryClassification = Generics.newTreeMap();\n    unaryClassification.put(\"\", Wcat);\n\n    return new SentimentModel(binaryTransform, binaryTensors, binaryClassification, unaryClassification, wordVectors, op);\n  }\n\n  public SentimentModel(TwoDimensionalMap<String, String, SimpleMatrix> binaryTransform,\n                        TwoDimensionalMap<String, String, SimpleTensor> binaryTensors,\n                        TwoDimensionalMap<String, String, SimpleMatrix> binaryClassification,","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/sentiment/SentimentModel.java#L198-L234","documentation":"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.","triggerScenarios":"Calling SentimentModel.modelFromMatrices(W, Wcat, Wt, wordVectors, op) where the passed RNNOptions has combineClassification=false or simplifiedModel=false.","commonSituations":"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.","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"],"exampleFix":"// before\nRNNOptions op = new RNNOptions();\nop.simplifiedModel = false;\nSentimentModel model = SentimentModel.modelFromMatrices(W, Wcat, Wt, wordVectors, op);\n// after\nRNNOptions op = new RNNOptions();\nop.combineClassification = true;\nop.simplifiedModel = true;\nSentimentModel model = SentimentModel.modelFromMatrices(W, Wcat, Wt, wordVectors, op);","handlingStrategy":"validation","validationCode":"if (!op.combineClassification || !op.simplifiedModel) {\n  throw new IllegalArgumentException(\"modelFromMatrices requires combineClassification and simplifiedModel\");\n}\nSentimentModel model = SentimentModel.modelFromMatrices(W, Wcat, Wt, wordVectors, op);","typeGuard":null,"tryCatchPattern":"try {\n  model = SentimentModel.modelFromMatrices(W, Wcat, Wt, wordVectors, op);\n} catch (IllegalArgumentException e) {\n  op.combineClassification = true;\n  op.simplifiedModel = true;\n  model = SentimentModel.modelFromMatrices(W, Wcat, Wt, wordVectors, op);\n}","preventionTips":["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"],"tags":["java","stanford-nlp","sentiment","configuration"],"backgroundTag":"invalid-config-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}