{"record":{"id":"c487d04baee17b5a","repo":"stanfordnlp/CoreNLP","slug":"the-dimension-of-embedding-file-does-not-match-con","errorCode":null,"errorMessage":"The dimension of embedding file does not match config.embeddingSize (<dim> vs <config.embeddingSize>).  Perhaps set the -embeddingSize flag","messagePattern":"The dimension of embedding file does not match config\\.embeddingSize \\(<dim> vs <config\\.embeddingSize>\\)\\.  Perhaps set the -embeddingSize flag","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/nndep/DependencyParser.java","lineNumber":656,"sourceCode":"  private double[][] readEmbedFile(String embedFile, Map<String, Integer> embedID) {\n\n    double[][] embeddings = null;\n    if (embedFile != null) {\n      try (BufferedReader input = IOUtils.readerFromString(embedFile)) {\n        List<String> lines = new ArrayList<>();\n        for (String s; (s = input.readLine()) != null; ) {\n          lines.add(s);\n        }\n\n        int nWords = lines.size();\n        String[] splits = lines.get(0).split(\"\\\\s+\");\n\n        int dim = splits.length - 1;\n        embeddings = new double[nWords][dim];\n        log.info(\"Embedding File \" + embedFile + \": #Words = \" + nWords + \", dim = \" + dim);\n\n        if (dim != config.embeddingSize)\n            throw new IllegalArgumentException(\"The dimension of embedding file does not match config.embeddingSize (\" + dim + \" vs \" + config.embeddingSize + \").  Perhaps set the -embeddingSize flag\");\n\n        for (int i = 0; i < lines.size(); ++i) {\n          splits = lines.get(i).split(\"\\\\s+\");\n          embedID.put(splits[0], i);\n          for (int j = 0; j < dim; ++j)\n            embeddings[i][j] = Double.parseDouble(splits[j + 1]);\n        }\n      } catch (IOException e) {\n        throw new RuntimeIOException(e);\n      }\n      embeddings = Util.scaling(embeddings, 0, 1.0);\n    }\n    return embeddings;\n  }\n\n  /**\n   * Train a new dependency parser model.\n   *","sourceCodeStart":638,"sourceCodeEnd":674,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/nndep/DependencyParser.java#L638-L674","documentation":"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.","triggerScenarios":"Passing -embeddingFile whose vectors have a dimension different from config.embeddingSize (default 50) during training or model building.","commonSituations":"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.","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"],"exampleFix":"// before\njava -cp stanford-corenlp.jar edu.stanford.nlp.parser.nndep.DependencyParser -trainFile ... -embeddingFile w2v.txt # dim 300 vs 50\n// after\njava -cp stanford-corenlp.jar edu.stanford.nlp.parser.nndep.DependencyParser -trainFile ... -embeddingFile w2v.txt -embeddingSize 300","handlingStrategy":"validation","validationCode":"// verify embedding dim before training\nString firstLine = Files.readAllLines(Paths.get(embedFile)).get(0);\nint dim = firstLine.trim().split(\"\\\\s+\").length - 1;\nprops.setProperty(\"embeddingSize\", String.valueOf(dim));","typeGuard":null,"tryCatchPattern":"try {\n  DependencyParser.train(config);\n} catch (IllegalArgumentException e) {\n  // adjust -embeddingSize to the file's real dimension and retry\n}","preventionTips":["Always pass -embeddingSize together with -embeddingFile","Check the header/column count of your embedding file","Use the same embedding source across experiment configs"],"tags":["java","illegal-argument","nndep","embeddings"],"backgroundTag":"shape-mismatch","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}