dennybritz /cnn-text-classification-tf
Convolutional Neural Network for Text Classification in Tensorflow
★ 5,685⑂ 2,718👁 273⑃ 38● 158▤ 0
+0
日增长
5,685
stars
2,718
forks
273
watchers
38
prs
158
issues
0
releases
README
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:
bash
./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:
bash
./train.py
Evaluating
bash
./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
- Convolutional Neural Networks for Sentence Classification
- A Sensitivity Analysis of (and Practitioners' Guide to) Convolutional Neural Networks for Sentence ClassificationTop issues
#69Multiclass classification and pre-trained word embedding (word2vec & GloVe) support and it's comparison36 comments · 2017-02-22#17Using pretrained word embeddings32 comments · 2016-05-18#127error to parse FLAGS13 comments · 2017-12-26#147Warning: tensorflow.contrib.learn.python.learn.preprocessing.text) is deprecated and will be removed in a future version. Instructions for updating: Please use tensorflow/transform or tf.data.10 comments · 2018-05-30#116Evaluation when using pre trained vectors8 comments · 2017-10-26#115eval.py7 comments · 2017-10-24#88How to constrain L2-Norm of weights in the last layer as Kim did?7 comments · 2017-05-01#82I run train.py and then run eval.py, have error,could you help me please!6 comments · 2017-04-11