stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException
Vector of incorrect size passed to applyInitialHessian in…
Error message
Vector of incorrect size passed to applyInitialHessian in QNInfo class
What it means
QNMinimizer.QNInfo.applyInitialHessian scales the input vector element-wise by the stored diagonal d. If the passed vector's length differs from d.length, the element-wise division is impossible, so it throws this IllegalArgumentException. If d is null, the vector is returned unscaled (no error).
Solutions
- Pass an x vector whose length matches the QNInfo's stored d (same model dimension)
- Create a fresh QNInfo/QNMinimizer for the new problem dimension instead of reusing one
- Clear/reset the stored history (set d null or construct a new QNInfo) when the dimension changes
Example fix
// before qnInfo.applyInitialHessian(new double[100]); // qnInfo built for dim 50 // after double[] x = new double[50]; qnInfo.applyInitialHessian(x); // match stored dimension
Defensive patterns
Strategy: validation
Validate before calling
if (x.length != expectedDim) throw new IllegalArgumentException("x.length=" + x.length + " but QNInfo dimension=" + expectedDim); Try / catch
try { qnInfo.applyInitialHessian(x); } catch (IllegalArgumentException e) { if (e.getMessage().contains("incorrect size passed to applyInitialHessian")) { qnInfo = new QNMinimizer.QNInfo(x.length); qnInfo.applyInitialHessian(x); } else throw e; } Prevention
- Never reuse QNInfo/QNMinimizer instances across problems of different dimension
- Assert vector lengths equal the model dimension before optimizer calls
- Reset optimizer state whenever the model size changes
When it happens
Trigger: Calling applyInitialHessian (directly or through the QNMinimizer pipeline) with a state vector x whose dimension differs from the dimension of the previously stored Hessian diagonal/surrogate history d.
Common situations: Reusing a QNInfo object across problems of different dimensionality; changing model size between optimization runs while reusing the same minimizer/QNInfo; passing a gradient subset instead of the full vector.
Understand the failure class
Background: Tensor shape mismatch errors ("must have shape", "expected shape ... got ..."): when tensor dimensions disagree with what an op or layer was told to expect — this error's family across 6 libraries.
Related errors
- Word vectors file has dimension too small for requested…
- NO SAMPLING METHOD SELECTED
- Attempt to use ExternalFiniteDifference without passing…
- Doesn't support floats yet
- LogPrior.valueAt is undefined for prior of type
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/8004855438d826e3.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/optimization/QNMinimizer.java:724
return used;
}
} // end class ScalarQNInfo
class DiagonalQNInfo extends QNInfo {
DiagonalQNInfo(int size) {
super(size);
}
DiagonalQNInfo(List<double[]> sList, List<double[]> yList) {
super(sList, yList);
}
double[] applyInitialHessian(double[] x, StringBuilder sb) {
sb.append('D');
if(d != null) {
// Check sizes
if(x.length != d.length)
throw new IllegalArgumentException("Vector of incorrect size passed to applyInitialHessian in QNInfo class");
// Scale element-wise
for(int i = 0; i < x.length; i++)
x[i] /= d[i];
}
return x;
}
int update(double[] newS, double[] newY, double yy, double sy, double sg, double step) {
if(sy < 0) {
// NOTE: if applying QNMinimizer to a non convex problem, we would still
// like to update the matrix
// or we could get stuck in a series of skipped updates.
if(!quiet)
log.info(" Negative curvature detected, update skipped ");
return used;
}
if(yy == 0.0) {
if(!quiet)View on GitHub (pinned to 1b7edd19c4)