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
This is my classifier, that I made using keras to do it with LSTM.
max_len=50 max_features=20000 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']) classifier.summary()
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)] classifier.fit(X_train, y_train,batch_size=100,epochs=5,callbacks=callback ,validation_data=(X_test, y_test)) ----> 2 classifier.fit(X_train, 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) 539 540 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.