我面临以下问题。我想建立一个 LSTM 模型来进行情绪分析。在 C++ 中,我使用 mlpack 库。首先,为了理解架构,我通过 python 和 Keras 从一些教程中建议了这个问题。本教程有以下代码:
from keras.models import Sequential
from keras.layers import Dense, Embedding, LSTM, GRU
from keras.layers.embeddings import Embedding
EMBEDDING_DIM = 100
print('Build model...')
model = Sequential()
model.add(Embedding(vocab_size, EMBEDDING_DIM, input_length=max_length())
model.add(GRU(units=32, dropout=0.2, recurrent_dropout=0.2))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
在我的代码中,在 C++ 中,我编写了这个块:
model.Add<IdentityLayer<> >();
model.Add<Embedding<> >(vocabSize, embedSize);
model.Add<LSTM<> >(inputSize, lstmCells, maxRho);
model.Add<Dropout<> >(0.5);
model.Add<ReLULayer<> >();
model.Add<Linear<> >(lstmCells, outputSize);
输出控制台给了我这个错误:
error: conv_to(): given object can't be interpreted as a vector
terminate called after throwing an instance of 'std::logic_error'
what(): conv_to(): given object can't be interpreted as a vector
经过几个小时的调试,我无法理解错误在哪里......谢谢