transformer tensorflow
1.0.0
Tensorflowの注意の実装だけが必要です。 (2017。6)

HBベースによるINITプロジェクト
.
├── 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
参照:HB-Config、DataSet、Experiments_Fn、TisitatorSpec
すべての実験環境を制御できます。
例:tiny.ymlをcheckします
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-webhookcheck-tiny韓国語から英語に翻訳された約30文のデータセットです。 (それを読むことをお勧めします:)) 要件をインストールします。
pip install -r requirements.txt
次に、RAWデータを前処理します。
python data_loader.py --config check-tiny
最後に、列車を開始してモデルを評価します
python main.py --config check-tiny --mode train_and_evaluate
または、IWSLT'15英語とベトナムのデータセットを使用できます。
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
トレーニング後、モデルをテストできます。
python predict.py --config {config} --src {src_sentence}$ 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>✅:働いています
◽:まだテストされていません。
evaluate :評価データで評価します。extend_train_hooks :トレーニング用のフックを拡張します。reset_export_strategies :new_export_strategiesでエクスポート戦略をリセットします。run_std_server :Tensorflowサーバーを起動し、サービングスレッドに結合します。test :シングルステップの推定器のトレーニング、評価、エクスポートのテスト。train :トレーニングデータを使用して推定器を適合させます。train_and_evaluate :トレーニングと評価をリーブします。tensorboard --logdir logs

Dongjun Lee([email protected])