Need help with cnn-text-classification-tf?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

dennybritz
5.3K Stars 2.7K Forks Apache License 2.0 80 Commits 110 Opened issues

Description

Convolutional Neural Network for Text Classification in Tensorflow

Services available

!
?

Need anything else?

Contributors list

# 1,199
Scala
Jupyter...
machine...
transla...
44 commits
# 32,466
Python
perform...
Sass
locust
3 commits
# 97,371
Python
HTML
1 commit
# 65,403
Jupyter...
R
Groovy
naive-b...
1 commit
# 25,915
Python
Tensorf...
word-em...
bert
1 commit
# 98,000
Python
1 commit
# 94,484
Python
Shell
HTML
policy-...
1 commit
# 98,001
Python
Nim
Shell
1 commit
# 29,673
Python
Shell
HTML
softwar...
1 commit
# 98,020
Python
1 commit

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.