我成功地从http://deeplearning4j.org/word2vec训练了 word2vec 模型 ,现在在尝试应用 wordsNearest 时出现此异常:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 99
at
org.deeplearning4j.models.embeddings.loader.WordVectorSerializer.loadTxt(WordVectorSerializer.java:1107)
at
org.deeplearning4j.models.embeddings.loader.WordVectorSerializer.loadTxtVectors(WordVectorSerializer.java:1033)
at
org.deeplearning4j.examples.nlp.word2vec.NearestWords.main(NearestWords.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
这是我的代码:
package org.deeplearning4j.examples.nlp.word2vec;
import java.io.File;
import java.util.Collection;
import org.deeplearning4j.models.embeddings.loader.WordVectorSerializer;
import org.deeplearning4j.models.embeddings.wordvectors.WordVectors;
public class NearestWords {
public static void main(String[] args) throws Exception{
File file = new File("pathToWriteto.txt");
WordVectors vec = WordVectorSerializer.loadTxtVectors(file);
Collection<String> similar = vec.wordsNearest("day", 10);
System.out.println(similar);
}
}