{"record":{"id":"a98edfeb79a5e2f6","repo":"stanfordnlp/CoreNLP","slug":"illegal-beam-size-beamsize","errorCode":null,"errorMessage":"Illegal beam size ${beamSize}","messagePattern":"Illegal beam size (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/shiftreduce/PerceptronModel.java","lineNumber":293,"sourceCode":"    List<TrainingUpdate> updates = Generics.newArrayList();\n    Pair<Integer, Integer> firstError = null;\n\n    IntCounter<Class<? extends Transition>> correctTransitions = new IntCounter<>();\n    TwoDimensionalIntCounter<Class<? extends Transition>, Class<? extends Transition>> wrongTransitions = new TwoDimensionalIntCounter<>();\n\n    ReorderingOracle reorderer = null;\n    if (op.trainOptions().trainingMethod == ShiftReduceTrainOptions.TrainingMethod.REORDER_ORACLE ||\n        op.trainOptions().trainingMethod == ShiftReduceTrainOptions.TrainingMethod.REORDER_BEAM) {\n      reorderer = new ReorderingOracle(op, rootOnlyStates);\n    }\n\n    int reorderSuccess = 0;\n    int reorderFail = 0;\n\n    if (op.trainOptions().trainingMethod == ShiftReduceTrainOptions.TrainingMethod.BEAM ||\n        op.trainOptions().trainingMethod == ShiftReduceTrainOptions.TrainingMethod.REORDER_BEAM) {\n      if (op.trainOptions().beamSize <= 0) {\n        throw new IllegalArgumentException(\"Illegal beam size \" + op.trainOptions().beamSize);\n      }\n      PriorityQueue<State> agenda = new PriorityQueue<>(op.trainOptions().beamSize + 1, ScoredComparator.ASCENDING_COMPARATOR);\n      State goldState = example.initialStateFromGoldTagTree();\n      List<Transition> transitions = example.trainTransitions();\n      agenda.add(goldState);\n\n      while (transitions.size() > 0) {\n        Transition goldTransition = transitions.get(0);\n        Transition highestScoringTransitionFromGoldState = null;\n        double highestScoreFromGoldState = 0.0;\n        PriorityQueue<State> newAgenda = new PriorityQueue<>(op.trainOptions().beamSize + 1, ScoredComparator.ASCENDING_COMPARATOR);\n        State highestScoringState = null;\n        // keep track of the state in the current agenda which leads\n        // to the highest score on the next agenda.  this will be\n        // trained down assuming it is not the correct state\n        State highestCurrentState = null;\n        for (State currentState : agenda) {\n          // TODO: can maybe speed this part up, although it doesn't seem like a critical part of the runtime","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/shiftreduce/PerceptronModel.java#L275-L311","documentation":"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.","triggerScenarios":"Training with trainingMethod set to BEAM or REORDER_BEAM while trainOptions.beamSize is <= 0 (unset, explicitly 0, or negative).","commonSituations":"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.","solutions":["Set the training option beamSize to a positive integer (e.g. -trainingMethod BEAM -beamSize 8 or the equivalent in your options file)","If you don't want beam training, switch trainingMethod to a non-beam method (e.g. EARLY_TERMINATION) so beamSize isn't required","Check the serialized training options embedded in any model/config you reused for stale beamSize=0 values"],"exampleFix":"// before\nopts.trainOptions().trainingMethod = TrainingMethod.BEAM;\nopts.trainOptions().beamSize = 0;\n\n// after\nopts.trainOptions().trainingMethod = TrainingMethod.BEAM;\nopts.trainOptions().beamSize = 8;","handlingStrategy":"validation","validationCode":"ShiftReduceTrainOptions to = op.trainOptions();\nif ((to.trainingMethod == TrainingMethod.BEAM || to.trainingMethod == TrainingMethod.REORDER_BEAM) && to.beamSize <= 0) {\n  throw new IllegalArgumentException(\"beamSize must be > 0 for beam training\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  model.trainTreebank(...);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Illegal beam size\")) {\n    op.trainOptions().beamSize = 8;\n    model.trainTreebank(...);\n  } else throw e;\n}","preventionTips":["Validate training options once at config load time","Always set beamSize explicitly when selecting BEAM methods","Audit serialized option files for beamSize=0"],"tags":["parser","training","beam-search","configuration"],"backgroundTag":"invalid-config-value","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"}