Skip to content
Convolutional Neural Network for Text Classification in Tensorflow
Python
Branch: master
Clone or download
Latest commit 18762b4 Jul 21, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
data/rt-polaritydata Make code Python 3 compatible. Change data to UTF-8 Apr 2, 2016
.gitignore Code updates Nov 26, 2015
LICENSE Add license May 8, 2016
README.md Fixes the required TF version. Jan 5, 2017
data_helpers.py Update data_helpers.py Jul 20, 2018
eval.py Minor typo Sep 23, 2017
text_cnn.py Minor fix to comment typo Sep 28, 2017
train.py solve `error to parse FLAGS` Mar 7, 2018

README.md

This code belongs to the "Implementing a CNN for Text Classification in Tensorflow" blog post.

It is slightly simplified implementation of Kim's Convolutional Neural Networks for Sentence Classification paper in Tensorflow.

Requirements

  • Python 3
  • Tensorflow > 0.12
  • Numpy

Training

Print parameters:

./train.py --help
optional arguments:
  -h, --help            show this help message and exit
  --embedding_dim EMBEDDING_DIM
                        Dimensionality of character embedding (default: 128)
  --filter_sizes FILTER_SIZES
                        Comma-separated filter sizes (default: '3,4,5')
  --num_filters NUM_FILTERS
                        Number of filters per filter size (default: 128)
  --l2_reg_lambda L2_REG_LAMBDA
                        L2 regularizaion lambda (default: 0.0)
  --dropout_keep_prob DROPOUT_KEEP_PROB
                        Dropout keep probability (default: 0.5)
  --batch_size BATCH_SIZE
                        Batch Size (default: 64)
  --num_epochs NUM_EPOCHS
                        Number of training epochs (default: 100)
  --evaluate_every EVALUATE_EVERY
                        Evaluate model on dev set after this many steps
                        (default: 100)
  --checkpoint_every CHECKPOINT_EVERY
                        Save model after this many steps (default: 100)
  --allow_soft_placement ALLOW_SOFT_PLACEMENT
                        Allow device soft device placement
  --noallow_soft_placement
  --log_device_placement LOG_DEVICE_PLACEMENT
                        Log placement of ops on devices
  --nolog_device_placement

Train:

./train.py

Evaluating

./eval.py --eval_train --checkpoint_dir="./runs/1459637919/checkpoints/"

Replace the checkpoint dir with the output from the training. To use your own data, change the eval.py script to load your data.

References

You can’t perform that action at this time.