-:ARTIFICIAL INTELLIGENCE
APPLICATIONS:-
CASE STUDY-
Binary Classification of Sequential Data Using Recurrent Neural
Networks (RNNs)
RNN-Text-Classification
DONE BY:
M Jyothi Swaroop VU21CSEN0500069
RVS. Aditya VU21CSEN0500132
N. Varun Reddy VU21CSEN0500008
Prattyush VU21CSEN0500022
Rawat
Text Classification with an RNN
The pipeline WE follow is the usual when using Keras and TF:
Setup of Libraries.
Download/ Access Raw Data.
Create a Text Encoder. This step allows the convert of sentences of words
into vector representations using tokenization. Some text preprocessing is
also required in this step.
Optimize the text dataset. Some cool features from TF are used to improve
memory and optimization.
Model. Sometimes this step will be directly from the TF 2.0 API, or simply
using a Sequential model from Keras. A key thing to notice is mandatory.
Since we are working with representations of vectors, it is necessary to create
embeddings. Embeddings are typically dense encodings of words. Ideally,
similar words have similar encodings.
Assemble the model. Depending on the task, this step might get tougher. For
now, We will only use standard compiling parameters.
Train the model.
Some inference regarding predicted data or model structure.
Setup Libraries:
! pip install -q tensorflow_datasets
import numpy as np
import tensorflow_datasets as tfds
import tensorflow as tf
tfds.disable_progress_bar()
import [Link] as plt
def plot_graphs(history, metric):
[Link]([Link][metric])
[Link]([Link]['val_'+metric], '')
[Link]("Epochs")
[Link](metric)
[Link]([metric, 'val_'+metric])
Collecting Data:
Downloading and preparing dataset imdb_reviews/plain_text/1.0.0 (download: 80.23 MiB, generated:
Unknown size, total: 80.23 MiB) to /root/tensorflow_datasets/imdb_reviews/plain_text/1.0.0...
Sample Data:
Dataset:
BUFFER_SIZE = 10000
BATCH_SIZE = 64
train_dataset =
train_dataset.shuffle(BUFFER_SIZE).batch(BATCH_SIZE).prefetch([Link]
[Link])
test_dataset =
test_dataset.shuffle(BUFFER_SIZE).batch(BATCH_SIZE).prefetch([Link]
[Link])
Vectorized Data:
Text Encoding Process:
Example of the first 100 words in the Vocabulary available:
Create a Model
We will use a very simple model consisting of five layers arranged in a sequential
flow.
The Text Vectorization and Embedding layers have already been described. In the Bidirectional
layer, we employ an RNN. An RNN lets us pass the input in both the forward and backward
direction, so that gives us two outputs that we concatenate at the end of this block. Those
outputs are the next input to a dense layer, followed by a final classifier.
Conclusion:
We achieve high enough validation accuracy, especially considering the size of the
vocabulary and the number of epochs that we have been allowed to train. It is noteworthy
that the model captures quite nicely the deep hidden patterns in the data. With regard to
the choice of a larger vocabulary, it means better quality of the representation that input
text has when processed. This allows the model for better insight into finer language
features. In contrast, training over more epochs increases the exploration of data by the
model, and subsequently, its predictions are refined. In a nutshell, these lead to robust
generalization by the model to unseen data, thus enhancing its performance capability in
robustly executing real-world applications.
LINK:[Link]
86vFUm1H#scrollTo=29Cd3AqM640Z