/text_cnn

textcnn pytorch implemention on sentiment analysis

Primary LanguagePython

Pytorch Sentiment Classification

on A clean and simple template by FrancescoSaverioZuppichini🚀🚀

Dxzmpk

In this article, we present you a deep learning project called Pytorch Sentiment Classification. I will use the method proposed in <<Kim Y. Convolutional Neural Networks for Sentence Classification. 2014>>

  • modularity: we split each logic piece into a different python submodule
  • ready to go: by using poutyne a Keras-like framework you don't have to write any train loop.
  • torchsummary to show a summary of your models
  • reduce the learning rate on a plateau
  • auto-saving the best model
  • experiment tracking with comet
  • logging using python logging module

Installation

Clone the repo and go inside it. Then, run:

pip install -r requirements.txt

Run

python train.py

don't forget to download nltk_data for yourself, or the program will report an error

Train/Evaluation

In our case we kept things simple, all the training and evaluation logic is inside .main.py where we used poutyne as the main library. We already defined a useful list of callbacks:

  • learning rate scheduler
  • auto-save of the best model
  • early stopping Usually, this is all you need! alt

Callbacks

You may need to create custom callbacks, with poutyne is very easy since it support Keras-like API. You custom callbacks should go inside ./callbacks. For example, we have created one to update Comet every epoch. alt

Track your experiment

We are using comet to automatically track our models' results. This is what comet's board looks like after a few models run. alt Running main.py produces the following output: alt

Conclusions

I hope you found some useful information and hopefully it this template will help you on your next amazing project :)