Skip to content
Shravyala edited this page Jul 21, 2020 · 2 revisions

Lesson-12 (RNN)

In this ICP, we have learnt about difference between FNN and RNN, what is RNN and LSTM.

Software Requirements:

  1. Python version 3 or Google Colab

  2. Pycharm

  3. Keras and Tensorflow installed

  4. Anaconda

  5. Github

Objectives of this ICP:

1. Save the model and use the saved model to predict on new text data (ex, “A lot of good things are happening. We are respected again throughout the world, and that's a great thing.@realDonaldTrump”)

  1. The data set considered here is Sentiment.csv

  2. Below is the link for source code.

     https://umkc.box.com/s/xrxrv8un2xen18yb1p9nq2xw70tm849g
    
  3. Import the necessary libraries

  4. Reading the CSV as a pandas data frame.

  5. Having only necessary two columns in the data frame.

  6. Next step is data pre-processing

  7. Replacing the special characters and rt in the text data with empty space

  8. Maximum features taken is 2000.

  9. Converting the text data into lower case

  10. Used the tokenizer API and performed fit to text and text to sequence methods on the text data.

  11. No of neurons and embedded dimensions are 128 and 196

  12. Next is the model creation

  13. Initialized the sequential layer

  14. Added the embedded layer, dropout is 0.2 and output layer is softmax

  15. Loss used is categorical_crossentropy, the optimizer is Adam and Metics is accuracy.

  16. Converting the categorical Y data to the numerical format and split it into test and train data

  17. Model execution is done. Accuracy and loss values are printed.

  18. Save and load the model

  19. In order to predict the new text from the saved model, Take the string and converting into pandas column. Performing the pre-processing which is converting the text data into lower case and removing the special characters. Converting the pre-processed text into the numerical format, which is used the tokenizer API and performed fit to text and text to sequence methods on the text data we see the predicted value at the output.

Below is the source code:

The output images are shown below:

Below is the link for complete output.

https://github.com/Shravyala/Python-Deep-Learning/blob/master/ICP-12/Output%20Images/ICP-12(1)_Output.txt

2. Apply GridSearchCV on the source code provided in the class

To the above code GridSearchCV is applied.

  1. Used the grid search CV to find out the best hyperparameters to train the model.

  2. Batch sizes are taken are 10 and 20. No of epochs used is 1 and 2.

  3. Initialized the Grid Search Model with the above parameters while fitting the model on the train data.

  4. Best parameters chosen are batch_size 10, epochs 2

  5. So found the accuracy for the tuned parameters

  6. Below is the source code

Output Images are shown below:

Below is the link for the complete output.

https://github.com/Shravyala/Python-Deep-Learning/blob/master/ICP-12/Output%20Images/ICP-12(2)_Output.txt

3. Apply the code on spamdata set available in thesourcecode (text classification on the spam.csvdata set)

  1. Here the data set considered is spam.csv

  2. To the first program source code the data set is replaced with spam.csv

  3. Loss and accuracy are calculated.

  4. Prediction is also done on the sample input text.

Below is the source code:

Output images are shown below:

Below is the link for complete output.

https://github.com/Shravyala/Python-Deep-Learning/blob/master/ICP-12/Output%20Images/ICP-12(3)_Output.txt

Video Link:

https://youtu.be/U7yCJK6qipA

Clone this wiki locally