Giter VIP home page Giter VIP logo

nlp_sentiment_classification's Introduction

NLP Sentiment Classification

Sentiment analysis in PyTorch, algorithm implemented as follows:

  • LSTM
  • LSTM with glove-pretrain embedding weights
  • Bidirectional LSTM
  • DistilBert

Dataset: IMDb

from datasets import load_dataset
load_dataset('imdb').with_format('torch') # for pytorch format

Glove

Apply pre-train glove pre-train word vector for LSTM embedding weight

unzip glove.6B.zip
python -m gensim.scripts.glove2word2vec --input glove.6B.100d.txt --output glove.6B.100d.w2vformat.txt
## load glove pre-train weight
import gensim
word_vec = gensim.models.KeyedVectors.load_word2vec_format('glove.6B.100d.w2vformat.txt', binary=False, encoding='utf-8')

Train & Save Model

# --m: model type(default/lstm: LSTM, glove-lstm: LSTM with glove-pretrain embedding weights, 
#                 bi-lstm:Bidirectional LSTM, distilbert:DistilBert)
# --e: epoch (default:2)
python main.py --m "glove-lstm" --e 3

Performance on Training & Test set (for ref)

Loss

model embedding dimention training epochs training loss test loss
LSTM 128 7 0.132 0.456
LSTM+GLOVE 100 7 0.309 0.331
Bidirectional LSTM 128 7 0.125 0.425
DistilBert 128 3 0.382 0.342

Accuracy

model training accuracy (%) test accuracy (%)
LSTM 95.73 84.54
LSTM+GLOVE 86.80 85.53
Bidirectional LSTM 95.96 84.39
DistilBert 83.10 85.10

Demo

Use gradio to demo model result, please click link to give it a try! image

nlp_sentiment_classification's People

Contributors

zolahsieh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.