Coder Social home page Coder Social logo

charlstm's Introduction

Bidirectional Character LSTM for Sentiment Analysis

Requirements

  • Python 2.7
  • NLTK (punkt)
  • Tensorflow GPU/CPU version 1.1.0 (NOTE: This code has only been tested to work on this version of Tensorflow!!)

Setup

  • Download the datasets in CharLSTM/datasets
  • Download the Tokenize module of NLTK using nltk.download()
  • Change the PATH variable in data_utils.py and in the model files
  • Install the requirements
cd CharLSTM

# Create virtual environment
virtualenv --python==/path/to/python2.7 venv

# Activate venv
source venv/bin/activate

# Install requirements
pip install -r requirements.txt
  • Train the model you want with python main.py <MODEL_NAME> --train

Using a Pretrained Model

This repository provides a pretrained model for the unidirectional LSTM you can test your own sentences using:

python main.py lstm --sentences 'sentence 1' 'sentence 2' 'etc...'

Model

Results

Both models were trained for more or less 80000 iterations (~ 5 epochs) and achieved similar accuracy on a test set of 80000 tweets.

# (LSTM) Valid loss: 23.50035 -- Valid Accuracy: 0.83613
# (Bidirectional LSTM) Valid loss: 24.41145 -- Valid Accuracy: 0.82714
# Some examples...
# "cant believe i still have to write an essay..", yielded (pos/neg): 0.03065/0.96935, pred: neg
#
# "Why are you concerned with people leaking information youve declassified?" , yielded (pos/neg):
#  0.04639/0.95361, pred: neg
# 
# "Virus is going in reverse now, god my guts hurt", yielded (pos/neg): 0.09748/0.90252, pred: neg
# However, it still has problem with sarcasm:
# "his bravery?  Haha, you have to be kidding.", yielded (pos/neg): 0.73277/0.26723, pred: pos

You can read the tutorial here.

charlstm's People

Contributors

charlesashby avatar

Watchers

 avatar  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.