top of page

TensorFlow Simple MultiClass NLP prediction - Poem classification, level 2, 21 min

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
confusion matrix in multi class tensorflow nlp problem

In this simple TensorFlow multiclass prediction problem in Python we will be an NLP model and attempt to classify poems as Affection, Death, Environment, or Love. Poems are a very difficult NLP classification due to the abstract nature of the writing makes this a very difficult dataset to get a very high score. Our goal will be an accuracy of .50, which is normally very low but very difficult to achieve on Poem classification.


We will build our model today in the Sequential model in TensorFlow. The first layer in our model will be an Embedding layer. We will follow our embedding layer with a special type of dropout layer called Spatial Dropout and this drops each neuron by changing not a certain percentage of each layer. This allows some epochs to have more or less total neurons turned off. This type of dropout works for NLP problems.



After our Spatial Dropout layers, we use a Global Average Pooling layers and that's it. This simple style of NLP model doesn't work well on all types of datasets but tends to work well when the concept of the words is abstract like is often true in poems.








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
remove special character in string Python

Here we use tried to use replace in Pandas but \xa0 turns out to be a special character to represent a line break and we had to use the split and join functions to fix this.




free, free academic, instruct, instructional, instructional education,free python learn, seaborn, python, project, data analysis project, pandas, analyze, Tensorflow, architecture, neural network, deep learning
lowercase character remove stop words and punction

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


free, free academic, instruct, instructional, instructional education,free python learn, seaborn, python, project, data analysis project, pandas, analyze, Tensorflow, architecture, neural network, deep learning
Sequential NLP model in Tensorflow

109 views0 comments
bottom of page