run.sh 3.6 KB
Newer Older
Y
Yibing Liu 已提交
1
#!/bin/bash
2 3
export FLAGS_fraction_of_gpu_memory_to_use=0.02
export CUDA_VISIBLE_DEVICES=0,1,2,3     #   which GPU to use
Y
Yibing Liu 已提交
4 5 6

function run_train() {
    echo "training"
7
    python train.py \
Y
Yibing Liu 已提交
8 9 10
        --train_data ./data/train.tsv \
        --test_data ./data/test.tsv \
        --model_save_dir ./models \
11 12 13 14
        --validation_steps 2 \
        --save_steps 10 \
        --print_steps 1 \
        --batch_size 300 \
Y
Yibing Liu 已提交
15
        --epoch 10 \
16 17 18
        --traindata_shuffle_buffer 20000 \
        --word_emb_dim 128 \
        --grnn_hidden_dim 128 \
Y
Yibing Liu 已提交
19 20
        --bigru_num 2 \
        --base_learning_rate 1e-3 \
21
        --emb_learning_rate 2 \
Y
Yibing Liu 已提交
22 23 24
        --crf_learning_rate 0.2 \
        --word_dict_path ./conf/word.dic \
        --label_dict_path ./conf/tag.dic \
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
        --word_rep_dict_path ./conf/q2b.dic \
        --enable_ce false \
        --use_cuda false \
        --cpu_num 1
}

function run_train_single_gpu() {
    echo "single gpu training"              # which GPU to use
    export CUDA_VISIBLE_DEVICES=0
    python train.py \
        --use_cuda true
}

function run_train_multi_gpu() {
    echo "multi gpu training"
    export CUDA_VISIBLE_DEVICES=0,1,2,3     # which GPU to use
    python train.py \
        --use_cuda true
}

function run_train_multi_cpu() {
    echo "multi cpu training"
    python train.py \
        --use_cuda false \
        --cpu_num 10         #cpu_num works only when use_cuda=false
Y
Yibing Liu 已提交
50 51
}

Y
Yibing Liu 已提交
52 53
function run_eval() {
    echo "evaluating"
Y
Yibing Liu 已提交
54
    echo "this may cost about 5 minutes if run on you CPU machine"
55 56 57 58
    python eval.py \
        --batch_size 200 \
        --word_emb_dim 128 \
        --grnn_hidden_dim 128 \
Y
Yibing Liu 已提交
59
        --bigru_num 2 \
60
        --use_cuda False \
Y
Yibing Liu 已提交
61 62 63 64 65 66 67 68 69 70
        --init_checkpoint ./model_baseline \
        --test_data ./data/test.tsv \
        --word_dict_path ./conf/word.dic \
        --label_dict_path ./conf/tag.dic \
        --word_rep_dict_path ./conf/q2b.dic
}


function run_infer() {
    echo "infering"
71 72 73 74
    python predict.py \
        --batch_size 200 \
        --word_emb_dim 128 \
        --grnn_hidden_dim 128 \
Y
Yibing Liu 已提交
75
        --bigru_num 2 \
76 77 78
        --use_cuda False \
        --init_checkpoint ./model_baseline \
        --infer_data ./data/infer.tsv \
Y
Yibing Liu 已提交
79 80 81 82 83 84
        --word_dict_path ./conf/word.dic \
        --label_dict_path ./conf/tag.dic \
        --word_rep_dict_path ./conf/q2b.dic
}


85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
function run_inference() {
    echo "inference model"
    python inference_model.py \
        --word_emb_dim 128 \
        --grnn_hidden_dim 128 \
        --bigru_num 2 \
        --use_cuda False \
        --init_checkpoint ./model_baseline \
        --word_dict_path ./conf/word.dic \
        --label_dict_path ./conf/tag.dic \
        --word_rep_dict_path ./conf/q2b.dic \
        --inference_save_dir ./infer_model
}


Y
Yibing Liu 已提交
100 101 102 103 104 105
function main() {
    local cmd=${1:-help}
    case "${cmd}" in
        train)
            run_train "$@";
            ;;
106 107 108 109 110 111 112 113 114
        train_single_gpu)
            run_train_single_gpu "$@";
            ;;
        train_multi_gpu)
            run_train_multi_gpu "$@";
            ;;
        train_multi_cpu)
            run_train_multi_cpu "$@";
            ;;
Y
Yibing Liu 已提交
115 116
        eval)
            run_eval "$@";
Y
Yibing Liu 已提交
117 118 119 120
            ;;
        infer)
            run_infer "$@";
            ;;
121 122 123
        inference)
            run_inference "$@";
            ;;
Y
Yibing Liu 已提交
124
        help)
125
            echo "Usage: ${BASH_SOURCE} {train|train_single_gpu|train_multi_gpu|train_multi_cpu|eval|infer}";
Y
Yibing Liu 已提交
126 127 128 129
            return 0;
            ;;
        *)
            echo "unsupport command [${cmd}]";
130
            echo "Usage: ${BASH_SOURCE} {train|train_single_gpu|train_multi_gpu|train_multi_cpu|eval|infer}";
Y
Yibing Liu 已提交
131 132 133 134 135 136
            return 1;
            ;;
    esac
}

main "$@"