1

When I run the following code, the following error interrupts training process.

ValueError: No data provided for "embedding_15_input". Need data for each key in: ['embedding_15_input']

I would like to mention that I want to construct a lstm network with multi_lable output ( 11 labels ).

Here is the function to generate the model structure:

def lstm_twiter(n_input, n_out, input_dim,units_activation = 'tanh', batch_size =20 ):

 model = Sequential()
 embedding_size_out = min(50, input_dim/2)
 model.add(Embedding( input_length = n_input, output_dim = embedding_size_out\
                     , input_dim = input_dim, mask_zero = True))
 model.add(Bidirectional(LSTM(100,activation=units_activation)))
 model.add(Dropout(0.5))
 model.add(Dense(n_out,activation="sigmoid"))
 callsback = EarlyStopping(patience =2 )
 dict_1={'callbacks':[callsback],'batch_size':batch_size}
 model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])

 return(model, dict_1)

Here is how I call it:

matrix_input_train, matrix_output_train, matrix_input_dev,\
        matrix_output_dev, matrix_input_test, matrix_output_test,size_of_vocab= \
                                                    preprocessing (txt_file_train, txt_file_dv) 

n_input =  matrix_input_train.shape[1] 
input_dim = size_of_vocab 
n_out =  matrix_output_train.shape[1]
model, dict_1=lstm_twiter(n_input, n_out, input_dim,units_activation = 'tanh'\
                      , batch_size =20  )
dict_1.update(x=matrix_input_train,y=matrix_output_train,epochs=10, \
          validation_data=(matrix_input_dev, matrix_output_dev))
model.fit(dict_1)

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
embedding_17 (Embedding)     (None, 56, 50)            1103150   
_________________________________________________________________
bidirectional_15 (Bidirectio (None, 200)               120800    
_________________________________________________________________
dropout_15 (Dropout)         (None, 200)               0         
_________________________________________________________________
dense_14 (Dense)             (None, 11)                2211      
=================================================================
Total params: 1,226,161
Trainable params: 1,226,161
Non-trainable params: 0
______________________________________________________
desertnaut
  • 57,590
  • 26
  • 140
  • 166

1 Answers1

1

I encountered this error on 3 cases (However in R and not in Python):

  1. The input data does not have the same dimension as was declared in the first layer
  2. The input data included missing values
  3. The input data is not a matrix (for example, a data frame)

Please check that all of the above.

Maybe this code in R can help:

library(keras)

#The network should identify the rule that a row sum greater than 1.5 should yield an output of 1

my_x=matrix(data=runif(30000), nrow=10000, ncol=3)
my_y=ifelse(rowSums(my_x)>1.5,1,0)
my_y=to_categorical(my_y, 2)

model = keras_model_sequential()
layer_dense(model,units = 2000, activation = "relu", input_shape = c(3))
layer_dropout(model,rate = 0.4)
layer_dense(model,units = 50, activation = "relu")
layer_dropout(model,rate = 0.3)
layer_dense(model,units = 2, activation = "softmax")

compile(model,loss = "categorical_crossentropy",optimizer = optimizer_rmsprop(),metrics = c("accuracy"))

history <- fit(model,  my_x, my_y, epochs = 5, batch_size = 128, validation_split = 0.2)

evaluate(model,my_x, my_y,verbose = 0)

predict_classes(model,my_x)
Roee Anuar
  • 3,071
  • 1
  • 19
  • 33
  • 1
    Thanks for the remark... The data input format is crucial to get Keras running. In my case I missed out on making Xtrain a matrix (it actually was a dataframe). So `as.matrix(Xtrain)` solved the problem. – Peter Oct 31 '18 at 13:21