stanfordnlp/CoreNLP · error · IllegalArgumentException

Illegal beam size

Error message

Illegal beam size ${beamSize}

What it means

PerceptronModel.trainTree validates that beam-based training methods (BEAM or REORDER_BEAM) receive a positive beamSize. A zero or negative beam size makes the PriorityQueue agenda useless (it could never retain candidates), so the model throws IllegalArgumentException before training starts.

Solutions

  1. Set the training option beamSize to a positive integer (e.g. -trainingMethod BEAM -beamSize 8 or the equivalent in your options file)
  2. If you don't want beam training, switch trainingMethod to a non-beam method (e.g. EARLY_TERMINATION) so beamSize isn't required
  3. Check the serialized training options embedded in any model/config you reused for stale beamSize=0 values

Example fix

// before
opts.trainOptions().trainingMethod = TrainingMethod.BEAM;
opts.trainOptions().beamSize = 0;

// after
opts.trainOptions().trainingMethod = TrainingMethod.BEAM;
opts.trainOptions().beamSize = 8;
Defensive patterns

Strategy: validation

Validate before calling

ShiftReduceTrainOptions to = op.trainOptions();
if ((to.trainingMethod == TrainingMethod.BEAM || to.trainingMethod == TrainingMethod.REORDER_BEAM) && to.beamSize <= 0) {
  throw new IllegalArgumentException("beamSize must be > 0 for beam training");
}

Try / catch

try {
  model.trainTreebank(...);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Illegal beam size")) {
    op.trainOptions().beamSize = 8;
    model.trainTreebank(...);
  } else throw e;
}

Prevention

When it happens

Trigger: Training with trainingMethod set to BEAM or REORDER_BEAM while trainOptions.beamSize is <= 0 (unset, explicitly 0, or negative).

Common situations: A config file that sets trainingMethod=BEAM but omits beamSize (defaulting to 0); a script passing beamSize=0 expecting 'auto'; copy-pasted training options where beamSize was zeroed out.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/a98edfeb79a5e2f6. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/shiftreduce/PerceptronModel.java:293

    List<TrainingUpdate> updates = Generics.newArrayList();
    Pair<Integer, Integer> firstError = null;

    IntCounter<Class<? extends Transition>> correctTransitions = new IntCounter<>();
    TwoDimensionalIntCounter<Class<? extends Transition>, Class<? extends Transition>> wrongTransitions = new TwoDimensionalIntCounter<>();

    ReorderingOracle reorderer = null;
    if (op.trainOptions().trainingMethod == ShiftReduceTrainOptions.TrainingMethod.REORDER_ORACLE ||
        op.trainOptions().trainingMethod == ShiftReduceTrainOptions.TrainingMethod.REORDER_BEAM) {
      reorderer = new ReorderingOracle(op, rootOnlyStates);
    }

    int reorderSuccess = 0;
    int reorderFail = 0;

    if (op.trainOptions().trainingMethod == ShiftReduceTrainOptions.TrainingMethod.BEAM ||
        op.trainOptions().trainingMethod == ShiftReduceTrainOptions.TrainingMethod.REORDER_BEAM) {
      if (op.trainOptions().beamSize <= 0) {
        throw new IllegalArgumentException("Illegal beam size " + op.trainOptions().beamSize);
      }
      PriorityQueue<State> agenda = new PriorityQueue<>(op.trainOptions().beamSize + 1, ScoredComparator.ASCENDING_COMPARATOR);
      State goldState = example.initialStateFromGoldTagTree();
      List<Transition> transitions = example.trainTransitions();
      agenda.add(goldState);

      while (transitions.size() > 0) {
        Transition goldTransition = transitions.get(0);
        Transition highestScoringTransitionFromGoldState = null;
        double highestScoreFromGoldState = 0.0;
        PriorityQueue<State> newAgenda = new PriorityQueue<>(op.trainOptions().beamSize + 1, ScoredComparator.ASCENDING_COMPARATOR);
        State highestScoringState = null;
        // keep track of the state in the current agenda which leads
        // to the highest score on the next agenda.  this will be
        // trained down assuming it is not the correct state
        State highestCurrentState = null;
        for (State currentState : agenda) {
          // TODO: can maybe speed this part up, although it doesn't seem like a critical part of the runtime

View on GitHub (pinned to 1b7edd19c4)