0

我成功地从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);
    }
}
4

1 回答 1

0

当前版本 (0.4-rc3.10) 在 loadTxt 函数中有一个错误。它已在主存储库中修复,并将反映在下一个版本中。阅读此 github 问题以解决您的问题: https ://github.com/deeplearning4j/deeplearning4j/issues/1721

目前一个简单的解决方法是将最新的 WordVectorSerializer.java 复制到您的项目中。 https://github.com/deeplearning4j/deeplearning4j/blob/master/deeplearning4j-scaleout/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/embeddings/loader/WordVectorSerializer.java

于 2016-06-29T01:32:55.460 回答