I'm implementing an LSTM with Keras to predict the correct words order. My dataset is composed by sentences, each sentences is composed by a variable number of words and each word is composed by the same number of features. Now, I would to compute loss function after every sentence parsed, but I need to have dynamic timesteps for each sentence. One solution might be use the fit_generator(), but in the generator I need to know which sentence is to return the correct number of timesteps. Another solution might be use pad_sequences() to a fixed number, but when I want to predict the right label for a word, I have to return to the original sentence length without pad. (for example, If I pad a sentence from 6 words to 20 words, when I predict, the hidden state will be a list of 20 numbers, but I want one number for each original word, so 6 numbers).

Any suggestions? Thanks in advance.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.