ValueError: Shapes (None, 3) and (None, 200, 3) are incompatible
I have 3 categories for different http attack
My code here:
X_data, y_data = np.array(processed_text), np.array(attack)
X_train, X_test, y_train, y_test = train_test_split(X_data, y_data, test_size = 0.25)
y_train = to_categorical(y_train, 3)
y_test = to_categorical(y_test, 3)
Embedding_dimensions = 100
Word2vec_train_data = list(map(lambda x: x.split(), X_train))
word2vec_model = Word2Vec(Word2vec_train_data,
vector_size=Embedding_dimensions,
workers=8,
min_count=5)
input_length = 200
tokenizer = Tokenizer(filters=“”, lower=False)
tokenizer.fit_on_texts(X_train)
X_train = tokenizer.texts_to_sequences(X_train)
X_test = tokenizer.texts_to_sequences(X_test)
vocab_length = len(tokenizer.word_index) + 1
X_train = pad_sequences(X_train, padding=‘post’, maxlen=input_length)
X_test = pad_sequences(X_test, padding=‘post’, maxlen=input_length)
embedding_matrix = np.zeros((vocab_length, Embedding_dimensions))
for word, token in tokenizer.word_index.items():
if word2vec_model.wv.contains(word):
embedding_matrix[token] = word2vec_model.wv.getitem(word)
embedding_layer = Embedding(input_dim = vocab_length,
output_dim = Embedding_dimensions,
weights=[embedding_matrix],
trainable=False)
model = Sequential([
Input(shape=(input_length,)),
embedding_layer,
Bidirectional(LSTM(100, dropout=0.3, return_sequences=True)),
Bidirectional(LSTM(100, dropout=0.3, return_sequences=True)),
Attention(return_sequences=True),
Dropout(0.2),
Dense(units=3,activation=‘softmax’),
],
name=“Model”)
model.compile(loss=‘categorical_crossentropy’, optimizer=‘adam’, metrics=[‘accuracy’])
history = model.fit(
X_train, y_train,
batch_size=128,
epochs=5,
validation_split=0.1,
verbose=1,
)