-
Notifications
You must be signed in to change notification settings - Fork 57
/
train_dragnn_sejong.sh
executable file
·191 lines (157 loc) · 4.46 KB
/
train_dragnn_sejong.sh
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
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
#!/bin/bash
set -o nounset
set -o errexit
# code from https://github.com/bazelbuild/bazel/blob/master/scripts/packages/bazel.sh
function get_realpath() {
if [ "$(uname -s)" == "Darwin" ]; then
local queue="$1"
if [[ "${queue}" != /* ]] ; then
# Make sure we start with an absolute path.
queue="${PWD}/${queue}"
fi
local current=""
while [ -n "${queue}" ]; do
# Removing a trailing /.
queue="${queue#/}"
# Pull the first path segment off of queue.
local segment="${queue%%/*}"
# If this is the last segment.
if [[ "${queue}" != */* ]] ; then
segment="${queue}"
queue=""
else
# Remove that first segment.
queue="${queue#*/}"
fi
local link="${current}/${segment}"
if [ -h "${link}" ] ; then
link="$(readlink "${link}")"
queue="${link}/${queue}"
if [[ "${link}" == /* ]] ; then
current=""
fi
else
current="${link}"
fi
done
echo "${current}"
else
readlink -f "$1"
fi
}
VERBOSE_MODE=0
function error_handler()
{
local STATUS=${1:-1}
[ ${VERBOSE_MODE} == 0 ] && exit ${STATUS}
echo "Exits abnormally at line "`caller 0`
exit ${STATUS}
}
trap "error_handler" ERR
PROGNAME=`basename ${BASH_SOURCE}`
function print_usage_and_exit()
{
set +x
local STATUS=$1
echo "Usage: ${PROGNAME} [-v] [-v] [-h] [--help]"
echo ""
echo " Options -"
echo " -v enables verbose mode 1"
echo " -v -v enables verbose mode 2"
echo " -h, --help shows this help message"
exit ${STATUS:-0}
}
function debug()
{
if [ "$VERBOSE_MODE" != 0 ]; then
echo $@
fi
}
GETOPT=`getopt vh $*`
if [ $? != 0 ] ; then print_usage_and_exit 1; fi
eval set -- "${GETOPT}"
while true
do case "$1" in
-v) let VERBOSE_MODE+=1; shift;;
-h|--help) print_usage_and_exit 0;;
--) shift; break;;
*) echo "Internal error!"; exit 1;;
esac
done
if (( VERBOSE_MODE > 1 )); then
set -x
fi
# template area is ended.
# -----------------------------------------------------------------------------
if [ ${#} != 0 ]; then print_usage_and_exit 1; fi
# current dir of this script
CDIR=$(get_realpath $(dirname $(get_realpath ${BASH_SOURCE[0]})))
PDIR=$(get_realpath $(dirname $(get_realpath ${BASH_SOURCE[0]}))/..)
# -----------------------------------------------------------------------------
# functions
function make_calmness()
{
exec 3>&2 # save 2 to 3
exec 2> /dev/null
}
function revert_calmness()
{
exec 2>&3 # restore 2 from previous saved 3(originally 2)
}
function close_fd()
{
exec 3>&-
}
function jumpto
{
label=$1
cmd=$(sed -n "/$label:/{:a;n;p;ba};" $0 | grep -v ':$')
eval "$cmd"
exit
}
# end functions
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# main
make_calmness
if (( VERBOSE_MODE > 1 )); then
revert_calmness
fi
python=/usr/bin/python
SRC_CORPUS_DIR=${CDIR}/sejong/wdir
DATA_DIR=${CDIR}/dragnn_examples/data_sejong
TRAIN_FILE=${DATA_DIR}/deptree.txt.v3.training
DEV_FILE=${DATA_DIR}/deptree.txt.v3.tuning
CHECKPOINT_FILE=${DATA_DIR}/checkpoint.model
function prepare_data {
local _src_corpus_dir=$1
local _data_dir=$2
mkdir -p ${_data_dir}
cp -rf ${_src_corpus_dir}/deptree.txt.v3.training ${_data_dir}
cp -rf ${_src_corpus_dir}/deptree.txt.v3.tuning ${_data_dir}
}
function train {
local _n_steps=$1
local _batch_size=$2
cd ${PDIR}
${PDIR}/bazel-bin/work/dragnn_examples/write_master_spec \
--spec_file=${DATA_DIR}/parser_spec.textproto
${PDIR}/bazel-bin/work/dragnn_examples/train_dragnn \
--logtostderr \
--compute_lexicon \
--dragnn_spec=${DATA_DIR}/parser_spec.textproto \
--resource_path=${DATA_DIR} \
--training_corpus_path=${TRAIN_FILE} \
--tune_corpus_path=${DEV_FILE} \
--tensorboard_dir=${DATA_DIR}/tensorboard \
--checkpoint_filename=${CHECKPOINT_FILE} \
--n_steps=${_n_steps} \
--batch_size=${_batch_size}
}
prepare_data ${SRC_CORPUS_DIR} ${DATA_DIR}
n_steps=100000
batch_size=64
train ${n_steps} ${batch_size}
close_fd
# end main
# -----------------------------------------------------------------------------