We will build a simple LSTM version of the recurrent neural network, with an embedding layer following the input layer. The embedding layer word vectors are initialized with the pretrained Glove vectors with a dimension of 100, and the layer is defined as trainable, so that the word vector embedding can update itself based on the training data. The dimension of the hidden states and the cell states is also kept as 100. The model is trained using binary cross-entropy loss. To avoid overfitting, ridge regularization is added to the loss function. The Adam optimizer is used for training the model.
The following code snippet shows the function used to build the model in TensorFlow:
def _build_model(self):
with tf.variable_scope('inputs'):
self.X = tf.placeholder(shape=[None, self.sentence_length],dtype=tf.int32,name="X"...