Skip to content

Instantly share code, notes, and snippets.

@aravindpai
Last active March 12, 2020 10:54
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 aravindpai/c7546863492ec90e9b7506ea51749732 to your computer and use it in GitHub Desktop.
Save aravindpai/c7546863492ec90e9b7506ea51749732 to your computer and use it in GitHub Desktop.
#deep learning library
from keras.models import *
from keras.layers import *
from keras.callbacks import *
model=Sequential()
#embedding layer
model.add(Embedding(size_of_vocabulary,300,input_length=100,trainable=True))
#lstm layer
model.add(LSTM(128,return_sequences=True,dropout=0.2))
#Global Maxpooling
model.add(GlobalMaxPooling1D())
#Dense Layer
model.add(Dense(64,activation='relu'))
model.add(Dense(1,activation='sigmoid'))
#Add loss function, metrics, optimizer
model.compile(optimizer='adam', loss='binary_crossentropy',metrics=["acc"])
#Adding callbacks
es = EarlyStopping(monitor='val_loss', mode='min', verbose=1,patience=3)
mc=ModelCheckpoint('best_model.h5', monitor='val_acc', mode='max', save_best_only=True,verbose=1)
#Print summary of model
print(model.summary())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment