A BiLSTM model
The first model we will try is a BiLSTM model. First, the basic constants need to be set up:
# Length of the vocabulary
vocab_size = len(text_vocab) + 1
# The embedding dimension
embedding_dim = 64
# Number of RNN units
rnn_units = 100
#batch size
BATCH_SIZE=90
# num of NER classes
num_classes = len(ner_vocab)+1
Next, a convenience function for instantiating models is defined:
from tensorflow.keras.layers import Embedding, Bidirectional, LSTM, TimeDistributed, Dense
dropout=0.2
def build_model_bilstm(vocab_size, embedding_dim, rnn_units, batch_size, classes):
model = tf.keras.Sequential([
Embedding(vocab_size, embedding_dim, mask_zero=True,
batch_input_shape=[batch_size,
None]),
Bidirectional(LSTM(units=rnn_units,
return_sequences=True,
dropout=dropout,
kernel_initializer=\
tf.keras.initializers.he_normal...