I want to make a classification model for 3 classes, i have 2 sentences for each observation, firstly i apply a cnn layer for each sentence and then i added dense layer.
inputs = Input(shape=(2,n_timesteps))
embedding_inputs = embedding_layer(inputs)
sentence1 = Lambda(lambda x: x[:,0,:,:])(embedding_inputs)
sentence2 = Lambda(lambda x: x[:,1,:,:])(embedding_inputs)
conv_sentence1 = Conv1D(filters=64, kernel_size=3, activation='relu',
input_shape=(n_timesteps,n_features))(sentence1)
conv_sentence2 = Conv1D(filters=64, kernel_size=3, activation='relu',
input_shape=(n_timesteps,n_features))(sentence2)
pooling_sentence1 = MaxPooling1D(pool_size=2)(conv_sentence1)
pooling_sentence2 = MaxPooling1D(pool_size=2)(conv_sentence2)
flat_sentence1 = Flatten()(pooling_sentence1)
flat_sentence2 = Flatten()(pooling_sentence2)
concat_senrences = concatenate([flat_sentence1,flat_sentence2])
dense_layer = dense(50)(concat_senrences)
dense_prediction = dense(3,activation='softmax')(dense_layer)
but i get an early overfetting, so i thought that the problem comes from "sentence 2", each observation has an unique "sentence 1", ,instead, "sentence 2" can be exists in several observations, in that case the neural network relies strongly on it, so i want to combine two sentences and apply an unique CNN layer, that's why i asked how to obtain a similarity vector.
thanks !!!