Code Monkey home page Code Monkey logo

muhammedbuyukkinaci / tensorflow-sentiment-analysis-on-amazon-reviews-data Goto Github PK

View Code? Open in Web Editor NEW
51.0 4.0 17.0 61.91 MB

Implementing different RNN models (LSTM,GRU) & Convolution models (Conv1D, Conv2D) on a subset of Amazon Reviews data with TensorFlow on Python 3. A sentiment analysis project.

Python 100.00%
tensorflow long-short-term-memory-models sentiment-analysis sentiment-classification amazon-reviews tensorflow-examples tensorflow-tutorials tensorflow-gpu tensorflow-experiments tensorflow-api

tensorflow-sentiment-analysis-on-amazon-reviews-data's Introduction

TensorFlow-Sentiment-Analysis-on-Amazon-Reviews-Data

Implementing different RNN(GRU & LSTM) models on a subset of Amazon Reviews data.

Requirements

pip3 install -r requirements.txt

Pre-trained Word Embeddings

I used 100-Dimensional GloVe Word Embeddings for this project.

You can download it from here.

After downloading, glove.6B.100d.txt must be in where .py files are.

Default Version

If you have GPU, use 02_CUDNN_GRU.py or 06_CUDNN_LSTM.py as default .

If you don't have, use 04_CPU_Optimized_GRU.py or 08_CPU_Optimized_LSTM.py as default.

Training

python3 01_Baseline_GPU.py

python3 02_CUDNN_GRU.py

python3 03_CUDNN_GRU_bidirectional.py

python3 04_CPU_Optimized_GRU.py

python3 05_Baseline_LSTM.py

python3 06_CUDNN_LSTM.py

python3 07_CUDNN_LSTM_bidirectional.py

python3 08_CPU_Optimized_LSTM.py

python3 09_CONV1D_CUDNNGRU.py

python3 10_CONV2D.py

python3 11_Attention_GRU.py

python3 12_Attention_CUDNNGRU.py

python3 13_Attention_CUDNNGRU_bidirectional.py

Dataset

Dataset used in this project is a subset of Amazon Reviews.

Train dataset has 150k rows.

Test dataset has 30k rows.

Output classes are positive and negative (Binary Classification).

The models were trained on train dataset and validated on test dataset.

Models

01_Baseline_GRU.py --> Base GRU implementation.

02_CUDNN_GRU.py --> GPU optimized CUDNNGRU implementation.

03_CUDNN_GRU_bidirectional.py --> GPU optimized CUDNNGRU bidirectional implementation.

04_CPU_Optimized_GRU.py --> CPU optimized GRU implementation.

05_Baseline_LSTM.py --> Base LSTM implementation.

06_CUDNN_LSTM.py --> GPU optimized CUDNNLSTM implementation.

07_CUDNN_LSTM_bidirectional.py --> GPU optimized CUDNNLSTM bidirectional implementation.

08_CPU_Optimized_LSTM.py --> CPU optimized LSTM implementation.

09_CONV1D_CUDNNGRU.py --> CONV1D BEFORE CUDNNGRU implementation

10_CONV2D.py ---> CONV2D implementation before fully connected layers.

11_Attention_GRU.py ---> Attention Layer including GRU implementation

12_Attention_CUDNNGRU.py ---> Attention Layer including CUDNNGRU implementation

13_Attention_CUDNNGRU_bidirectional.py ---> Attention Layer including Bidirectional CUDNNGRU implementation

Early Stopping

I defined a customized function to check if loss is decreasing on test data.

If it isn't decreasing for a time period, the model stops to train.

#Defining a function for early stopping
def early_stopping_check(x):
    if np.mean(x[-20:]) <= np.mean(x[-80:]):
        return True
    else:
        return False

Results

results

tensorflow-sentiment-analysis-on-amazon-reviews-data's People

Contributors

muhammedbuyukkinaci avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tensorflow-sentiment-analysis-on-amazon-reviews-data's Issues

Invalid requirements file format

The format of requirements file doesn't meet expected format for pip3 requirements file. You can generate content of this file automatically using pip3 freeze

Model Testing

firstly thank you for your effort. Please, I have a question. I'm a little bit confused about why you are using the testing data for the validation process? Because as far as I know there should be training, validation, and testing. But I don't see that in your implementation!

Also, I want to ask if there is a way to visualize the attention weights in 11_Attention_GRU file?

Thanks

error while executing

The issue is Coming while involving 100-Dimensional GloVe Word Embeddings for this project.

Here i am using Notepad++
Traceback (most recent call last):
File "08_CPU_Optimized_LSTM.py", line 93, in
print(open(os.path.join(working_dir,EMBEDDING_FILE),'r' ).read())
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\encodings\cp
1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1215192:
character maps to

Error while training the tensorflow model

All of the training underwent good on GPU Machine, but the training has been stopped before the training steps like for 18000 steps it is showing Training has finished. What was the issue?

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.