Skip to content

Instantly share code, notes, and snippets.

@AyishaR
Created February 19, 2021 07:14
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 AyishaR/6fc15e4de4d221f508f3c44a0c580dd2 to your computer and use it in GitHub Desktop.
Save AyishaR/6fc15e4de4d221f508f3c44a0c580dd2 to your computer and use it in GitHub Desktop.
# Build and train neural network
embedding_dim = 128
model = models.Sequential([
layers.Embedding(vocab, embedding_dim, input_length = mlen),
layers.LSTM(128, activation='tanh'),
layers.Dense(32, activation = 'relu'),
layers.Dense(16, activation = 'relu'),
layers.Dense(1, activation = 'sigmoid')
])
cb = [callbacks.EarlyStopping(patience = 5, restore_best_weights = True)]
model.compile(optimizer = optimizers.Adam(0.01), loss = losses.BinaryCrossentropy(), metrics = ['accuracy'])
history = model.fit(Xtrain, ytrain, batch_size=64, epochs = 256, validation_data=(Xval, yval), callbacks = cb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment