Skip to content

Detailed implementation of a CNN for sentiment analysis

Notifications You must be signed in to change notification settings

omseeth/cnn_sentiment_analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to use a Convolutional Neural Network (CNN) for text classification (sentiment analysis) with PyTorch

This tutorial is an introduction to Convolutional Neural Networks (CNNs) for sentiment analysis with PyTorch. There are already a few tutorials and solutions for this task by Gal Hever, Jason Brownlee, or Ben Trevett. However, they are either written in Keras or lack some explanations that I find essential for understanding the underlying mechanics of CNNs as well as their PyTorch specific implementations. I hope this tutorial will therefore help the interested reader to learn more about CNNs and how to implement them for NLP tasks, such as sentiment analysis.

What follows is partially the result of a lecture given by Barbara Plank at LMU in 2024, whom I'd like to thank along with her lab MaiNLP for letting me use some of their code. The theoretical part discussed in this tutorial is also highly indebted to Raschka et al. (2022), whose book on machine learning is for me one of the best resources.

Check out sentiment_analyser.ipynb for the the following chapters:

  • Preliminaries imports
  • Section 1) Preprocessing the dataset
  • Section 2) Theoretical foundations of CNNs for classification
  • Section 3) Implementing a CNN with PyTorch
  • Section 4) Evaluation of results

About

Detailed implementation of a CNN for sentiment analysis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published