I am implementing a simple LSTM network. I would like to include multiple features at the input layer. These features are a pre-trained word embeddings and a vector to flag a specific word in the given sentence.
For example:
Sentence = "I have a question"
feature_vector_1 = [4, 2, 281, 5201] #word2index which will be passed to the embedding layer
feature_vector_2 = [0, 1, 0, 0]
final features= [feature_vector_1 + feature_vector_2]
suppose that:
embedding is of dim = 100
index_flag is of dim = 50
max sentence length = 50
My network code is:
input= Input(shape=(None,))
embedded_layer_input=Embedding(input_dim=embedding_matrix.shape[0], output_dim=embedding_matrix.shape[1],
input_length=tweet_max_length, weights= [embedding_matrix], trainable=False)(input)
lstm_layer=Bidirectional(LSTM(64))(embedded_layer_input)
output_layer=Dense(1,activation='sigmoid')(lstm_layer)
model=Model(input, output_layer)
#complie and train
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['acc'])
# Summarize the model
print(model.summary())
# Fit the model
model.fit(padded_train_x, y_train, epochs=epochs, batch_size=batch_size, shuffle=False, verbose=1, validation_data=(padded_dev_x,y_dev))
My question is how and where to include the new feature vector? I looked at Concatenate but I am not sure how to prepare feature vector 2.