#!/bin/bash

if [ $# -lt 3 ]; then
    echo "$0 <log_file> <exp_name> <preprocessed_data_path/> [init_model,init_model]"
    echo "  require 3 or 4 args, given $#"
    exit;
fi

log_file=$1
exp_name=$2
data_path=$3
init_model=${4:-""}

IFS="," read -r -a init_models <<< ${init_model}

echo "-----------------------------------------------"
echo "  Started `date`"
echo "-----------------------------------------------"

if [ ! -z ${init_model} ]; then
    echo "  Initializing "
    echo "    MT encoder from: ${init_models[0]}"
    echo "    MT decoder from: ${init_models[1]}"
    reload_model="--reload_model \"${init_model}\""
else
    echo "  Training MT from scratch"
fi

echo "  Log file  : ${log_file}"
echo "  Input data: ${data_path}"

epoch_size=10000
max_epoch=1000
bsize=64

dump_path=`dirname ${log_file}`/dumps/

emb_dim=512
n_layers=6
n_heads=4
dropout=0.3
attn_dropout=0.0
optimizer="adam,lr=0.0001"


# queue.pl is for BUT SGE cluster only
queue.pl --config conf/queue.conf --gpu 1 ${log_file} \
    python train.py \
    --exp_name ${exp_name} \
    --data_path ${data_path} \
    --dump_path ${dump_path} \
    --lgs en-pt \
    --clm_steps "" \
    --mlm_steps "" \
    --mt_steps "en-pt" \
    --encoder_only false \
    --emb_dim ${emb_dim} \
    --n_layers ${n_layers} \
    --n_heads ${n_heads} \
    --dropout ${dropout} \
    --attention_dropout ${attn_dropout} \
    --epoch_size ${epoch_size} \
    --max_epoch ${max_epoch} \
    --batch_size ${bsize} \
    --optimizer ${optimizer} \
    --eval_bleu true \
    ${reload_model}


echo "-----------------------------------------------"
echo "  Done    `date`"
echo "-----------------------------------------------"
