stanfordnlp/CoreNLP · error · IllegalArgumentException

Unknown argument

Error message

Unknown argument 

What it means

SentimentTraining's main() parses its own args first (e.g. -train, -test, -filterUnknown) and then delegates the rest to Options.setOption. If that call consumes no arguments, the current token is unrecognized and an IllegalArgumentException naming the token is thrown.

Solutions

  1. Remove or correct the unrecognized argument in the command line.
  2. Check the tool's usage: only training flags (-train, -test, -dev, -model, -filterUnknown, etc.) plus Options-settable flags are accepted.
  3. Verify against the CoreNLP version in use — option names change between releases.
  4. Prefix generic Options flags correctly (many need a prefix, e.g. -trainTrees vs plain flags).

Example fix

// before
java edu.stanford.nlp.sentiment.SentimentTraining -train train.txt -dev dev.txt -model model.ser.gz -threads 4 -unknownFlag
// after
java edu.stanford.nlp.sentiment.SentimentTraining -train train.txt -dev dev.txt -model model.ser.gz -trainTrees -threads 4
Defensive patterns

Strategy: validation

Validate before calling

// whitelist known flags before invoking the trainer
Set<String> known = Set.of("-train","-test","-dev","-model","-filterUnknown","-trainTrees","-threads");
for (String a : args) if (a.startsWith("-") && !known.contains(a)) throw new IllegalArgumentException("unknown flag: " + a);

Prevention

When it happens

Trigger: Passing a flag that neither SentimentTraining's arg loop nor the training Options object recognizes, e.g. a typo like -traiFile, or an option belonging to a different tool (such as pipeline flags) at SentimentTraining.java:177.

Common situations: Copy-pasting command lines between Stanford NLP tools (SentimentPipeline and SentimentTraining accept different flags), typos, or removed/renamed training options across CoreNLP versions.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/sentiment/SentimentTraining.java:177

      } else if (args[argIndex].equalsIgnoreCase("-gradientcheck")) {
        runGradientCheck = true;
        argIndex++;
      } else if (args[argIndex].equalsIgnoreCase("-trainpath")) {
        trainPath = args[argIndex + 1];
        argIndex += 2;
      } else if (args[argIndex].equalsIgnoreCase("-devpath")) {
        devPath = args[argIndex + 1];
        argIndex += 2;
      } else if (args[argIndex].equalsIgnoreCase("-model")) {
        modelPath = args[argIndex + 1];
        argIndex += 2;
      } else if (args[argIndex].equalsIgnoreCase("-filterUnknown")) {
        filterUnknown = true;
        argIndex++;
      } else {
        int newArgIndex = op.setOption(args, argIndex);
        if (newArgIndex == argIndex) {
          throw new IllegalArgumentException("Unknown argument " + args[argIndex]);
        }
        argIndex = newArgIndex;
      }
    }

    // read in the trees
    List<Tree> trainingTrees = SentimentUtils.readTreesWithGoldLabels(trainPath);
    log.info("Read in " + trainingTrees.size() + " training trees");
    if (filterUnknown) {
      trainingTrees = SentimentUtils.filterUnknownRoots(trainingTrees);
      log.info("Filtered training trees: " + trainingTrees.size());
    }

    List<Tree> devTrees = null;
    if (devPath != null) {
      devTrees = SentimentUtils.readTreesWithGoldLabels(devPath);
      log.info("Read in " + devTrees.size() + " dev trees");
      if (filterUnknown) {

View on GitHub (pinned to 1b7edd19c4)