args.py 4.4 KB
Newer Older
Q
qiuxuezhong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#   Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
import distutils.util


def parse_args():
    parser = argparse.ArgumentParser(description=__doc__)
X
xuezhong 已提交
25 26 27 28
    parser.add_argument(
        '--prepare',
        action='store_true',
        help='create the directories, prepare the vocabulary and embeddings')
Q
qiuxuezhong 已提交
29
    parser.add_argument('--train', action='store_true', help='train the model')
X
xuezhong 已提交
30
    parser.add_argument(
Q
qiuxuezhong 已提交
31
        '--evaluate', action='store_true', help='evaluate the model on dev set')
X
xuezhong 已提交
32
    parser.add_argument(
Q
qiuxuezhong 已提交
33
        '--predict',
X
xuezhong 已提交
34 35
        action='store_true',
        help='predict the answers for test set with trained model')
Q
qiuxuezhong 已提交
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
    parser.add_argument(
        "--embed_size",
        type=int,
        default=300,
        help="The dimension of embedding table. (default: %(default)d)")
    parser.add_argument(
        "--hidden_size",
        type=int,
        default=300,
        help="The size of rnn hidden unit. (default: %(default)d)")
    parser.add_argument(
        "--batch_size",
        type=int,
        default=32,
        help="The sequence number of a mini-batch data. (default: %(default)d)")
    parser.add_argument(
        "--pass_num",
        type=int,
        default=5,
        help="The pass number to train. (default: %(default)d)")
    parser.add_argument(
        "--learning_rate",
        type=float,
        default=0.001,
        help="Learning rate used to train the model. (default: %(default)f)")
X
xuezhong 已提交
61 62 63
    parser.add_argument(
        "--weight_decay",
        type=float,
X
xuezhong 已提交
64
        default=0.0001,
X
xuezhong 已提交
65
        help="Weight decay. (default: %(default)f)")
Q
qiuxuezhong 已提交
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
    parser.add_argument(
        "--use_gpu",
        type=distutils.util.strtobool,
        default=True,
        help="Whether to use gpu. (default: %(default)d)")
    parser.add_argument(
        "--save_dir",
        type=str,
        default="model",
        help="Specify the path to save trained models.")
    parser.add_argument(
        "--load_dir",
        type=str,
        default="",
        help="Specify the path to load trained models.")
    parser.add_argument(
        "--save_interval",
        type=int,
        default=1,
        help="Save the trained model every n passes."
        "(default: %(default)d)")
    parser.add_argument(
        "--log_interval",
        type=int,
        default=50,
        help="log the train loss every n batches."
        "(default: %(default)d)")
    parser.add_argument(
        "--dev_interval",
        type=int,
        default=1000,
        help="cal dev loss every n batches."
        "(default: %(default)d)")
Q
qiuxuezhong 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111
    parser.add_argument('--optim', default='adam', help='optimizer type')
    parser.add_argument('--trainset', nargs='+', help='train dataset')
    parser.add_argument('--devset', nargs='+', help='dev dataset')
    parser.add_argument('--testset', nargs='+', help='test dataset')
    parser.add_argument('--vocab_dir', help='dict')
    parser.add_argument('--max_p_num', type=int, default=5)
    parser.add_argument('--max_a_len', type=int, default=200)
    parser.add_argument('--max_p_len', type=int, default=500)
    parser.add_argument('--max_q_len', type=int, default=9)
    parser.add_argument('--doc_num', type=int, default=5)
    parser.add_argument('--para_print', action='store_true')
    parser.add_argument('--drop_rate', type=float, default=0.0)
    parser.add_argument('--random_seed', type=int, default=123)
Q
qiuxuezhong 已提交
112 113 114
    parser.add_argument(
        '--log_path',
        help='path of the log file. If not set, logs are printed to console')
X
xuezhong 已提交
115 116 117 118 119 120 121 122
    parser.add_argument(
        '--result_dir',
        default='../data/results/',
        help='the dir to output the results')
    parser.add_argument(
        '--result_name',
        default='test_result',
        help='the file name of the results')
Q
qiuxuezhong 已提交
123 124
    args = parser.parse_args()
    return args