ValueError: setting an array element with a sequence

Guys, I am making a Sentiment Analysis Classifier and now I am stuck with a problem called ValueError: setting an array element with a sequence.
The dataset is twitter dataset, as it can contain mainly un-processed tweets, so I first processed the data, by cleaning the punctuations and un-used words or not-meaningful words. Then as we need to tokenized our data to feed it into the embedding and LSTM layer, so I did it before splitting the data into train set and test set.
Size of train and test set -
(31962,) (17197,) and train[‘label’](label part) is (31962,).
This is my classifier, that I made using keras to do it with LSTM.

classifier= Sequential()
classifier.add(Embedding(max_features, 100, mask_zero=True))
classifier.add(LSTM(200, dropout=0.3, recurrent_dropout=0.3, return_sequences=False))
classifier.add(Dense(1, activation='softmax'))
classifier.compile(loss = 'sparse_categorical_crossentropy', optimizer='adam',metrics = ['accuracy'])

Now after making callback and using classifier.fir function, it should return a training loss value along with epoch count, but it is giving me an unexpected error shown below -

callback = [EarlyStopping(monitor='val_loss', patience=2),ModelCheckpoint(filepath='best_model.h5', monitor='val_loss', save_best_only=True)], y_train,batch_size=100,epochs=5,callbacks=callback ,validation_data=(X_test, y_test))

----> 2, y_train,batch_size=100,epochs=5,callbacks=callback ,validation_data=(X_test, y_test))

    537     """
--> 538     return array(a, dtype, copy=False, order=order)

ValueError: setting an array element with a sequence.

Can anyone of you help me to resolve this error, I am almost done with my project, but this is out of my knowledge. Please help and also please ask if anything is unclear. Thanks.

While we try to help with questions that use libraries and models built on top of PyTorch when people have errors that ultimately come down how they use PyTorch, and Keras is bound to be a fine library, it would seem that most people here are not using it as much.

I would suggest using Keras’ suggested support venues because ultimately there you will find people using it every day.

That said, do check out if you want a PyTorch-based library that roughly has similar intentions as Keras.

Best regards


1 Like

Sir, I am sorry that I posted in the wrong group, but sir, can you tell me or help me regarding this including in the PyTorch. Actually I am almost done in this project and this can give me the end of this project, I hope you are getting me. So, can I personally Message you here regarding this? Because, I am not getting how can I do this in PyTorch?
Still I am very much interested to do in PyTorch as I have done several projects in PyTorch.
Thanks, and any lead will be helpful to me.