Skip to content

Instantly share code, notes, and snippets.

@negedng
Last active October 18, 2020 20:47
Show Gist options
  • Save negedng/5450964ebee4681ce69f531e2df191e6 to your computer and use it in GitHub Desktop.
Save negedng/5450964ebee4681ce69f531e2df191e6 to your computer and use it in GitHub Desktop.
import numpy as np
from tensorflow import keras
from tensorflow.keras import layers
max_features = 20000 # Only consider the top 20k words
maxlen = 200 # Only consider the first 200 words of each movie review
def get_model():
# Input for variable-length sequences of integers
inputs = keras.Input(shape=(None,), dtype="int32")
# Embed each integer in a 128-dimensional vector
x = layers.Embedding(max_features, 128)(inputs)
# Add 2 bidirectional LSTMs
x = layers.Bidirectional(layers.LSTM(64, return_sequences=True))(x)
x = layers.Bidirectional(layers.LSTM(64))(x)
# Add a classifier
outputs = layers.Dense(1, activation="sigmoid")(x)
model = keras.Model(inputs, outputs)
return model
model = get_model()
model.summary()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment