distill_chnsenticorp.sh 3.2 KB
Newer Older
C
chenxuyi 已提交
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 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 68 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
set -x
export PYTHONPATH=.:$PYTHONPATH
output_dir=./output/distill
teacher_dir=${output_dir}/teacher
student_dir=${output_dir}/student

# 1. finetune teacher
CUDA_VISIBLE_DEVICES=0 \
python3 -u ./distill/finetune_chnsenticorp.py \
    --data_dir ${TASK_DATA_PATH}/distill/chnsenticorp/teacher \
    --warm_start_from ${MODEL_PATH}/params \
    --vocab_file ${MODEL_PATH}/vocab.txt \
    --max_seqlen 128 \
    --run_config '{
        "model_dir": "'${teacher_dir}'",
        "max_steps": '$((10 * 9600 / 32))',
        "save_steps": 100,
        "log_steps": 10,
        "max_ckpt": 1,
        "skip_steps": 0,
        "eval_steps": 100
    }' \
    --hparam ${MODEL_PATH}/ernie_config.json \
    --hparam '{ # model definition
		"sent_type_vocab_size": None,    # default term in official config
		"use_task_id": False,
        "task_id": 0,
	}' \
    --hparam '{ # learn					    
      "warmup_proportion":  0.1,
      "weight_decay": 0.01,
      "fp16": 0,
      "learning_rate": 0.00005,
      "num_label": 2,
      "batch_size": 32 
    }' 

(($?!=0)) && echo "Something goes wrong at Step 1, please check" && exit -1

# 2. start a prediction server
export CUDA_VISIBLE_DEVICES=0
cat ${TASK_DATA_PATH}/distill/chnsenticorp/student/unsup_train_aug/part.0 |awk -F"\t" '{print $2}' |python3 -u ./distill/finetune_chnsenticorp.py \
    --do_predict \
    --data_dir ${TASK_DATA_PATH}/distill/chnsenticorp/teacher \
    --warm_start_from ${MODEL_PATH}/params \
    --vocab_file ${MODEL_PATH}/vocab.txt \
    --max_seqlen 128 \
    --run_config '{
        "model_dir": "'${teacher_dir}'",
        "log_steps": 10,
    }' \
    --hparam ${MODEL_PATH}/ernie_config.json \
    --hparam '{ # model definition
		"sent_type_vocab_size": None,    # default term in official config
		"use_task_id": False,
        "task_id": 0,
	}' \
    --hparam '{ # learn
      "warmup_proportion":  0.1,
      "weight_decay": 0.01,
      "fp16": 0,
      "learning_rate": 0.00005,
      "num_label": 2,
      "batch_size": 100 
    }'  > prediction_label

(($?!=0)) && echo "Something goes wrong at Step 2, please check" && exit -1

mkdir prediction_output
paste ${TASK_DATA_PATH}/distill/chnsenticorp/student/unsup_train_aug/part.0 prediction_label |awk -F"\t" '{print $2"\t"$3}' > prediction_output/part.0

#. 3. learn from teacher
export CUDA_VISIBLE_DEVICES=0 
python3 ./distill/distill_chnsentocorp.py \
    --data_dir ${TASK_DATA_PATH}/distill/chnsenticorp/student \
    --vocab_file ${TASK_DATA_PATH}/distill/chnsenticorp/student/vocab.txt \
    --unsupervise_data_dir ./prediction_output/ \
    --max_seqlen 128 \
    --run_config '{
        "model_dir": "'${student_dir}'",
        "max_steps": '$((100 * 9600 / 100))',
        "save_steps": 1000,
        "log_steps": 10,
        "max_ckpt": 1,
        "skip_steps": 0,
        "eval_steps": 100
    }' \
    --hparam '{
        "num_label": 2,
        "vocab_size": 35000,
        "emb_size": 128,
        "initializer_range": 0.02,
	}' \
    --hparam '{  					     # lr shit
      "warmup_proportion":  0.1,
      "weight_decay": 0.00,
      "fp16": 0,
      "learning_rate": 1e-4,
      "batch_size": 100 
    }' 

(($?!=0)) && echo "Something goes wrong at Step 3, please check" && exit -1