UKPLab / elmo-bilstm-cnn-crf

BiLSTM-CNN-CRF architecture for sequence tagging using ELMo representations.
Apache License 2.0
388 stars 81 forks source link

Error When running Script: ValueError: input_shape` or `batch_input_shape` argument. #20

Open Rusiecki opened 5 years ago

Rusiecki commented 5 years ago

Hey I was trying to run your script and ran into a problem.

:: Lookup of 1000 ELMo representations. This takes a while :: 100%[==================================================] 1000/ 1000 sentences

:: Lookup of 1000 ELMo representations. This takes a while :: 100%[==================================================] 1000/ 1000 sentencesShape Train X: (1000, 100, 256) Shape Test Y: (1000, 100, 256) Traceback (most recent call last): File "/Users/banana/PycharmProjects/MasterArbeit/MasterArbeit/ELMo.py", line 178, in model.add(Conv1D(filters=250, kernel_size=3, padding='same')) #input_shape=(1000, 100, 1024))) File "/usr/local/lib/python3.7/site-packages/keras/models.py", line 451, in add raise ValueError('The first layer in a ' ValueError: The first layer in a Sequential model must get an input_shape or batch_input_shape argument.

What I've tried

# Simple model for sentence / document classification using CNN + global max pooling
model = Sequential()
model.add(Conv1D(filters=250, kernel_size=3, padding='same', input_shape=(1000, 100, 1024)))
model.add(GlobalMaxPooling1D())
model.add(Dense(250, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(train_x, train_y, validation_data=(test_x, test_y), epochs=1, batch_size=32)

But it than trows me a different error. What is the needed Input_shape?

Best Regards

nreimers commented 5 years ago

Not sure why you get this error, your first layer Conv1D specified an input_shape.

However, your error log shows that model.add(Conv1D(filters=250, kernel_size=3, padding='same')) you did not specify the input_shape there.