{"record":{"id":"23b769964647e0df","repo":"stanfordnlp/CoreNLP","slug":"qnminimizer-terminated-without-converging","errorCode":null,"errorMessage":"QNMinimizer terminated without converging","messagePattern":"QNMinimizer terminated without converging","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/optimization/QNMinimizer.java","lineNumber":1125,"sourceCode":"    case TERMINATE_RELATIVENORM:\n      if (!quiet) log.info(\"QNMinimizer terminated due to sufficient decrease in gradient norms: |g|/|g0| < TOL \");\n      success = true;\n      break;\n    case TERMINATE_AVERAGEIMPROVE:\n      if (!quiet) log.info(\"QNMinimizer terminated due to average improvement: | newest_val - previous_val | / |newestVal| < TOL \");\n      success = true;\n      break;\n    case TERMINATE_MAXITR:\n      if (!quiet) log.info(\"QNMinimizer terminated due to reached max iteration \" + maxItr);\n      success = true;\n      break;\n    case TERMINATE_EVALIMPROVE:\n      if (!quiet) log.info(\"QNMinimizer terminated due to no improvement on eval \");\n      success = true;\n      x = rec.getBest();\n      break;\n    default:\n      log.warn(\"QNMinimizer terminated without converging\");\n      success = false;\n      break;\n    }\n\n    double completionTime = rec.howLong();\n    if (!quiet) log.info(\"Total time spent in optimization: \" + nfsec.format(completionTime) + 's');\n\n    if (outputToFile) {\n      infoFile.println(completionTime + \"; Total Time \");\n      infoFile.println(fevals + \"; Total evaluations\");\n      infoFile.close();\n      outFile.close();\n    }\n\n    qn.free();\n    return x;\n\n  } // end minimize()","sourceCodeStart":1107,"sourceCodeEnd":1143,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/optimization/QNMinimizer.java#L1107-L1143","documentation":"QNMinimizer (Stanford CoreNLP's L-BFGS quasi-Newton optimizer) finished its main loop through a 'default' branch of the termination-state switch, meaning it stopped for a reason other than achieving evaluation improvement or a normal convergence criterion. The optimizer marks the run as not successful and logs this warning. It indicates the optimization did not reach a proper minimum within its configured limits.","triggerScenarios":"minimize() ran until an unhandled TerminationCondition state was reached, typically hitting maxIterations/maxTime without the convergence tests firing, or an objective function producing NaN/Inf evaluations that prevented the normal TERMINATE_EvalImprovement path from being taken.","commonSituations":"Training a CoreNLP model (e.g., classifier or parser) with too few iterations, a badly scaled or noisy objective, learning data with degenerate features, or a DiffFunction that returns NaN for bad parameter values.","solutions":["Increase the maximum number of iterations (useMaxIterations/useSummedObj etc. options passed to the trainer) so the optimizer has room to converge.","Inspect training data for degenerate/duplicate features or extreme values that break numerical stability of the objective.","Verify the objective (DiffFunction) never returns NaN or Infinity; fix the function or filter bad examples.","Loosen the convergence tolerance (e.g., QNMinimizer's TOL / useEvalImprovement settings) if near-convergence is acceptable.","Treat the returned weights with caution: since success=false, consider re-training with different initialization or regularization."],"exampleFix":"// before\nQNMinimizer minimizer = new QNMinimizer(15);\ndouble[] result = minimizer.minimize(f, 100, initial, options); // may stop at 100 iters without converging\n\n// after\nQNMinimizer minimizer = new QNMinimizer(15);\nminimizer.useMaxIterations();\ndouble[] result = minimizer.minimize(f, 10000, initial, options); // more iterations to converge","handlingStrategy":"validation","validationCode":"// Check the objective produces finite values at the initial point before minimizing\nif (!Arrays.stream(f.domain().sampleNeighborhood(initial)).allMatch(v -> Double.isFinite(f.valueAt(v)))) {\n  throw new IllegalStateException(\"Objective returns non-finite values; fix data/features before training\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sanity-check training data for NaN/extreme feature values before fitting","Budget enough iterations for the dataset size and dimensionality","Scale/normalize features so the Hessian approximation stays well-conditioned","Check minimizer.success() / wasSuccessful after minimize() and re-run with different settings if false"],"tags":["nlp","optimization","numerical-stability","training"],"backgroundTag":"optimizer-did-not-converge","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"}