• Stars
    star
    248
  • Rank 163,560 (Top 4 %)
  • Language
    Python
  • Created almost 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Convolutional Neural Networks for Sentence Classification(TextCNN) implements by TensorFlow

text-cnn hb-research

This code implements Convolutional Neural Networks for Sentence Classification models.

  • Figure 1: Illustration of a CNN architecture for sentence classification

figure-1

Requirements

Project Structure

init Project by hb-base

.
โ”œโ”€โ”€ config                  # Config files (.yml, .json) using with hb-config
โ”œโ”€โ”€ data                    # dataset path
โ”œโ”€โ”€ notebooks               # Prototyping with numpy or tf.interactivesession
โ”œโ”€โ”€ scripts                 # download or prepare dataset using shell scripts
โ”œโ”€โ”€ text-cnn                # text-cnn architecture graphs (from input to logits)
    โ”œโ”€โ”€ __init__.py             # Graph logic
โ”œโ”€โ”€ data_loader.py          # raw_date -> precossed_data -> generate_batch (using Dataset)
โ”œโ”€โ”€ hook.py                 # training or test hook feature (eg. print_variables)
โ”œโ”€โ”€ main.py                 # define experiment_fn
โ”œโ”€โ”€ model.py                # define EstimatorSpec
โ””โ”€โ”€ predict.py              # test trained model       

Reference : hb-config, Dataset, experiments_fn, EstimatorSpec

Todo

  • apply embed_type
    • CNN-rand
    • CNN-static
    • CNN-nonstatic
    • CNN-multichannel

Config

example: kaggle_movie_review.yml

data:
  type: 'kaggle_movie_review'
  base_path: 'data/'
  raw_data_path: 'kaggle_movie_reviews/'
  processed_path: 'kaggle_processed_data'
  testset_size: 25000
  num_classes: 5
  PAD_ID: 0

model:
  batch_size: 64
  embed_type: 'rand'     #(rand, static, non-static, multichannel)
  pretrained_embed: "" 
  embed_dim: 300
  num_filters: 256
  filter_sizes:
    - 2
    - 3
    - 4
    - 5
  dropout: 0.5

train:
  learning_rate: 0.00005
  
  train_steps: 100000
  model_dir: 'logs/kaggle_movie_review'
  
  save_checkpoints_steps: 1000
  loss_hook_n_iter: 1000
  check_hook_n_iter: 1000
  min_eval_frequency: 1000
  
slack:
  webhook_url: ""   # after training notify you using slack-webhook

Usage

Install requirements.

pip install -r requirements.txt

Then, prepare dataset and train it.

sh prepare_kaggle_movie_reviews.sh
python main.py --config kaggle_movie_review --mode train_and_evaluate

After training, you can try typing the sentences what you want using predict.py.

python python predict.py --config rt-polarity

Predict example

python predict.py --config rt-polarity
Setting max_seq_length to Config : 62
load vocab ...
Typing anything :)

> good
1
> bad
0

Experiments modes

โœ… : Working
โ—ฝ : Not tested yet.

  • โœ… evaluate : Evaluate on the evaluation data.
  • โ—ฝ extend_train_hooks : Extends the hooks for training.
  • โ—ฝ reset_export_strategies : Resets the export strategies with the new_export_strategies.
  • โ—ฝ run_std_server : Starts a TensorFlow server and joins the serving thread.
  • โ—ฝ test : Tests training, evaluating and exporting the estimator for a single step.
  • โœ… train : Fit the estimator using the training data.
  • โœ… train_and_evaluate : Interleaves training and evaluation.

Tensorboard

tensorboard --logdir logs

  • Category Color

category_image

  • rt-polarity (binary classification)

images

  • kaggle_movie_review (multiclass classification)

images

Reference

More Repositories

1

transformer-tensorflow

TensorFlow implementation of 'Attention Is All You Need (2017. 6)'
Python
349
star
2

conversation-tensorflow

TensorFlow implementation of Conversation Models
Python
144
star
3

quantified-self

Self-knowledge through numbers
Python
143
star
4

char-rnn-tensorflow

Multi-layer Recurrent Neural Networks for character-level language models implements by TensorFlow
Python
60
star
5

notes

The notes for Math, Machine Learning, Deep Learning and Research papers.
Python
52
star
6

dmn-tensorflow

TensorFlow implementation of 'Ask Me Anything: Dynamic Memory Networks for Natural Language Processing (2015)'
Python
41
star
7

awesome-feeds

A curated list of tech, machine learning, biz and etc... feeds
28
star
8

dqn-tensorflow

Deep Q Network implements by Tensorflow
Python
25
star
9

hb-config

hb-config: easy to configure your python project especially Deep Learning experiments
Python
21
star
10

hb-base

Project structure of Deep Learning experiments
Python
13
star
11

BeAwesomeToday

Be Awesome Today - My Awesome List & Today I Learned & Blogging Articles
13
star
12

DeepLearning-Notebooks

Deep Learning Notebooks Implements by TensorFlow, Python + numpy
Jupyter Notebook
12
star
13

vae-tensorflow

TensorFlow implementation of Auto-Encoding Variational Bayes.
Python
8
star
14

gan-pytorch

PyTorch implementation of 'GAN (Generative Adversarial Networks)'
Python
7
star
15

DataScience-Notebooks

Collection of Data Science Notebooks
Jupyter Notebook
7
star
16

hb-nvim

The ultimate nvim distribution
Vim Script
6
star
17

kino-webhook

Serverless webhook handler
Python
2
star
18

SaladyBot

Slack Bot for Salady
Python
2
star
19

PEP8_kor

PEP 8 -- Style Guide for Python Code (Korean)
2
star
20

DongjunLee

2
star
21

relation-network-tensorflow

TensorFlow implementation of 'A simple neural network module for relational reasoning' for bAbi task.
Python
2
star
22

BeHappy-Django

Quantified Self Project for Happiness, Efficiency, Activity
CSS
2
star
23

bi-att-flow-tensorflow

In Progress...
Python
2
star
24

Effective_Python_Notes

Summary of Effective Python and example notebooks
1
star