{"record":{"id":"68a14e3219ded253","repo":"stanfordnlp/CoreNLP","slug":"need-to-either-train-a-new-model-run-the-gradient","errorCode":null,"errorMessage":"Need to either train a new model, run the gradient check or specify a model to load with -model","messagePattern":"Need to either train a new model, run the gradient check or specify a model to load with -model","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/dvparser/DVParser.java","lineNumber":555,"sourceCode":"      } else if (args[argIndex].equalsIgnoreCase(\"-continueTraining\")) {\n        runTraining = true;\n        filter = false;\n        initialModelPath = args[argIndex + 1];\n        argIndex += 2;\n      } else if (args[argIndex].equalsIgnoreCase(\"-resultsRecord\")) {\n        resultsRecordPath = args[argIndex + 1];\n        argIndex += 2;\n      } else {\n        unusedArgs.add(args[argIndex++]);\n      }\n    }\n\n    if (parserPath == null && modelPath == null) {\n      throw new IllegalArgumentException(\"Must supply either a base parser model with -parser or a serialized DVParser with -model\");\n    }\n\n    if (!runTraining && modelPath == null && !runGradientCheck) {\n      throw new IllegalArgumentException(\"Need to either train a new model, run the gradient check or specify a model to load with -model\");\n    }\n\n    String[] newArgs = unusedArgs.toArray(new String[unusedArgs.size()]);\n    DVParser dvparser = null;\n    LexicalizedParser lexparser = null;\n    if (initialModelPath != null) {\n      lexparser = LexicalizedParser.loadModel(initialModelPath, newArgs);\n      DVModel model = getModelFromLexicalizedParser(lexparser);\n      dvparser = new DVParser(model, lexparser);\n    } else if (runTraining || runGradientCheck) {\n      lexparser = LexicalizedParser.loadModel(parserPath, newArgs);\n      dvparser = new DVParser(lexparser);\n    } else if (modelPath != null) {\n      lexparser = LexicalizedParser.loadModel(modelPath, newArgs);\n      DVModel model = getModelFromLexicalizedParser(lexparser);\n      dvparser = new DVParser(model, lexparser);\n    }\n","sourceCodeStart":537,"sourceCodeEnd":573,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/dvparser/DVParser.java#L537-L573","documentation":"After validating a model source exists, DVParser.main() checks what work it should do: train a new model, run a gradient check, or load a serialized model. If runTraining is false, no -model is given, and runGradientCheck is false, there is nothing to do, so it throws. It prevents a silent no-op run.","triggerScenarios":"Running DVParser.main() without -trainingThreads... specifically without flags that set runTraining or runGradientCheck to true, and without -model, e.g. only passing -parser plus unused args.","commonSituations":"Supplying -parser alone expecting the parser to just parse text (DVParser's main is for training/checking, not parsing); typo-ing -trainingInput... misspelling a mode flag so it lands in unusedArgs and no mode is activated.","solutions":["Add -model <path> to load and use an existing serialized DVParser","Add the training flag (e.g. -trainTreebank with training data) to enable runTraining","Add -gradientCheck (with the required -parser model) if you intend to run the gradient check"],"exampleFix":"// before\njava edu.stanford.nlp.parser.dvparser.DVParser -parser englishPCFG.ser.gz\n// after\njava edu.stanford.nlp.parser.dvparser.DVParser -parser englishPCFG.ser.gz -model dvmodel.ser.gz","handlingStrategy":"validation","validationCode":"boolean hasMode = runTraining || runGradientCheck || modelPath != null;\nif (!hasMode) {\n  throw new IllegalArgumentException(\"Set a mode: train (-trainTreebank), -gradientCheck, or -model\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  DVParser.main(args);\n} catch (IllegalArgumentException e) {\n  System.err.println(\"No operation requested: \" + e.getMessage());\n}","preventionTips":["Decide the run mode (train/gradient-check/load) before invoking DVParser.main","Remember -parser alone only supplies the base model, not an operation","Check the DVParser documentation for mode flags when scripting"],"tags":["java","cli","missing-argument","dvparser"],"backgroundTag":"missing-required-argument","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"}