stanfordnlp/CoreNLP · warning
Error: Failed to load TreebankLanguagePack
Error message
Error: Failed to load TreebankLanguagePack: ${tlpCanonicalName} What it means
While reading a saved DependencyParser model file, CoreNLP instantiates the TreebankLanguagePack named in the model via reflection (ReflectionLoading.loadByReflection). If the class cannot be instantiated, the parser logs this warning and continues with config.tlp left unset (or its default), which can cause downstream failures or wrong preprocessing behavior.
Solutions
- Add the jar containing the named TreebankLanguagePack class (usually stanford-corenlp-x.x-models.jar or the language-specific model jar) to the classpath.
- Check the exact fully-qualified TLP name stored in the model file and confirm the class exists in your CoreNLP version (class names moved between versions).
- Re-train or regenerate the parser model with a TLP class available in your deployment.
- If the default TLP is acceptable, set the tlp explicitly in the parser options so behavior is deterministic instead of relying on the failed reflection load.
Example fix
// before (classpath missing the TLP class)
DependencyParser model = DependencyParser.loadModel("edu/stanford/nlp/models/parser/nndep/english_UD.gz");
// after: ensure the models jar is on the classpath, e.g.
// java -cp stanford-corenlp.jar:stanford-corenlp-models.jar:... YourMain
dependencyParserOpts("-model", "edu/stanford/nlp/models/parser/nndep/english_UD.gz",
"-tlp", "edu.stanford.nlp.trees.PennTreebankLanguagePack"); Defensive patterns
Strategy: fallback
Validate before calling
// Verify the TLP class loads before opening the model
try {
Class.forName("edu.stanford.nlp.trees.PennTreebankLanguagePack");
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Required TreebankLanguagePack missing from classpath", e);
} Prevention
- Ship the corenlp models jar matching your library version on the classpath
- After upgrading CoreNLP, grep model options for TLP class names and verify they still exist
- Set the -tlp option explicitly so failures are deterministic and diagnosable
- Keep custom TreebankLanguagePacks in a jar included in every deployment
When it happens
Trigger: loadModelFile reads a 'tlp=' line from a serialized nndep model and tries Class.forName + newInstance on that class name; any exception (class not on classpath, wrong package after refactor, no no-arg constructor, class loading error) triggers the log.warn at line 535.
Common situations: Loading a model trained with a different language pack (e.g., a Chinese/English TLP) while running with only the core jar but not the models/classpath containing that TLP class; CoreNLP version upgrades that moved or renamed TLP classes; custom TLP not shipped with the deployment.
Related errors
- not found - not applying NER tags!
- Error running
- Error leading weights from
- Error loading flags.readerAndWriter
- Error loading flags.plainTextDocumentReaderAndWriter
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/2702a491e56a99cc.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/nndep/DependencyParser.java:535
void loadModelFile(String modelFile, boolean verbose) {
Timing t = new Timing();
try (BufferedReader input = IOUtils.readerFromString(modelFile)) {
// first line in newer saved models is language, legacy models don't store this
String s = input.readLine();
// check if language was stored
if (isModelNewFormat(s)) {
// set up language
config.language = Config.getLanguage(s.substring(9, s.length() - 1));
// set up tlp
s = input.readLine();
String tlpCanonicalName = s.substring(4);
try {
config.tlp = ReflectionLoading.loadByReflection(tlpCanonicalName);
log.info("Loaded TreebankLanguagePack: " + tlpCanonicalName);
} catch (Exception e) {
log.warn("Error: Failed to load TreebankLanguagePack: " + tlpCanonicalName);
}
s = input.readLine();
}
int nDict = Integer.parseInt(s.substring(s.indexOf('=') + 1));
s = input.readLine();
int nPOS = Integer.parseInt(s.substring(s.indexOf('=') + 1));
s = input.readLine();
int nLabel = Integer.parseInt(s.substring(s.indexOf('=') + 1));
s = input.readLine();
int eSize = Integer.parseInt(s.substring(s.indexOf('=') + 1));
s = input.readLine();
int hSize = Integer.parseInt(s.substring(s.indexOf('=') + 1));
s = input.readLine();
int nTokens = Integer.parseInt(s.substring(s.indexOf('=') + 1));
s = input.readLine();
int nPreComputed = Integer.parseInt(s.substring(s.indexOf('=') + 1));
knownWords = new ArrayList<>();View on GitHub (pinned to 1b7edd19c4)