I'm very new to DL and I've been trying to use a seq2seq model to classify text (sentiment analysis) from this repo. The dataset I've used is amazon review polarity (first 2000 rows).Data-set basically consists of labels and corresponding text. My model is as follows:
sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32') #MAX_SEQUENCE_LENGTH = 1000
embedded_sequences = embedding_layer(sequence_input)
l_gru = Bidirectional(GRU(100, return_sequences=True))(embedded_sequences)
l_att = AttLayer()(l_gru)
preds = Dense(2, activation='softmax')(l_att)
model = Model(sequence_input, preds)
model.compile(optimizer='rmsprop', loss='sparse_categorical_crossentropy',metrics=['accuracy'])
print("model fitting - attention GRU network")
model.summary()
model.fit(x_train, y_train, validation_data=(x_val, y_val),
epochs=5,verbose = 1, batch_size=50)
model.save('s2s.h5')
Output:
model fitting - attention GRU network
Model: "model_23"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_24 (InputLayer) (None, 1000) 0
_________________________________________________________________
embedding_11 (Embedding) (None, 1000, 100) 1276800
_________________________________________________________________
bidirectional_24 (Bidirectio (None, 1000, 200) 120600
_________________________________________________________________
att_layer_24 (AttLayer) (None, 1000, 200) 200
_________________________________________________________________
dense_23 (Dense) (None, 1000, 2) 402
=================================================================
Total params: 1,398,002
Trainable params: 1,398,002
Non-trainable params: 0
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-112-ec37b13f1d7e> in <module>()
1 model.fit(x_train, y_train, validation_data=(x_val, y_val),
----> 2 epochs=5,verbose = 1, batch_size=50)
3
4 model.save('s2s.h5')
2 frames
/usr/local/lib/python3.6/dist-packages/keras/engine/training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
129 ': expected ' + names[i] + ' to have ' +
130 str(len(shape)) + ' dimensions, but got array '
--> 131 'with shape ' + str(data_shape))
132 if not check_batch_axis:
133 data_shape = data_shape[1:]
ValueError: Error when checking target: expected dense_22 to have 3 dimensions, but got array with shape (1600, 2)
Dimension of test and validation data set:
print(x_train.shape)
print(x_val.shape)
print(y_train.shape)
print(y_val.shape)
Output:
(1600, 1000)
(400, 1000)
(1600, 2)
(400, 2)
I also referred other similar questions like: this. But couldn't find any leads.I am ready to provide more details on my implementation if these don't sufffice. Thanks in advance.