Skip to content

Instantly share code, notes, and snippets.

@aravindpai

aravindpai/10_3.py

Last active Mar 12, 2020
Embed
What would you like to do?
#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
You can’t perform that action at this time.