• Stars
    star
    349
  • Rank 121,528 (Top 3 %)
  • 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

TensorFlow implementation of 'Attention Is All You Need (2017. 6)'

transformer hb-research

TensorFlow implementation of Attention Is All You Need. (2017. 6)

images

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
├── transformer             # transformer architecture graphs (from input to logits)
    ├── __init__.py             # Graph logic
    ├── attention.py            # Attention (multi-head, scaled_dot_product and etc..)
    ├── encoder.py              # Encoder logic
    ├── decoder.py              # Decoder logic
    └── layer.py                # Layers (FFN)
├── 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

Reference : hb-config, Dataset, experiments_fn, EstimatorSpec

Todo

  • Train and evaluate with 'WMT German-English (2016)' dataset

Config

Can control all Experimental environment.

example: check-tiny.yml

data:
  base_path: 'data/'
  raw_data_path: 'tiny_kor_eng'
  processed_path: 'tiny_processed_data'
  word_threshold: 1

  PAD_ID: 0
  UNK_ID: 1
  START_ID: 2
  EOS_ID: 3

model:
  batch_size: 4
  num_layers: 2
  model_dim: 32
  num_heads: 4
  linear_key_dim: 20
  linear_value_dim: 24
  ffn_dim: 30
  dropout: 0.2

train:
  learning_rate: 0.0001
  optimizer: 'Adam'  ('Adagrad', 'Adam', 'Ftrl', 'Momentum', 'RMSProp', 'SGD')
  
  train_steps: 15000
  model_dir: 'logs/check_tiny'
  
  save_checkpoints_steps: 1000
  check_hook_n_iter: 100
  min_eval_frequency: 100
  
  print_verbose: True
  debug: False
  
slack:
  webhook_url: ""  # after training notify you using slack-webhook
  • debug mode : using tfdbg
  • check-tiny is a data set with about 30 sentences that are translated from Korean into English. (recommend read it :) )

Usage

Install requirements.

pip install -r requirements.txt

Then, pre-process raw data.

python data_loader.py --config check-tiny

Finally, start train and evaluate model

python main.py --config check-tiny --mode train_and_evaluate

Or, you can use IWSLT'15 English-Vietnamese dataset.

sh prepare-iwslt15.en-vi.sh                                        # download dataset
python data_loader.py --config iwslt15-en-vi                       # preprocessing
python main.py --config iwslt15-en-vi --mode train_and_evalueate   # start training

Predict

After training, you can test the model.

  • command
python predict.py --config {config} --src {src_sentence}
  • example
$ python predict.py --config check-tiny --src "안녕하세요. 반갑습니다."

------------------------------------
Source: 안녕하세요. 반갑습니다.
 > Result: Hello . I'm glad to see you . <\s> vectors . <\s> Hello locations . <\s> will . <\s> . <\s> you . <\s>

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.

Tensorboar

tensorboard --logdir logs

  • check-tiny example

images

Reference

Author

Dongjun Lee ([email protected])

More Repositories

1

text-cnn-tensorflow

Convolutional Neural Networks for Sentence Classification(TextCNN) implements by TensorFlow
Python
248
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