Last active
September 30, 2022 10:25
-
-
Save nikkisharma536/90e1bd96f3669ca6e95e06c7345db0be 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
from keras.models import Model, Input | |
from keras.layers import LSTM, Embedding, Dense, TimeDistributed, Dropout, Bidirectional | |
import keras as k | |
from keras_contrib.layers import CRF | |
input = Input(shape=(672,)) | |
word_embedding_size = 150 | |
# Embedding Layer | |
model = Embedding(input_dim=n_words, output_dim=word_embedding_size, input_length=672)(input) | |
# BI-LSTM Layer | |
model = Bidirectional(LSTM(units=word_embedding_size, | |
return_sequences=True, | |
dropout=0.5, | |
recurrent_dropout=0.5, | |
kernel_initializer=k.initializers.he_normal()))(model) | |
model = LSTM(units=word_embedding_size * 2, | |
return_sequences=True, | |
dropout=0.5, | |
recurrent_dropout=0.5, | |
kernel_initializer=k.initializers.he_normal())(model) | |
# TimeDistributed Layer | |
model = TimeDistributed(Dense(n_tags, activation="relu"))(model) | |
# CRF Layer | |
crf = CRF(n_tags) | |
out = crf(model) # output | |
model = Model(input, out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment