{"record":{"id":"845b099088976e87","repo":"stanfordnlp/CoreNLP","slug":"unexpected-matrix-initialization-type-op-trainop","errorCode":null,"errorMessage":"Unexpected matrix initialization type ${op.trainOptions.transformMatrixType}","messagePattern":"Unexpected matrix initialization type (.+?)","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/dvparser/DVModel.java","lineNumber":238,"sourceCode":"    case OFF_DIAGONAL:\n      matrix = SimpleMatrix.random_DDRM(numRows,numCols,-1.0/Math.sqrt((double)numCols * 100.0),1.0/Math.sqrt((double)numCols * 100.0),rand).plus(identity);\n      for (int i = 0; i < numCols; ++i) {\n        int x = rand.nextInt(numCols);\n        int y = rand.nextInt(numCols);\n        int scale = rand.nextInt(3) - 1;  // -1, 0, or 1\n        matrix.set(x, y, matrix.get(x, y) + scale);\n      }\n      break;\n    case RANDOM_ZEROS:\n      matrix = SimpleMatrix.random_DDRM(numRows,numCols,-1.0/Math.sqrt((double)numCols * 100.0),1.0/Math.sqrt((double)numCols * 100.0),rand).plus(identity);\n      for (int i = 0; i < numCols; ++i) {\n        int x = rand.nextInt(numCols);\n        int y = rand.nextInt(numCols);\n        matrix.set(x, y, 0.0);\n      }\n      break;\n    default:\n      throw new IllegalArgumentException(\"Unexpected matrix initialization type \" + op.trainOptions.transformMatrixType);\n    }\n    return matrix;\n  }\n\n  public void addRandomUnaryMatrix(String childBasic) {\n    if (unaryTransform.get(childBasic) != null) {\n      return;\n    }\n\n    ++numUnaryMatrices;\n\n    // scoring matrix\n    SimpleMatrix score = SimpleMatrix.random_DDRM(1, numCols, -1.0/Math.sqrt((double)numCols),1.0/Math.sqrt((double)numCols),rand);\n    unaryScore.put(childBasic, score.scale(op.trainOptions.scalingForInit));\n\n    SimpleMatrix transform;\n    if (op.trainOptions.useContextWords) {\n      transform = new SimpleMatrix(numRows, numCols * 3 + 1);","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/dvparser/DVModel.java#L220-L256","documentation":"DVModel.randomTransformMatrix uses a switch over op.trainOptions.transformMatrixType to build random transform matrices; the default branch throws IllegalArgumentException for any unrecognized type. This indicates the TrainingOptions field was set to a value outside the supported enum/constants (e.g. via options file or programmatic misuse).","triggerScenarios":"Setting trainOptions.transformMatrixType to an unsupported value before DVModel construction, which then calls randomTransformMatrix from the unary/left/right matrix initializers during model build.","commonSituations":"Hand-editing parser options files with an invalid matrix type name; copy-pasting option values between CoreNLP versions where the constant set differs; typos in -transformMatrixType style flags.","solutions":["Set transformMatrixType to a supported value (e.g. RANDOM ||Diagonal||) in trainOptions","Remove the custom override and use the default transform matrix initialization","Check the CoreNLP version's TrainOptions for the valid constants and correct the config"],"exampleFix":"// before\nop.trainOptions.transformMatrixType = \"DIAGONAL\"; // unsupported\n// after\nop.trainOptions.transformMatrixType = TrainOptions.TransformMatrixType.RANDOM;","handlingStrategy":"validation","validationCode":"String t = op.trainOptions.transformMatrixType;\nSet<String> supported = Set.of(\"RANDOM\", \"ZERO\", \"DIAGONAL\"); // check TrainOptions for your version\nif (!supported.contains(t)) {\n    throw new IllegalArgumentException(\"Unsupported transformMatrixType: \" + t);\n}","typeGuard":null,"tryCatchPattern":"try {\n    DVModel model = new DVModel(op, stateIndex, wordlist, dvWordVectorsFile);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"matrix initialization type\")) {\n        op.trainOptions.transformMatrixType = \"RANDOM\";\n    }\n}","preventionTips":["Only set transformMatrixType to constants defined in TrainOptions","Don't hand-edit options files with invented type names","Pin CoreNLP version so option names stay consistent"],"tags":["invalid-value","model-training","stanford-corenlp"],"backgroundTag":"invalid-enum-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}