Giter VIP home page Giter VIP logo

sentiment-analysis-tensorflow's Introduction

Sentiment Analisys with Tensorflow

Forked from: https://github.com/katakonst/sentiment-analysis-tensorflow

This is a example of sentiment analisys for romanian and english language built up on tensorflow and tflearn

Enhancements:

  • added a webserver to expose a api

  • added Docker containers

Usage with docker

Language parameter can be en/ro

docker run -e "language=en" --publish 8080:8001 danionescu/sentiment-analysis-tensorflow:latest

Swagger:

http://localhost:8001/docs

Usage with curl

curl -X 'PUT' \
  'http://localhost:8001/api/analize' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "phrase": "Ceva text rau"
}'

Response body:

{
  "phrase": "Ceva text rau",
  "language": "ro",
  "positive": 0.020164920017123222,
  "negative": 0.979835033416748
}

Running in dev mode

cd project_folder
uvicorn webserver:app --reload --host 0.0.0.0 --port 8001

Running with docker compose

docker-compose up

Accuracy

After 10 epochs for romanian dataset :

Training Step: 5360  | total loss: 0.05475 | time: 51.239s
| Adam | epoch: 010 | loss: 0.05475 - acc: 0.9881 | val_loss: 0.53884 - val_acc: 0.8536 -- iter: 17144/17144

After 10 epochs for english dataset :

Training Step: 13620  | total loss: 0.05636 | time: 142.459s
| Adam | epoch: 010 | loss: 0.05636 - acc: 0.9940 | val_loss: 0.18359 - val_acc: 0.9396 -- iter: 43561/43561

How to use it

Predict

Pass en for English or ro for Romanian as arg to command line followed by text

$ python predict.py en "Food is awesome"
negative=0.022818154
positive=0.97718185
$ python predict.py ro "Mancarea este proasta"
negative=0.9629853
positive=0.037014768

Train

Pass en for English or ro for Romanian as arg to command line

$ python train.py en

Datasets

Positive dataset is more numerous than the negative one. This may cause a drop in accuracy.

English dataset

Dataset of reviews from yelp and imdb reviews

Train:
  • neg: 10090
  • pos: 33532
  • total: 43561
Test
  • neg: 10228
  • pos: 33394
  • total: 43622

Romanian dataset

Dataset of products and movies reviews

Train:
  • neg: 6370
  • pos: 10774
  • total: 17144
Test
  • neg: 4427
  • pos: 5840
  • total: 10267

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.