ICP 10 - awais546/Python-and-Deep-Learning GitHub Wiki

Python and Deep Learning

Introduction

In this ICP we learned to develop a deep learning model for sentiment analysis. Sentiment analysis is a technique used in NLP to detect the emotions of a text. This can be done using WordtoVec model. This model converts words to numeric vectors and those vectors can be used to develop a deep learning model to predict the sentiment of the text.

Tasks

  • Correct the code
  • Add Embedded layer
  • Run the code on 20newsgroup data

Correct the code

There were few mistakes in the code.

  1. The input dimensions were not defined. The input dimension is kept the shape of the element of the training set.
  2. The second error was the output layers was written wrong. The number of categories in the file was 3 but it was written 5 in the code.
  3. The third error was the presence of wrong activation function. For determining the category of a sample we need to check the probabilities and that can be achieved using the 'sigmoid' activation function.

By running the code following accuracy was achieved.

Addition of embedding layer

By adding the embedding layer the accuracy was increased as shown in the following screenshot.

20newsgroup Dataset In order to downloaded the dataset use the following piece of code.

Running the prediction on one of the sample of 20newsgroup text gives the following array. This array shows the one hot encoding array.