forked from dsindex/textsum_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·159 lines (128 loc) · 3.29 KB
/
test.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
#!/bin/bash
set -o nounset
set -o errexit
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}`
DRY_RUN_MODE=0
function print_usage_and_exit()
{
set +x
local STATUS=$1
echo "Usage: ${PROGNAME} [-v] [-v] [--dry-run] [-h] [--help]"
echo ""
echo " Options -"
echo " -v enables verbose mode 1"
echo " -v -v enables verbose mode 2"
echo " --dry-run show what would have been dumped"
echo " -h, --help shows this help message"
exit ${STATUS:-0}
}
function debug()
{
if [ "$VERBOSE_MODE" != 0 ]; then
echo $@
fi
}
GETOPT=`getopt -o vh --long dry-run,help -n "${PROGNAME}" -- "$@"`
if [ $? != 0 ] ; then print_usage_and_exit 1; fi
eval set -- "${GETOPT}"
while true
do case "$1" in
-v) let VERBOSE_MODE+=1; shift;;
--dry-run) DRY_RUN_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=$(readlink -f $(dirname $(readlink -f ${BASH_SOURCE[0]})))
PDIR=$(readlink -f $(dirname $(readlink -f ${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
cp -rf ${CDIR}/textsum/data ${CDIR}
cp -rf ${CDIR}/data/data ${CDIR}/data/training-0
cp -rf ${CDIR}/data/data ${CDIR}/data/validation-0
cp -rf ${CDIR}/data/data ${CDIR}/data/test-0
# training
function train {
${CDIR}/bazel-bin/textsum/seq2seq_attention \
--mode=train \
--article_key=article \
--abstract_key=abstract \
--data_path=data/training-* \
--vocab_path=data/vocab \
--log_root=textsum/log_root \
--train_dir=textsum/log_root/train
}
# evaluation
function evaluate {
${CDIR}/bazel-bin/textsum/seq2seq_attention \
--mode=eval \
--article_key=article \
--abstract_key=abstract \
--data_path=data/validation-* \
--vocab_path=data/vocab \
--log_root=textsum/log_root \
--eval_dir=textsum/log_root/eval
}
# decode
function decode {
${CDIR}/bazel-bin/textsum/seq2seq_attention \
--mode=decode \
--article_key=article \
--abstract_key=abstract \
--data_path=data/test-* \
--vocab_path=data/vocab \
--log_root=textsum/log_root \
--decode_dir=textsum/log_root/decode \
--beam_size=8
}
train
evaluate
decode
close_fd
# end main
# -----------------------------------------------------------------------------