Skip to content

Instantly share code, notes, and snippets.

@funktor
Created November 6, 2018 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funktor/258880ba3fbbb40e53fadb58a0773921 to your computer and use it in GitHub Desktop.
Save funktor/258880ba3fbbb40e53fadb58a0773921 to your computer and use it in GitHub Desktop.
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