run.sh 5.7 KB
Newer Older
0
0YuanZhang0 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#!/bin/bash

export FLAGS_sync_nccl_allreduce=0
export FLAGS_eager_delete_tensor_gb=1.0

export CUDA_VISIBLE_DEVICES=0

if [ $# -ne 2 ]
then
  echo "please input parameters: TRAIN_TYPE and TASK_TYPE"
  echo "TRAIN_TYPE: [matching|seq2seq_naive|seq2seq_att|keywords|human]"
  echo "TASK_TYPE: [train|predict|evaluate|inference]"
  exit 255
fi

TRAIN_TYPE=$1
TASK_TYPE=$2

candi_train_type=("matching" "seq2seq_naive" "seq2seq_att" "keywords" "human")
candi_task_type=("train" "predict" "evaluate" "inference")

if [[ ! "${candi_train_type[@]}" =~ ${TRAIN_TYPE} ]] 
then
  echo "unknown parameter: ${TRAIN_TYPE}, just support [matching|seq2seq_naive|seq2seq_att|keywords|human]"
  exit 255
fi

if [[ ! "${candi_task_type[@]}" =~ ${TASK_TYPE} ]] 
then
  echo "unknown parameter: ${TRAIN_TYPE}, just support [train|predict|evaluate|inference]"
  exit 255
fi

INPUT_PATH="data/input/data"
OUTPUT_PATH="data/output"
SAVED_MODELS="data/saved_models"
INFERENCE_MODEL="data/inference_models"
PYTHON_PATH="python"

#train pretrain model
if  [ ! "$CUDA_VISIBLE_DEVICES" ]
then
0
0YuanZhang0 已提交
43
  export CPU_NUM=1
0
0YuanZhang0 已提交
44 45 46 47 48 49 50 51 52 53
  use_cuda=false
else
  use_cuda=true
fi

#training
function pretrain_train()
{

    pretrain_model_path="${SAVED_MODELS}/matching_pretrained"
0
0YuanZhang0 已提交
54 55 56 57 58
    if [ -f ${pretrain_model_path} ]
    then
        rm ${pretrain_model_path}
    fi

0
0YuanZhang0 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    if [ ! -d ${pretrain_model_path} ]
    then
        mkdir ${pretrain_model_path}
    fi

    ${PYTHON_PATH} -u main.py \
      --do_train=true \
      --use_cuda=${1} \
      --loss_type="CLS" \
      --max_seq_len=50 \
      --save_model_path=${pretrain_model_path} \
      --save_param="params" \
      --training_file="${INPUT_PATH}/unlabel_data/train.ids" \
      --epoch=20 \
      --print_step=1 \
      --save_step=400 \
      --batch_size=256 \
      --hidden_size=256 \
      --emb_size=256 \
      --vocab_size=484016 \
      --learning_rate=0.001 \
      --sample_pro 0.1 
}

function finetuning_train()
{
    save_model_path="${SAVED_MODELS}/${2}_finetuned"
0
0YuanZhang0 已提交
86 87 88 89 90 91

    if [ -f ${save_model_path} ]
    then
        rm ${save_model_path}
    fi

0
0YuanZhang0 已提交
92 93 94 95
    if [ ! -d ${save_model_path} ]
    then
        mkdir ${save_model_path}
    fi
0
0YuanZhang0 已提交
96

0
0YuanZhang0 已提交
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 122 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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
    ${PYTHON_PATH} -u main.py \
      --do_train=true \
      --use_cuda=${1} \
      --loss_type="L2" \
      --max_seq_len=50 \
      --init_from_pretrain_model="${SAVED_MODELS}/matching_pretrained/params/step_final" \
      --save_model_path=${save_model_path} \
      --save_param="params" \
      --training_file="${INPUT_PATH}/label_data/${2}/train.ids" \
      --epoch=50 \
      --print_step=1 \
      --save_step=400 \
      --batch_size=256 \
      --hidden_size=256 \
      --emb_size=256 \
      --vocab_size=484016 \
      --learning_rate=0.001 \
      --sample_pro 0.1
}

#predict
function pretrain_predict()
{
    ${PYTHON_PATH} -u main.py \
      --do_predict=true \
      --use_cuda=${1} \
      --predict_file="${INPUT_PATH}/unlabel_data/test.ids" \
      --init_from_params="${SAVED_MODELS}/trained_models/matching_pretrained/params" \
      --loss_type="CLS" \
      --output_prediction_file="${OUTPUT_PATH}/pretrain_matching_predict" \
      --max_seq_len=50 \
      --batch_size=256 \
      --hidden_size=256 \
      --emb_size=256 \
      --vocab_size=484016
}

function finetuning_predict()
{
    ${PYTHON_PATH} -u main.py \
      --do_predict=true \
      --use_cuda=${1} \
      --predict_file="${INPUT_PATH}/label_data/${2}/test.ids" \
      --init_from_params=${SAVED_MODELS}/trained_models/${2}_finetuned/params \
      --loss_type="L2" \
      --output_prediction_file="${OUTPUT_PATH}/finetuning_${2}_predict" \
      --max_seq_len=50 \
      --batch_size=256 \
      --hidden_size=256 \
      --emb_size=256 \
      --vocab_size=484016
}

#evaluate
function pretrain_eval()
{
    ${PYTHON_PATH} -u main.py \
      --do_eval=true \
      --use_cuda=${1} \
      --evaluation_file="${INPUT_PATH}/unlabel_data/test.ids" \
      --output_prediction_file="${OUTPUT_PATH}/pretrain_matching_predict" \
      --loss_type="CLS" 
}

function finetuning_eval()
{
    ${PYTHON_PATH} -u main.py \
      --do_eval=true \
      --use_cuda=${1} \
      --evaluation_file="${INPUT_PATH}/label_data/${2}/test.ids" \
      --output_prediction_file="${OUTPUT_PATH}/finetuning_${2}_predict" \
      --loss_type="L2" 
}

#inference model
function pretrain_infer()
{
    ${PYTHON_PATH} -u main.py \
      --do_save_inference_model=true \
      --use_cuda=${1} \
      --init_from_params="${SAVED_MODELS}/trained_models/matching_pretrained/params" \
      --inference_model_dir="${INFERENCE_MODEL}/matching_inference_model"

}
function finetuning_infer()
{
    ${PYTHON_PATH} -u main.py \
      --do_save_inference_model=true \
      --use_cuda=${1} \
      --init_from_params="${SAVED_MODELS}/trained_models/${2}_finetuned/params" \
      --inference_model_dir="${INFERENCE_MODEL}/${2}_inference_model"
}

if [ "${TASK_TYPE}" = "train" ]
then
    echo "train ${TRAIN_TYPE} start.........."
    if [ "${TRAIN_TYPE}" = "matching" ]
    then
        pretrain_train ${use_cuda};
    else
        finetuning_train ${use_cuda} ${TRAIN_TYPE};
    fi
elif [ "${TASK_TYPE}" = "predict" ]
then
    echo "predict ${TRAIN_TYPE} start.........."
    if [ "${TRAIN_TYPE}" = "matching" ]
    then
        pretrain_predict ${use_cuda};
    else
        finetuning_predict ${use_cuda} ${TRAIN_TYPE};
    fi
elif [ "${TASK_TYPE}" = "evaluate" ]
then
    echo "evaluate ${TRAIN_TYPE} start.........."
    if [ "${TRAIN_TYPE}" = "matching" ]
    then
        pretrain_eval ${use_cuda};
    else
        finetuning_eval ${use_cuda} ${TRAIN_TYPE};
    fi
elif [ "${TASK_TYPE}" = "inference" ]
then
    echo "save ${TRAIN_TYPE} inference model start.........."
    if [ "${TRAIN_TYPE}" = "matching" ]
    then
        pretrain_infer ${use_cuda};
    else
        finetuning_infer ${use_cuda} ${TRAIN_TYPE};
    fi
else
    exit 255
fi