UKPLab / elmo-bilstm-cnn-crf

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

Input 0 of layer bidirectional_14 is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: (None, 120, 1024, 1024)` #51

Open fivin opened 3 years ago

fivin commented 3 years ago

I use this tutorial Keras_ELMo_Tutorial.ipynb to make named entity recognition task. Here are the details of data train and data test : Shape X_train: (3555, 120, 1024) Shape X_test: (887, 120, 1024) Shape y_train: (3555,) Shape y_test: (887,)

This is the model :

input = Input(shape=(120,))
word_embedding_size = 1024
model = Embedding(input_dim=n_words, output_dim=word_embedding_size, input_length=120)(input)
model = Bidirectional(LSTM(units=word_embedding_size, 
                           return_sequences=True, 
                           dropout=0.5, 
                           recurrent_dropout=0.5, 
                           kernel_initializer=k.initializers.he_normal()))(model)
model = LSTM(units=word_embedding_size * 2, 
             return_sequences=True, 
             dropout=0.5, 
             recurrent_dropout=0.5, 
             kernel_initializer=k.initializers.he_normal())(model)
model = TimeDistributed(Dense(n_tags, activation="relu"))(model)  # previously softmax output layer

crf = CRF(n_tags)  # CRF layer
out = crf(model)  # output
model = Model(input, out)

adam = k.optimizers.Adam(lr=0.0005, beta_1=0.9, beta_2=0.999)
model.compile(optimizer=adam, loss=crf.loss_function, metrics=[crf.accuracy, 'accuracy'])

model.summary()

model.fit(X_train , y_train, validation_data=(X_test, y_test), epochs=10, batch_size=32)

But i got the error like this : ValueError: Input 0 of layer bidirectional_14 is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: (None, 120, 1024, 1024)

Please help me out to solve this error