In this Deep Learning TensorFlow Guided Project, we will use the LSTM recurrent layer along with an embedding layer and dense fully connected layer in Python to predict if the news Headlines are sarcastic or not.
Follow along with me in this beginner simple TensorFlow deep learning project in Python. Learn to preprocess your data for NLP with TensorFlow. We will learn how to turn text into sequences and then how to pad these sequences so they are all the same size.
After we've done the essential NLP processing for deep learning we are ready to start building our architecture. We start with an embedding layer and next in our deep learning TensorFlow model we add a recurrent layer. You can use SimpleRNN, GRU, or LSTM layers but here we choose to use the LSTM layer.
The next layer we add to our TensorFlow simple deep learning model is a dropout layer to prevent overfitting and then this is followed by a dense layer with only 1 neuron as we are using a binary classification problem with sigmoid activation.
Follow Data Science Teacher Brandyn
dataGroups:
With machine learning in general but especially with deep learning models we need to be conscious of the balance in our target classes. Here we use a simple count plot in pandas to check the balance of our targets.
In our NLP processing, we can use pandas' lower function to use only lowercase letters in the alphabet.
With deep learning we need to convert our target from text into 0s and 1s to use with binary cross entropy loss function we will use in our tensorflow deep learning model.
Using a tool from classical machine learning we use the train test split from sklearn to separate our data into training and testing sets.
In TensorFlow, we use the tokenizer to convert the texts into numbers. In other words to tokenize our texts.
To build our simple NLP model we use TensorFlow's Sequential model. In our model we define an Embedding layer, a LSTM layer, a Dropout layer, and as our output, we have a Dense layer with one neuron activated by the sigmoid function.
Finally to view the history of our TensorFlow deep learning model we put the history attribute in a pandas DataFrame and use the default options in the pandas plot function to quickly and easily plot our deep learning model history.
simple python deep learning project