pytorch-sentiment-analysis icon indicating copy to clipboard operation
pytorch-sentiment-analysis copied to clipboard

migrating to the new API

Open richardxing opened this issue 3 years ago • 4 comments

Hi, could you migrate from the legacy API to the new API. Thanks a lot!

richardxing avatar Jul 02 '21 23:07 richardxing

I'm working on this currently. Planning to completely re-do all of the tutorials -- change the order and models used -- now that the new API is stable.

bentrevett avatar Jul 05 '21 09:07 bentrevett

Thanks a lot! Looking forward to it!

richardxing avatar Jul 05 '21 18:07 richardxing

Tutorials with the new API are now available, see:

  • https://github.com/bentrevett/pytorch-sentiment-analysis/blob/master/1_nbow.ipynb
  • https://github.com/bentrevett/pytorch-sentiment-analysis/blob/master/2_lstm.ipynb
  • https://github.com/bentrevett/pytorch-sentiment-analysis/blob/master/3_cnn.ipynb
  • https://github.com/bentrevett/pytorch-sentiment-analysis/blob/master/4_transformer.ipynb

Only the code is available for now, need to add the text/images. Major changes are:

  • using new torchtext API
  • using HuggingFace Datasets to load data. I decided to use this instead of torchtext to load the data as the HuggingFace team are constantly adding new datasets pretty rapidly, whereas torchtext seems to be hesitant to add more.
  • using tqdm instead of a custom timing function
  • plotting the loss/acc per batch instead of just printing loss/acc per epoch
  • order/models changed from rnn -> lstm -> nbow -> cnn -> transformer, to: nbow -> lstm -> cnn -> transformer. Decided it was better to start with the nbow model as it's the simplest, and nobody uses plain RNNs anymore and it was weird to start the tutorial with a model that didn't work.
  • use FastText embeddings instead of GloVe. API is the same but I see more people use FastText so decided to switch.

bentrevett avatar Jul 13 '21 13:07 bentrevett

Hie, is there a way to import custom data on the new torchtext API, as the data.TabularDatasets.splits is now retired. Thanks.

thulieblack avatar Sep 06 '21 11:09 thulieblack