-
-
Save funktor/258880ba3fbbb40e53fadb58a0773921 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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