stanfordnlp/CoreNLP · error · java.lang.UnsupportedOperationException
No maximum number of iterations has been specified.
Error message
No maximum number of iterations has been specified.
What it means
StochasticMinimizer.minimize() throws this UnsupportedOperationException when both maxIterations and numPasses are non-positive, meaning no stopping criterion was configured. Stochastic optimizers in this library are pass/iteration-driven and refuse to start without a bound.
Solutions
- Call setMaxIterations(n) with n > 0 before minimize()
- Or call setNumPasses(n) to run n full passes over the data
- Verify your options file/flag parsing sets the iteration fields
Example fix
// before StochasticMinimizer m = new SGD(); m.minimize(f, 1e-4, initial); // after StochasticMinimizer m = new SGD(); m.setNumPasses(10); m.minimize(f, 1e-4, initial);
Defensive patterns
Strategy: validation
Validate before calling
StochasticMinimizer m = new SGD(); if (m.maxIterations <= 0 && m.numPasses <= 0) m.setNumPasses(10);
Try / catch
try { m.minimize(f, 1e-4, initial); } catch (UnsupportedOperationException e) { m.setNumPasses(10); m.minimize(f, 1e-4, initial); } Prevention
- Set numPasses for any StochasticMinimizer subclass before training
- Validate optimizer settings in a config object before handing them to the optimizer
- Never rely on defaults for stopping criteria in stochastic training
When it happens
Trigger: Subclassing or directly using StochasticMinimizer (e.g. SGD, InefficientStochasticMinimizer) and invoking minimize() without setMaxIterations(n) or setNumPasses(n).
Common situations: Building a trainer programmatically and forgetting the iteration setter; a refactored config pipeline dropping the iterations option; assuming the base class supplies a default.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- No maximum number of iterations has been specified.
- Attempt to use ExternalFiniteDifference without passing…
- Doesn't support floats yet
- Gradient is numerically zero, stopped on machine epsilon.
- LogPrior.valueAt is undefined for prior of type
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/f0226828ddcfd4c8.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/optimization/StochasticMinimizer.java:390
ArrayMath.add(initial, gen.nextDouble() ); // to make sure that priors are working.
sdft.testSumOfBatches(initial, 1e-4);
System.exit(1);
--- */
x = initial;
grad = new double[x.length];
newX = new double[x.length];
gradList = new ArrayList<>();
numBatches = dfunction.dataDimension()/ bSize;
outputFrequency = (int) Math.ceil( ((double) numBatches) /( (double) outputFrequency) ) ;
init(dfunction);
initFiles();
boolean have_max = (maxIterations > 0 || numPasses > 0);
if (!have_max){
throw new UnsupportedOperationException("No maximum number of iterations has been specified.");
}else{
maxIterations = Math.max(maxIterations, numPasses)*numBatches;
}
sayln(" Batchsize of: " + bSize);
sayln(" Data dimension of: " + dfunction.dataDimension() );
sayln(" Batches per pass through data: " + numBatches );
sayln(" Max iterations is = " + maxIterations);
if (outputIterationsToFile) {
infoFile.println(function.domainDimension() + "; DomainDimension " );
infoFile.println(bSize + "; batchSize ");
infoFile.println(maxIterations + "; maxIterations");
infoFile.println(numBatches + "; numBatches ");
infoFile.println(outputFrequency + "; outputFrequency");
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!View on GitHub (pinned to 1b7edd19c4)