I have built an RNN model for entity recognition. I used BERT embedding and then processed the results through a RNN Model. However, while training the model for 5 epochs, each epoch seems to take about 2 hours. Also, the validation loss does not seem to decrease at all.
I am running the process on a RTX 2080 GPU. I have tried manipulating the model but does not improve the model. The dataset I have is of about 400000 sentences.
This is my model:
def build_model(max_seq_length, n_tags):
in_id = Input(shape=(max_seq_length,), name="input_ids")
in_mask = Input(shape=(max_seq_length,), name="input_masks")
in_segment = Input(shape=(max_seq_length,), name="segment_ids")
bert_inputs = [in_id, in_mask, in_segment]
bert_output = BertLayer(n_fine_tune_layers=3, pooling="first")(bert_inputs)
x = RepeatVector(max_seq_length)(bert_output)
x = Bidirectional(LSTM(units=lstm_units, return_sequences=True,
recurrent_dropout=0.2, dropout=0.2))(x)
x_rnn = Bidirectional(LSTM(units=lstm_units, return_sequences=True,
recurrent_dropout=0.2, dropout=0.2))(x)
x = add([x, x_rnn]) # residual connection to the first biLSTM
pred = TimeDistributed(Dense(n_tags, activation="softmax"))(x)
model = Model(inputs=bert_inputs, outputs=pred)
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.summary()
return model
This is the model summary:
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_ids (InputLayer) (None, 30) 0
__________________________________________________________________________________________________
input_masks (InputLayer) (None, 30) 0
__________________________________________________________________________________________________
segment_ids (InputLayer) (None, 30) 0
__________________________________________________________________________________________________
bert_layer_3 (BertLayer) ((None, 30), 768) 110104890 input_ids[0][0]
input_masks[0][0]
segment_ids[0][0]
__________________________________________________________________________________________________
repeat_vector_2 (RepeatVector) ((None, 30), 30, 768 0 bert_layer_3[0][0]
__________________________________________________________________________________________________
bidirectional_2 (Bidirectional) ((None, 30), 30, 200 695200 repeat_vector_2[0][0]
__________________________________________________________________________________________________
bidirectional_3 (Bidirectional) ((None, 30), 30, 200 240800 bidirectional_2[0][0]
__________________________________________________________________________________________________
add_1 (Add) ((None, 30), 30, 200 0 bidirectional_2[0][0]
bidirectional_3[0][0]
__________________________________________________________________________________________________
time_distributed_1 (TimeDistrib ((None, 30), 30, 3) 603 add_1[0][0]
==================================================================================================
Total params: 111,041,493
Trainable params: 22,790,811
Non-trainable params: 88,250,682
__________________________________________________________________________________________________
Logs:
32336/445607 [=>............................] - ETA: 2:12:59 - loss: 0.3469 - acc: 0.9068
32352/445607 [=>............................] - ETA: 2:12:58 - loss: 0.3469 - acc: 0.9068
32368/445607 [=>............................] - ETA: 2:12:58 - loss: 0.3469 - acc: 0.9068
Can you help me find out where I am going wrong?