All Projects → Shawn1993 → Cnn Text Classification Pytorch

Shawn1993 / Cnn Text Classification Pytorch

Licence: apache-2.0
CNNs for Sentence Classification in PyTorch

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Cnn Text Classification Pytorch

Health-Discernment-System
A menu based multiple chronic disease detection system which will detect if a person is suffering from a severe disease by taking an essential input image.
Stars: ✭ 25 (-97.04%)
Mutual labels:  cnn-model
yolo-deepsort-flask
Target detection and multi target tracking platform based on Yolo DeepSort and Flask.
Stars: ✭ 29 (-96.57%)
Mutual labels:  cnn-model
Cnn Models
ImageNet pre-trained models with batch normalization for the Caffe framework
Stars: ✭ 355 (-57.99%)
Mutual labels:  cnn-model
COVID-away
Repo of paper title 'Avoid touching your face: A hand-to-face 3d motion dataset (covid-away) and trained models for smartwatches'
Stars: ✭ 18 (-97.87%)
Mutual labels:  cnn-model
VoiceNET.Library
.NET library to easily create Voice Command Control feature.
Stars: ✭ 14 (-98.34%)
Mutual labels:  cnn-model
Speech Emotion Recognition
Using Convolutional Neural Networks in speech emotion recognition on the RAVDESS Audio Dataset.
Stars: ✭ 63 (-92.54%)
Mutual labels:  cnn-model
Weapon-Detection-And-Classification
Weapon Detection & Classification through CCTV surveillance using Deep Learning-CNNs.
Stars: ✭ 53 (-93.73%)
Mutual labels:  cnn-model
Cnn Lstm Bilstm Deepcnn Clstm In Pytorch
In PyTorch Learing Neural Networks Likes CNN(Convolutional Neural Networks for Sentence Classification (Y.Kim, EMNLP 2014) 、LSTM、BiLSTM、DeepCNN 、CLSTM、CNN and LSTM
Stars: ✭ 714 (-15.5%)
Mutual labels:  cnn-model
CompareModels TRECQA
Compare six baseline deep learning models on TrecQA
Stars: ✭ 61 (-92.78%)
Mutual labels:  cnn-model
Deeptraffic
Deep Learning models for network traffic classification
Stars: ✭ 321 (-62.01%)
Mutual labels:  cnn-model
SpeakerDiarization RNN CNN LSTM
Speaker Diarization is the problem of separating speakers in an audio. There could be any number of speakers and final result should state when speaker starts and ends. In this project, we analyze given audio file with 2 channels and 2 speakers (on separate channels).
Stars: ✭ 56 (-93.37%)
Mutual labels:  cnn-model
Music-Genre-Classification
Genre Classification using Convolutional Neural Networks
Stars: ✭ 27 (-96.8%)
Mutual labels:  cnn-model
PyVGGFace
VGG-Face CNN descriptor in PyTorch.
Stars: ✭ 21 (-97.51%)
Mutual labels:  cnn-model
Image-Classification
Pre-trained VGG-Net Model for image classification using tensorflow
Stars: ✭ 29 (-96.57%)
Mutual labels:  cnn-model
Evil
Optical Character Recognition in Swift for iOS&macOS. 银行卡、身份证、门牌号光学识别
Stars: ✭ 648 (-23.31%)
Mutual labels:  cnn-model
pyTorch-text-classification
pyTorch-text-classification
Stars: ✭ 15 (-98.22%)
Mutual labels:  cnn-model
pytorch Highway Networks
Highway Networks implement in pytorch
Stars: ✭ 63 (-92.54%)
Mutual labels:  cnn-model
Facerank
FaceRank - Rank Face by CNN Model based on TensorFlow (add keras version). FaceRank-人脸打分基于 TensorFlow (新增 Keras 版本) 的 CNN 模型(QQ群:167122861)。技术支持:http://tensorflow123.com
Stars: ✭ 841 (-0.47%)
Mutual labels:  cnn-model
Captcha Tensorflow
Image Captcha Solving Using TensorFlow and CNN Model. Accuracy 90%+
Stars: ✭ 660 (-21.89%)
Mutual labels:  cnn-model
Resnetcam Keras
Keras implementation of a ResNet-CAM model
Stars: ✭ 269 (-68.17%)
Mutual labels:  cnn-model

Introduction

This is the implementation of Kim's Convolutional Neural Networks for Sentence Classification paper in PyTorch.

  1. Kim's implementation of the model in Theano: https://github.com/yoonkim/CNN_sentence
  2. Denny Britz has an implementation in Tensorflow: https://github.com/dennybritz/cnn-text-classification-tf
  3. Alexander Rakhlin's implementation in Keras; https://github.com/alexander-rakhlin/CNN-for-Sentence-Classification-in-Keras

Requirement

  • python 3
  • pytorch > 0.1
  • torchtext > 0.1
  • numpy

Result

I just tried two dataset, MR and SST.

Dataset Class Size Best Result Kim's Paper Result
MR 2 77.5%(CNN-rand-static) 76.1%(CNN-rand-nostatic)
SST 5 37.2%(CNN-rand-static) 45.0%(CNN-rand-nostatic)

I haven't adjusted the hyper-parameters for SST seriously.

Usage

./main.py -h

or

python3 main.py -h

You will get:

CNN text classificer

optional arguments:
  -h, --help            show this help message and exit
  -batch-size N         batch size for training [default: 50]
  -lr LR                initial learning rate [default: 0.01]
  -epochs N             number of epochs for train [default: 10]
  -dropout              the probability for dropout [default: 0.5]
  -max_norm MAX_NORM    l2 constraint of parameters
  -cpu                  disable the gpu
  -device DEVICE        device to use for iterate data
  -embed-dim EMBED_DIM
  -static               fix the embedding
  -kernel-sizes KERNEL_SIZES
                        Comma-separated kernel size to use for convolution
  -kernel-num KERNEL_NUM
                        number of each kind of kernel
  -class-num CLASS_NUM  number of class
  -shuffle              shuffle the data every epoch
  -num-workers NUM_WORKERS
                        how many subprocesses to use for data loading
                        [default: 0]
  -log-interval LOG_INTERVAL
                        how many batches to wait before logging training
                        status
  -test-interval TEST_INTERVAL
                        how many epochs to wait before testing
  -save-interval SAVE_INTERVAL
                        how many epochs to wait before saving
  -predict PREDICT      predict the sentence given
  -snapshot SNAPSHOT    filename of model snapshot [default: None]
  -save-dir SAVE_DIR    where to save the checkpoint

Train

./main.py

You will get:

Batch[100] - loss: 0.655424  acc: 59.3750%
Evaluation - loss: 0.672396  acc: 57.6923%(615/1066) 

Test

If you has construct you test set, you make testing like:

/main.py -test -snapshot="./snapshot/2017-02-11_15-50-53/snapshot_steps1500.pt

The snapshot option means where your model load from. If you don't assign it, the model will start from scratch.

Predict

  • Example1

     ./main.py -predict="Hello my dear , I love you so much ." \
               -snapshot="./snapshot/2017-02-11_15-50-53/snapshot_steps1500.pt" 
    

    You will get:

     Loading model from [./snapshot/2017-02-11_15-50-53/snapshot_steps1500.pt]...
     
     [Text]  Hello my dear , I love you so much .
     [Label] positive
    
  • Example2

     ./main.py -predict="You just make me so sad and I have to leave you ."\
               -snapshot="./snapshot/2017-02-11_15-50-53/snapshot_steps1500.pt" 
    

    You will get:

     Loading model from [./snapshot/2017-02-11_15-50-53/snapshot_steps1500.pt]...
     
     [Text]  You just make me so sad and I have to leave you .
     [Label] negative
    

Your text must be separated by space, even punctuation.And, your text should longer then the max kernel size.

Reference

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].