top of page

TensorFlow Simple NLP Sarcasm Prediction LSTM Deep Learning Guided Project in Python

Updated: Aug 21, 2023



free, free academic, instruct, instructional, instructional education,free python learn, seaborn, python, project, data analysis project, pandas, analyze, Tensorflow, architecture, neural network, deep learning, simple lstm, simple nlp, simple TensorFlow, simple deep learning
Simple TensorFlow LSTM deep learning model

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:











free, free academic, instruct, instructional, instructional education,free python learn, seaborn, python, project, data analysis project, pandas, analyze, Tensorflow, architecture, neural network, deep learning, simple lstm, simple nlp, simple TensorFlow, simple deep learning
count plot of target checking for balance in classes

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.




free, free academic, instruct, instructional, instructional education,free python learn, seaborn, python, project, data analysis project, pandas, analyze, Tensorflow, architecture, neural network, deep learning, simple lstm, simple nlp, simple TensorFlow, simple deep learning
lower case text and removing punctuation

In our NLP processing, we can use pandas' lower function to use only lowercase letters in the alphabet.

free, free academic, instruct, instructional, instructional education,free python learn, seaborn, python, project, data analysis project, pandas, analyze, Tensorflow, architecture, neural network, deep learning, simple lstm, simple nlp, simple TensorFlow, simple deep learning
target to binary 0 and 1

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.



free, free academic, instruct, instructional, instructional education,free python learn, seaborn, python, project, data analysis project, pandas, analyze, Tensorflow, architecture, neural network, deep learning, simple lstm, simple nlp, simple TensorFlow, simple deep learning
sklearn for train test split

Using a tool from classical machine learning we use the train test split from sklearn to separate our data into training and testing sets.

free, free academic, instruct, instructional, instructional education,free python learn, seaborn, python, project, data analysis project, pandas, analyze, Tensorflow, architecture, neural network, deep learning, simple lstm, simple nlp, simple TensorFlow, simple deep learning
tokenizer in tensorflow

In TensorFlow, we use the tokenizer to convert the texts into numbers. In other words to tokenize our texts.

free, free academic, instruct, instructional, instructional education,free python learn, seaborn, python, project, data analysis project, pandas, analyze, Tensorflow, architecture, neural network, deep learning, simple lstm, simple nlp, simple TensorFlow, simple deep learning
tensorflow sequential model


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.

free, free academic, instruct, instructional, instructional education,free python learn, seaborn, python, project, data analysis project, pandas, analyze, Tensorflow, architecture, neural network, deep learning, simple lstm, simple nlp, simple TensorFlow, simple deep learning
plot training history of tensorflow model

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.

681 views1 comment
bottom of page