[How To] Run Bidirectional LSTM in Python
This is a sample program to run bidirectional LSTM in Python using Tensorflow. The complete code repository is available at https://github.com/devharsh/LSTM-Demo . Code: #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Jun 1 13:34:00 2022. @author: devharsh """ import matplotlib.pyplot as plt from pandas import read_csv from sklearn.model_selection import train_test_split from sklearn.preprocessing import LabelEncoder from tensorflow import keras from tensorflow.keras import layers inputs = keras.Input(shape=(None,), dtype="float64") xem = layers.Embedding(101, 128)(inputs) xl1 = layers.Bidirectional(layers.LSTM(64, return_sequences=True))(xem) xl2 = layers.Bidirectional(layers.LSTM(64))(xl1) outputs = layers.Dense(1, activation="sigmoid")(xl2) model = keras.Model(inputs, outputs) model.summary()