Last active
October 18, 2020 20:47
-
-
Save negedng/5450964ebee4681ce69f531e2df191e6 to your computer and use it in GitHub Desktop.
Model from the Keras tutorial: https://keras.io/examples/nlp/bidirectional_lstm_imdb/
This file contains hidden or 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
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