stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException
Unexpected matrix initialization type
Error message
Unexpected matrix initialization type ${op.trainOptions.transformMatrixType} What it means
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).
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
Example fix
// before op.trainOptions.transformMatrixType = "DIAGONAL"; // unsupported // after op.trainOptions.transformMatrixType = TrainOptions.TransformMatrixType.RANDOM;
Defensive patterns
Strategy: validation
Validate before calling
String t = op.trainOptions.transformMatrixType;
Set<String> supported = Set.of("RANDOM", "ZERO", "DIAGONAL"); // check TrainOptions for your version
if (!supported.contains(t)) {
throw new IllegalArgumentException("Unsupported transformMatrixType: " + t);
} Try / catch
try {
DVModel model = new DVModel(op, stateIndex, wordlist, dvWordVectorsFile);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("matrix initialization type")) {
op.trainOptions.transformMatrixType = "RANDOM";
}
} Prevention
- 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
When it happens
Trigger: Setting trainOptions.transformMatrixType to an unsupported value before DVModel construction, which then calls randomTransformMatrix from the unary/left/right matrix initializers during model build.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Unsupported minimizer
- Ate the whole text without matching. Expected is '" + w +…
- Cannot get max of attribute " + key + ", object of type: "…
- Cannot get min of attribute " + key + ", object of type: "…
- Cannot resolve annotation key " + annoKeyString
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/845b099088976e87.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/dvparser/DVModel.java:238
case OFF_DIAGONAL:
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);
for (int i = 0; i < numCols; ++i) {
int x = rand.nextInt(numCols);
int y = rand.nextInt(numCols);
int scale = rand.nextInt(3) - 1; // -1, 0, or 1
matrix.set(x, y, matrix.get(x, y) + scale);
}
break;
case RANDOM_ZEROS:
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);
for (int i = 0; i < numCols; ++i) {
int x = rand.nextInt(numCols);
int y = rand.nextInt(numCols);
matrix.set(x, y, 0.0);
}
break;
default:
throw new IllegalArgumentException("Unexpected matrix initialization type " + op.trainOptions.transformMatrixType);
}
return matrix;
}
public void addRandomUnaryMatrix(String childBasic) {
if (unaryTransform.get(childBasic) != null) {
return;
}
++numUnaryMatrices;
// scoring matrix
SimpleMatrix score = SimpleMatrix.random_DDRM(1, numCols, -1.0/Math.sqrt((double)numCols),1.0/Math.sqrt((double)numCols),rand);
unaryScore.put(childBasic, score.scale(op.trainOptions.scalingForInit));
SimpleMatrix transform;
if (op.trainOptions.useContextWords) {
transform = new SimpleMatrix(numRows, numCols * 3 + 1);View on GitHub (pinned to 1b7edd19c4)