Skip to content

Instantly share code, notes, and snippets.

@funktor funktor/ Secret
Created Nov 6, 2018

What would you like to do?
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
You can’t perform that action at this time.