I have a block of lines with some text, and for each line I want to predict the next word (word_0 -> word_1, than by word_0 and word_1 -> word_2 and so on for each line). Great tutorial and code here: Predict next word Source code
But in my way the loss doesn't decrease:
....
Epoch 42/50
2668/2668 [==============] - 1777s 666ms/step - loss: 4.6435 - acc: 0.1361
Epoch 43/50
2668/2668 [==============] - 1791s 671ms/step - loss: 4.6429 - acc: 0.1361
Epoch 44/50
2668/2668 [==============] - 1773s 665ms/step - loss: 4.6431 - acc: 0.1361
Epoch 45/50
2668/2668 [==============] - 1770s 664ms/step - loss: 4.6417 - acc: 0.1361
Epoch 46/50
2668/2668 [==============] - 1774s 665ms/step - loss: 4.6436 - acc: 0.1361
....
My LSTM NN setting:
nn_model = Sequential()
nn_model.add(Embedding(input_dim=vocab_size, output_dim=embedding_size,
weights=[pretrained_weights]))
nn_model.add(LSTM(units=embedding_size, return_sequences=True))
nn_model.add(LSTM(units=embedding_size))
nn_model.add(Dense(units=vocab_size))
nn_model.add(Activation('softmax'))
nn_model.compile(optimizer='adam', loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
where:
pretrained_weights = model.wv.syn0 (model is Word2Vec model)
vocab_size, embedding_size = pretrained_weights.shape
I tried to change batch_size (128, 64, 20, 10); tried to add any LSTM layers, but all doesn't help me. What's wrong and how can I fix this problem?