stanfordnlp/CoreNLP · error · IllegalArgumentException
-labels is required
Error message
-labels is required
What it means
The label map is central to the tool, so main validates that -labels <file> was provided and throws IllegalArgumentException("-labels is required") otherwise. Without a labels file there is no text->label mapping to apply to the trees.
Solutions
- Add -labels <file> pointing to a TSV mapping of text to label
- Verify the flag spelling is -labels (plural)
- Ensure the labels file path itself is correct so a subsequent read doesn't fail
Example fix
// before // java ParseAndSetLabels -parser m.gz -sentences s.txt -output o.txt // after // java ParseAndSetLabels -parser m.gz -sentences s.txt -output o.txt -labels labels.txt
Defensive patterns
Strategy: validation
Validate before calling
java.util.List<String> a = java.util.Arrays.asList(args);
if (!a.contains("-labels")) throw new IllegalArgumentException("-labels is required");
else if (!new java.io.File(a.get(a.indexOf("-labels") + 1)).exists()) throw new IllegalArgumentException("labels file missing"); Try / catch
try {
ParseAndSetLabels.main(args);
} catch (IllegalArgumentException e) {
if ("-labels is required".equals(e.getMessage())) System.err.println("Add -labels <file> to the command line");
throw e;
} Prevention
- Always include -labels in command templates
- Verify the labels file exists before launch
- Avoid near-miss spellings like -label
When it happens
Trigger: Running ParseAndSetLabels.main without the -labels flag (or with a misspelled variant that never set labelsFile).
Common situations: Forgotten flag in scheduled jobs; labels file argument dropped during script refactoring; typo such as -label instead of -labels that hits the unknown-argument branch instead.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Error: No dest file provided in properties or via command…
- Error: No training file provided in properties or via…
- Error: No training file provided in properties or via…
- Error: -train option must have treebankPath as first…
- Must specify input with -input
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/5cc93b26ef9cf5d2.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java:249
} else if (args[argIndex].equalsIgnoreCase("-nouseLabelKeys")) {
useLabelKeys = false;
argIndex += 1;
} else {
throw new IllegalArgumentException("Unknown argument " + args[argIndex]);
}
}
if (outputFile == null) {
throw new IllegalArgumentException("-output is required");
}
if (sentencesFile == null && !useLabelKeys) {
throw new IllegalArgumentException("-sentences or -useLabelKeys is required");
}
if (sentencesFile != null && useLabelKeys) {
throw new IllegalArgumentException("Use only one of -sentences or -useLabelKeys");
}
if (labelsFile == null) {
throw new IllegalArgumentException("-labels is required");
}
ParserGrammar parser = loadParser(parserFile, taggerFile);
TreeBinarizer binarizer = null;
if (binarize) {
binarizer = TreeBinarizer.simpleTreeBinarizer(parser.getTLPParams().headFinder(), parser.treebankLanguagePack());
}
Map<String, String> labelMap = readLabelMap(labelsFile, separator, remapLabels);
List<String> sentences;
if (sentencesFile != null) {
sentences = readSentences(sentencesFile);
} else {
sentences = new ArrayList<String>(labelMap.keySet());
}
View on GitHub (pinned to 1b7edd19c4)