Instantly share code, notes, and snippets.

@funktor /bilstm_crf.py Secret
Created Nov 6, 2018

Embed
What would you like to do?
class BiLSTM_CRF(BiLSTM):
def __init__(self, vocab_size, max_words, num_tags, embedding_size, model_file_path):
super(BiLSTM_CRF, self).__init__(vocab_size, max_words, num_tags, embedding_size, model_file_path)
def build_model(self):
print "Building model..."
input = Input(shape=(self.max_words,))
embed = Embedding(input_dim=self.vocab_size + 1, output_dim=self.embedding_size, input_length=self.max_words, mask_zero=True)(input)
bilstm = Bidirectional(LSTM(units=50, return_sequences=True, recurrent_dropout=0.1))(embed)
dense = TimeDistributed(Dense(50, activation="relu"))(bilstm)
crf = CRF(self.num_tags)
out = crf(dense)
self.model = Model(input, out)
self.model.compile(optimizer="adam", loss=crf.loss_function, metrics=[crf.accuracy])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment