stanfordnlp/CoreNLP · error · IllegalArgumentException
The dimension of embedding file does not match…
Error message
The dimension of embedding file does not match config.embeddingSize (<dim> vs <config.embeddingSize>). Perhaps set the -embeddingSize flag
What it means
When loading pre-trained word embeddings, DependencyParser.readEmbedFile compares the vector dimension parsed from the embedding file (number of whitespace-separated columns minus one) with config.embeddingSize. A mismatch means the neural model dimensions won't line up, so IllegalArgumentException is thrown, advising to set the -embeddingSize flag.
Solutions
- Add -embeddingSize <dim> matching your embedding file's dimension (e.g. 100, 300)
- Regenerate or download embeddings with the dimension the config expects
- Count the columns in the first line of the embedding file to confirm the true dim before rerunning
Example fix
// before java -cp stanford-corenlp.jar edu.stanford.nlp.parser.nndep.DependencyParser -trainFile ... -embeddingFile w2v.txt # dim 300 vs 50 // after java -cp stanford-corenlp.jar edu.stanford.nlp.parser.nndep.DependencyParser -trainFile ... -embeddingFile w2v.txt -embeddingSize 300
Defensive patterns
Strategy: validation
Validate before calling
// verify embedding dim before training
String firstLine = Files.readAllLines(Paths.get(embedFile)).get(0);
int dim = firstLine.trim().split("\\s+").length - 1;
props.setProperty("embeddingSize", String.valueOf(dim)); Try / catch
try {
DependencyParser.train(config);
} catch (IllegalArgumentException e) {
// adjust -embeddingSize to the file's real dimension and retry
} Prevention
- Always pass -embeddingSize together with -embeddingFile
- Check the header/column count of your embedding file
- Use the same embedding source across experiment configs
When it happens
Trigger: Passing -embeddingFile whose vectors have a dimension different from config.embeddingSize (default 50) during training or model building.
Common situations: Using word2vec/GloVe/fastText files trained with 100/300 dimensions while the parser config still has embeddingSize=50; reusing an old config with new embeddings; forgetting to pass -embeddingSize alongside -embeddingFile.
Related errors
- Language does not support parsing!
- Parser requires words with part-of-speech tag annotations
- Unknown language <props.containsKey("language")>
- Cannot put a child trie with no keys
- CoreMap must have either a Calendar or DocDate annotation
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/c487d04baee17b5a.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/nndep/DependencyParser.java:656
private double[][] readEmbedFile(String embedFile, Map<String, Integer> embedID) {
double[][] embeddings = null;
if (embedFile != null) {
try (BufferedReader input = IOUtils.readerFromString(embedFile)) {
List<String> lines = new ArrayList<>();
for (String s; (s = input.readLine()) != null; ) {
lines.add(s);
}
int nWords = lines.size();
String[] splits = lines.get(0).split("\\s+");
int dim = splits.length - 1;
embeddings = new double[nWords][dim];
log.info("Embedding File " + embedFile + ": #Words = " + nWords + ", dim = " + dim);
if (dim != config.embeddingSize)
throw new IllegalArgumentException("The dimension of embedding file does not match config.embeddingSize (" + dim + " vs " + config.embeddingSize + "). Perhaps set the -embeddingSize flag");
for (int i = 0; i < lines.size(); ++i) {
splits = lines.get(i).split("\\s+");
embedID.put(splits[0], i);
for (int j = 0; j < dim; ++j)
embeddings[i][j] = Double.parseDouble(splits[j + 1]);
}
} catch (IOException e) {
throw new RuntimeIOException(e);
}
embeddings = Util.scaling(embeddings, 0, 1.0);
}
return embeddings;
}
/**
* Train a new dependency parser model.
*View on GitHub (pinned to 1b7edd19c4)