How on earth can I pass the sequences with different length to an LSTM on keras? -


i have x_train set of 744983 samples divided 24443 sequences, while number of samples in each sequence different. each sample vector of 30 dimensions. how can feed these data lstm of keras? here description of train set :

print(type(x_train)) print(np.shape(x_train)) print(type(x_train[0])) print(np.shape(x_train[0]))  <class 'list'> (24443, ) <class 'numpy.ndarray'> (46, 30) 

when set parameters in way :

model = sequential() model.add(lstm(4, input_shape = (30, ), return_sequences=true,)) model.add(dense(1)) model.compile(loss='sparse_categorical_crossentropy', optimizer='adam') model.fit(x_train, y_train, epochs=1, batch_size=1, verbose=2`) 

the error "input 0 incompatible layer lstm_24: expected ndim=3, found ndim=2"

if change input_shape (30, ) (none, 30), code runs 1 minute give error 'error when checking model input: list of numpy arrays passing model not size model expected. expected see 1 arrays instead got following list of 24443 arrays'

furthermore, if change x_train nparrays before fitting, error turns : expected lstm_26_input have 3 dimensions, got array shape (24443, 1)

i tried pad sequences :

x_train = sequence.pad_sequences(x_train) x_test = sequence.pad_sequences(x_test) 

however turned inputs '0', '1', '-1' everywhere..

#x_train = np.array(x_train) #x_test = np.array(x_test) print(x_train[0]) [[ 0  0  0 ...,  0  0  0]  [ 0  0  0 ...,  0  0  0]  [ 0  0  0 ...,  0  0  0]  ...,   [ 0  0  0 ...,  0  1 -1]  [ 0  0  0 ...,  0  1  0]  [ 0  0  0 ...,  0  0  0]] 


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -