hoangcaobao / CharCNN

CharCNN model using TensorFlow framework for sentiment analysis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CharCNN

I use TensorFlow framework to create CharCNN model to detect sarcasm in English text. You can detect other characteristics when you provide data in data folder.

The architecture was created by Character-level Convolutional Networks for Text Classification.


Overview

Dataset

I use dataset supplied by google api. You can find it at here.

Model Architecture

The model utilizes Convolution 1D to extract features of the text, after that go throguh fully connected layers to classify.

Training

Small CharCNN and Large CharCNN take me only 5 epochs to get nearly 85% accuracy, but it will take a lot of time to train for Large CharCNN due to high number of parameters.


How to use my code

1. Clone it and install requirements libraries

git clone https://github.com/hoangcaobao/CharCNN.git
cd CharCNN
pip install -r requirements.txt

2. Upload data to train

Go to folder data, put data in json file in it. I already put sacarsm data in this folder.

3. Train model

This step makes you wait very long but it is required to get weights of model before next step.

python3 train.py --data-path ${} --epochs ${} --num-classes ${}

For example:

python3 train.py --data-path data/sarcasm.json --epochs 5 --num-classes 2

*Large CharCNN take a lot of time to train

4. Put sentences you want CharCNN to detect in test folder

5. Use model

python3 predict.py --data-path ${} --test-path ${} --num-classes ${}

For exmaple:

python3 predict.py --data-path data/sarcasm.json --test-path test/sentences.json 

Now you will have output of test folder in result.json file in result folder

Thank you for reading


HOANG CAO BAO

About

CharCNN model using TensorFlow framework for sentiment analysis

License:MIT License


Languages

Language:Python 100.0%