Creating a classification model using LSTM. Row data has been purified in natural language, and both x_data and y_data are ndarray types. Model.fit (X_train, y_train) errors when trying to divide train data and test data through train_split and proceed with modeling. I think it's the difference in array size, but I don't know the solution, so I'm leaving a question
X_train, X_test, y_train, y_test = train_test_split(padded_x, padded_y, test_size=0.2, random_state=42)
# padded_x, padded_y is the data that has been integerized and vectorized
print(X_train.shape) # 376, 360
print(y_train.shape) # 376, 54
word_size = len(token.word_index) + 1
# Word embedding
model = Sequential() # Layer Configuration
model.add(Embedding(word_size, 20, input_length=len(longest_sentence)))
# # len(longest_sentence)) = 360
#model.add(Flatten())
model.add(LSTM(360, activation='tanh'))
model.add(Dense(1, activation='softmax'))
model.summary()
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy',
metrics=[tf.keras.metrics.Accuracy()])
model.fit(X_train, y_train, batch_size=32, epochs=20)
ValueError: Shapes (None, 1) and (None, 54) are incompatible
I think the y_train is one-hot, and the end of the model is not one-hot.
© 2025 OneMinuteCode. All rights reserved.