我想使用 GloVe 嵌入英语句子。训练时显示错误“java.lang.RuntimeException:java.lang.UnsupportedOperationExceptionat”
手套嵌入是将英文文本编码为向量的无监督模型。Dl4j 是一个 java 库。在训练 Glove 模型时,会出现此错误。
File inputFile = new ClassPathResource("raw_sentences.txt").getFile();
// creating SentenceIterator wrapping our training corpus
SentenceIterator iter = new BasicLineIterator(inputFile.getAbsolutePath());
// Split on white spaces in the line to get words
TokenizerFactory t = new DefaultTokenizerFactory();
t.setTokenPreProcessor(new CommonPreprocessor());
Glove glove = new Glove.Builder()
.iterate(iter)
.tokenizerFactory(t)
.alpha(0.75)
.learningRate(0.1)
// number of epochs for training
.epochs(25)
// cutoff for weighting function
.xMax(100)
// training is done in batches taken from training corpus
.batchSize(1000)
// if set to true, batches will be shuffled before training
.shuffle(true)
// if set to true word pairs will be built in both directions, LTR and RTL
.symmetric(true)
.build();
log.info("Up here fine");
glove.fit(); // Getting error here
o.d.m.s.SequenceVectors - Starting learning process...
Exception in thread "VectorCalculationsThread 0" java.lang.RuntimeException: java.lang.UnsupportedOperationException
at org.deeplearning4j.models.sequencevectors.SequenceVectors$VectorCalculationsThread.run(SequenceVectors.java:1341)
Caused by: java.lang.UnsupportedOperationException
at org.deeplearning4j.models.embeddings.learning.impl.elements.GloVe.learnSequence(GloVe.java:137)
at org.deeplearning4j.models.sequencevectors.SequenceVectors.trainSequence(SequenceVectors.java:399)
at org.deeplearning4j.models.sequencevectors.SequenceVectors$VectorCalculationsThread.run(SequenceVectors.java:1274)