stanfordnlp/CoreNLP · error · IllegalArgumentException

Unknown argument " + args[argIndex]

Error message

Unknown argument " + args[argIndex]

What it means

IllegalArgumentException from ReadSentimentDataset.main when an unrecognized command-line flag is encountered; only the documented options (input directory, output directory, numClasses, splits, etc.) are accepted.

Solutions

  1. Check accepted flags in ReadSentimentDataset.java main and correct the command line
  2. Remove or correct the unknown token in your script
  3. Match exact casing; flags are compared with equalsIgnoreCase so spelling, not case, is the issue

Example fix

// before
-readSentimentDataset -dictionary dict.txt -unknownFlag x
// after
-readSentimentDataset -dictionary dict.txt -sentimentLabels labels.txt
Defensive patterns

Strategy: validation

Validate before calling

Set<String> known = Set.of("-dictionary","-sentimentLabels","-trainPath","-devPath","-testPath","-model","-numClasses");
for (String a : args) if (a.startsWith("-") && !known.contains(a.toLowerCase())) throw new IllegalArgumentException("Unknown argument " + a);

Try / catch

try { ReadSentimentDataset.main(args); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Unknown argument")) { printUsage(); } else throw e; }

Prevention

When it happens

Trigger: Running ReadSentimentDataset with a misspelled flag (e.g. '-sentamentLabels'), an unsupported option, or leftover positional garbage in the command line.

Common situations: Outdated documentation or scripts referencing flags that were renamed/removed, copy-paste errors in training scripts.

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/91900a07549a239c. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/sentiment/ReadSentimentDataset.java:447

        if (numClasses == 2) {
          trainFilename = args[argIndex + 1] + "/train-binary.txt";
          devFilename = args[argIndex + 1] + "/dev-binary.txt";
          testFilename = args[argIndex + 1] + "/test-binary.txt";
        } else if (numClasses == 3) {
          trainFilename = args[argIndex + 1] + "/train-3class.txt";
          devFilename = args[argIndex + 1] + "/dev-3class.txt";
          testFilename = args[argIndex + 1] + "/test-3class.txt";
        } else {
          trainFilename = args[argIndex + 1] + "/train.txt";
          devFilename = args[argIndex + 1] + "/dev.txt";
          testFilename = args[argIndex + 1] + "/test.txt";
        }
        argIndex += 2;
      } else if (args[argIndex].equalsIgnoreCase("-numClasses")) {
        // already been processed
        argIndex += 2;
      } else {
        throw new IllegalArgumentException("Unknown argument " + args[argIndex]);
      }
    }

    // Sentence file is formatted
    //   w1|w2|w3...
    List<List<String>> sentences = Generics.newArrayList();
    for (String line : IOUtils.readLines(tokensFilename, "utf-8")) {
      String[] sentence = line.split("\\|");
      sentences.add(Arrays.asList(sentence));
    }

    // Split and read the phrase ids file.  This file is in the format
    //   w1 w2 w3 ... | id
    Map<List<String>, Integer> phraseIds = Generics.newHashMap();
    for (String line : IOUtils.readLines(dictionaryFilename, "utf-8")) {
      String[] pieces = line.split("\\|");
      String[] sentence = pieces[0].split(" ");
      Integer id = Integer.valueOf(pieces[1]);

View on GitHub (pinned to 1b7edd19c4)