Skip to content

hongyusu/sentiment_predictor

Repository files navigation

Deep Learning for sentiment analysis

The sentiment predictor is built with a Convolutional Neural Network model realized by Keras API running Tensorflow as backend. The feature embedding is using pretrained sentiment140 model.

  1. Required packages

    Package Version Installation
    keras 1.0.3 PIP
    theano 0.8.2 PIP
    tensorflow 0.12.0rc0 PIP
    pandas 0.19.1 PIP
    sklearn 0.08.1 PIP
    flask 0.11.1 PIP
    tweepy 3.5.0 PIP
    h5py 2.6.0 PIP
  2. Installation script for deep learning modules

    pip install keras==1.0.3       
    pip install theano==0.8.2       
    pip install tensorflow==0.12.0rc0       
    pip install pandas==0.19.1       
    pip install sklearn==0.08.1       
    pip install flask==0.11.1       
    pip install tweep==3.5.0       
    pip install h5py==2.6.0

Web service

Web service is built with Python Flask.

Deploy to Heroku

  1. Install virtual environment

    sudo python install virtualenv
  2. Set up a new virtual environment with name venv

    virtualenv venv
  3. Activate the virtual environment

    souce ./venv/Scripts/activate
  4. Install all requirement Python packages

    pip install keras==1.0.3       
    pip install theano==0.8.2       
    pip install tensorflow==0.12.0rc0       
    pip install pandas==0.19.1       
    pip install sklearn==0.08.1       
    pip install flask==0.11.1       
    pip install tweep==3.5.0       
    pip install h5py==2.6.0
  5. Create a dependency file requirement.txt which include all packages and patterns. We do this via

    pip freeze > requirement.txt
  6. Tensorflow needs some special treatment (revision) to the requirement file. So remove the tensor flow line, something like

    tensorflow==0.10.0

    and add one line

    https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
  7. Create a runtime.txt file and add the following line to declare python version used in this web app

    python-2.7.12
  8. Create a Procfile file and add the following line to specify how to run the application when deployed

    web: bin/web

    also create the bin/web file with the following content

    python app.py
  9. Version control via Git all required files.

  10. Push to Heroku repository

    git push -u heroku master