run.sh 4.8 KB
Newer Older
0
0YuanZhang0 已提交
1 2 3 4 5 6 7
#!/bin/bash

export FLAGS_sync_nccl_allreduce=0

export CUDA_VISIBLE_DEVICES=0
if  [ ! "$CUDA_VISIBLE_DEVICES" ]
then
0
0YuanZhang0 已提交
8
    export CPU_NUM=1
0
0YuanZhang0 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
    use_cuda=false
else
    use_cuda=true
fi

TASK_NAME=$1
TASK_TYPE=$2

BERT_BASE_PATH="./data/pretrain_model/uncased_L-12_H-768_A-12"
INPUT_PATH="./data/input/data/${TASK_NAME}"
SAVE_MODEL_PATH="./data/saved_models/${TASK_NAME}"
TRAIN_MODEL_PATH="./data/saved_models/trained_models"
OUTPUT_PATH="./data/output"
INFERENCE_MODEL="data/inference_models"
PYTHON_PATH="python"

0
0YuanZhang0 已提交
25 26 27 28
if [ -f ${SAVE_MODEL_PATH} ]; then
    rm ${SAVE_MODEL_PATH}
fi

0
0YuanZhang0 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
if [ ! -d ${SAVE_MODEL_PATH} ]; then
	mkdir ${SAVE_MODEL_PATH}
fi

#parameter configuration
if [ "${TASK_NAME}" = "udc" ]
then
  save_steps=1000
  max_seq_len=210
  print_steps=1000
  batch_size=6720
  in_tokens=true
  epoch=2
  learning_rate=2e-5
elif [ "${TASK_NAME}" = "swda" ]
then
  save_steps=500
  max_seq_len=128
  print_steps=200
  batch_size=6720
  in_tokens=true
  epoch=3
  learning_rate=2e-5
elif [ "${TASK_NAME}" = "mrda" ]
then
  save_steps=500
  max_seq_len=128
  print_steps=200
  batch_size=4096
  in_tokens=true
  epoch=7
  learning_rate=2e-5
elif [ "${TASK_NAME}" = "atis_intent" ]
then
  save_steps=100
  max_seq_len=128
  print_steps=10
  batch_size=4096
  in_tokens=true
0
0YuanZhang0 已提交
68
  epoch=20
0
0YuanZhang0 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
  learning_rate=2e-5
  INPUT_PATH="./data/input/data/atis/${TASK_NAME}"
elif [ "${TASK_NAME}" = "atis_slot" ]
then
  save_steps=100
  max_seq_len=128
  print_steps=10
  batch_size=32
  in_tokens=False
  epoch=50
  learning_rate=2e-5
  INPUT_PATH="./data/input/data/atis/${TASK_NAME}"
elif [ "${TASK_NAME}" = "dstc2" ]
then
  save_steps=400
  print_steps=20
  batch_size=8192
  in_tokens=true
  epoch=40
  learning_rate=5e-5
  INPUT_PATH="./data/input/data/dstc2/${TASK_NAME}"
  if [ "${TASK_TYPE}" = "train" ]
  then
    max_seq_len=256
  else
    max_seq_len=512
  fi
else
  echo "not support ${TASK_NAME} dataset.."
  exit 255
fi

#training
function train()
{
    $PYTHON_PATH -u main.py \
       --task_name=${TASK_NAME} \
       --use_cuda=$1 \
       --do_train=true \
       --in_tokens=${in_tokens} \
       --epoch=${epoch} \
       --batch_size=${batch_size} \
       --do_lower_case=true \
       --data_dir=${INPUT_PATH} \
       --bert_config_path=${BERT_BASE_PATH}/bert_config.json \
       --vocab_path=${BERT_BASE_PATH}/vocab.txt \
       --init_from_pretrain_model=${BERT_BASE_PATH}/params \
       --save_model_path=${SAVE_MODEL_PATH} \
       --save_param="params" \
       --save_steps=${save_steps} \
       --learning_rate=${learning_rate} \
       --weight_decay=0.01 \
       --max_seq_len=${max_seq_len} \
0
0YuanZhang0 已提交
122
       --print_steps=${print_steps};
0
0YuanZhang0 已提交
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
}

#predicting
function predict()
{
    $PYTHON_PATH -u main.py \
       --task_name=${TASK_NAME} \
       --use_cuda=$1 \
       --do_predict=true \
       --in_tokens=${in_tokens} \
       --batch_size=${batch_size} \
       --data_dir=${INPUT_PATH} \
       --do_lower_case=true \
       --init_from_params=${TRAIN_MODEL_PATH}/${TASK_NAME}/params \
       --bert_config_path=${BERT_BASE_PATH}/bert_config.json \
       --vocab_path=${BERT_BASE_PATH}/vocab.txt \
       --output_prediction_file=${OUTPUT_PATH}/pred_${TASK_NAME} \
       --max_seq_len=${max_seq_len};
}

#evaluating
function evaluate()
{
    $PYTHON_PATH -u main.py \
       --task_name=${TASK_NAME} \
       --use_cuda=$1 \
       --do_eval=True \
       --evaluation_file=${INPUT_PATH}/test.txt \
       --output_prediction_file=${OUTPUT_PATH}/pred_${TASK_NAME};
}

#saving the inference model
function save_inference()
{
    $PYTHON_PATH -u main.py \
       --task_name=${TASK_NAME} \
       --use_cuda=$1 \
       --init_from_params=${TRAIN_MODEL_PATH}/${TASK_NAME}/params \
       --do_save_inference_model=True \
       --bert_config_path=${BERT_BASE_PATH}/bert_config.json \
       --inference_model_dir=${INFERENCE_MODEL}/${TASK_NAME};
}

if [ "${TASK_TYPE}" = "train" ]
then
    echo "train $TASK_NAME start..........";
    train $use_cuda;
    echo ""train $TASK_NAME finish..........
elif [ "${TASK_TYPE}" = "predict" ]
then 
    echo "predict $TASK_NAME start..........";
    predict $use_cuda;
    echo "predict $TASK_NAME finish..........";
elif [ "${TASK_TYPE}" = "evaluate" ]
then
    export CUDA_VISIBLE_DEVICES=
    echo "evaluate $TASK_NAME start.........."; 
    evaluate false;
    echo "evaluate $TASK_NAME finish..........";
elif [ "${TASK_TYPE}" = "inference" ]
then
    echo "save $TASK_NAME inference model start..........";
    save_inference $use_cuda;
    echo "save $TASK_NAME inference model finish..........";
elif [ "${TASK_TYPE}" = "all" ]
then
    echo "Execute train、predict、evaluate and save inference model in sequence...."
    train $use_cuda;
    predict $use_cuda;
    evaluate false;
    save_inference $use_cuda;
    echo "done";
else
    echo "Parameter $TASK_TYPE is not supported, you can input parameter in [train|predict|evaluate|inference|all]"
    exit 255;
fi