<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <a href="https
Step1:  IMDB Movie Review 
Step2:  Step 2 
Step3:  Step 3 
Step4:  Step 4 
<ASSISTANT_TASK:>
Python Code:
import tensorflow as tf
import numpy as np
import tensorflow_hub as hub
import tensorflow_datasets as ds
## general checks
print("Tensor Flow Version : {}".format(tf.__version__))
print("Eager Mode : {}".format(tf.executing_eagerly()))
print("Hub Version : {}".format(hub.__version__))
print("GPU availablility : {}".format(True if tf.config.experimental.list_physical_devices("GPU") else False))
Explanation: <a href="https://colab.research.google.com/github/rishuatgithub/MLPy/blob/master/Perceptrons_Basic_Understanding.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
End of explanation
## check if the dataset holds the imdb dataset or not
"imdb_reviews" in ds.list_builders()
## Load the dataset
if "imdb_reviews" in ds.list_builders():
  imdb_ds = ds.load("imdb_reviews")
for key,value in imdb_ds.items():
  print(key, value)
### Using TF DS to split the training data into 60:40 validation dataset.
if "imdb_reviews" in ds.list_builders():
  train_data, validation_data, test_data = ds.load(name="imdb_reviews",split=('train[:60]','train[60:]','test'),as_supervised=True)
type(train_data)
## Explore the data set
train_examples_batch, train_labels_batch = next(iter(train_data.batch(10)))
train_examples_batch
train_labels_batch
Explanation: IMDB Movie Review : Text Classification
Step 1: Download the dataset of IMDB review from TF Dataset library
End of explanation
## Embedding the word from TF Hub pre-build BoW
embedding = "https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1"
hub_layer = hub.KerasLayer(embedding,trainable=True,input_shape=[],dtype=tf.string)
hub_layer(train_examples_batch[:3])
### Define the layers
model = tf.keras.Sequential(name='IMDBSEQModel')
model.add(hub_layer)
model.add(tf.keras.layers.Dense(16, activation='relu'))
model.add(tf.keras.layers.Dense(1))
model.summary()
### Define the Loss Function and optimizer
model.compile(optimizer='adam',loss=tf.keras.losses.BinaryCrossentropy(from_logits=True), metrics=['accuracy'])
Explanation: Step 2 : Building the Model Layers
End of explanation
history = model.fit(train_data.shuffle(10000).batch(512), epochs=20, validation_data=validation_data.batch(512), verbose=1)
Explanation: Step 3 : Train the Model
End of explanation
results = model.evaluate(test_data.batch(512),verbose=2)
for name, value in zip(model.metrics_names, results):
  print("{} {}".format(name,value))
Explanation: Step 4 : Evaluate the Model
End of explanation
<END_TASK>