-
Notifications
You must be signed in to change notification settings - Fork 2
/
utagger
executable file
·201 lines (168 loc) · 4.37 KB
/
utagger
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
192
193
194
195
196
197
198
199
200
201
#!/bin/bash
set -e
LM=2 # LM order
CHANNEL=""
INPUT=""
OUTPUT="output"
MODE="train" # [train,test]
ROM="false"
IL="xx" # incident language
PL="en" # parent language(s), comman separated
BASELINE="brown"
NCLUSTERS=500
NJOBS=2
NITERS=500
W_LM=1
W_CM=1
INPUT_FORMAT="txt" #[elisa:tgz,xml;txt,bio]
BIO_DELIM=""
LRLP_FIELD="ULF_LRLP_TOKENIZED_SOURCE"
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
EXP_DIR="$BASEDIR/exp-cipher"
CODE_DIR="$BASEDIR/src/code"
if [ -z "$CARMEL_DIR" ]; then
CARMEL_DIR="/usr/local"
fi
if [ -z "$SRILM_DIR" ]; then
SRILM_DIR="$HOME/srilm-1.7.2"
fi
while [ $# -gt 1 ]
do
key="$1"
case $key in
-lm_o|--lm_order)
LM="$2"
shift # past argument
;;
-i|--input)
INPUT="$2"
shift # past argument
;;
-if|--in_format)
INPUT_FORMAT="$2"
shift # past argument
;;
-bio_delim|--bio_delim)
BIO_DELIM="$2"
shift # past argument
;;
-m|--mode)
MODE="$2"
shift # past argument
;;
-rom|--rom)
ROM="$2"
shift # past argument
;;
-cl|--child_lang)
IL="$2"
shift # past argument
;;
-pl|--par_langs)
PL="$2"
shift # past argument
;;
-o|--output)
OUTPUT="$2"
shift # past argument
;;
-exp|--exp_dir)
EXP_DIR="$2"
shift # past argument
;;
-ca|--clust_alg)
BASELINE="$2"
shift # past argument
;;
-nc|--nclusters)
NCLUSTERS="$2"
shift # past argument
;;
-nj|--njobs)
NJOBS="$2"
shift # past argument
;;
-wlm|--wlm)
W_LM="$2"
shift # past argument
;;
-wcm|--wcm)
W_CM="$2"
shift # past argument
;;
-carmel|--carmel)
CARMEL_DIR="$2"
shift # past argument
;;
-sri|--sridir)
SRILM_DIR="$2"
shift # past argument
;;
*)
# unknown option
;;
esac
shift
done
export CARMEL_DIR=$CARMEL_DIR
export SRILM_DIR=$SRILM_DIR
export EXP_DIR=$EXP_DIR
PL_CODES=(${PL//,/ })
mkdir -p $EXP_DIR/logs $EXP_DIR/models $EXP_DIR/data
datadir="$EXP_DIR/data"
if [ $OUTPUT = "output" ];then
OUTPUT="$datadir/output.tagged"
fi
##########################################################
# PREPROCESS
##########################################################
#extract from xml
echo "Extracting..."
if [ $INPUT_FORMAT = "xml" ]; then
python3 src/code/elisa2flat.py --infile $INPUT \
--fields $LRLP_FIELD \
--outfile $datadir/input.raw
elif [ $INPUT_FORMAT = "bio" ]; then
cat $INPUT | cut -f 1 -d " " | sed 's/^$/#eos/g' | tr '\n' ' ' | \
sed 's/ #eos /\n/g' > "$datadir"/input.raw
else
cp $INPUT $datadir/input.raw
fi
# preprocess
echo "Preprocessing..."
bash $CODE_DIR/preprocess.sh -i $datadir/input.raw -rom $ROM -m $MODE -l input -exp $EXP_DIR
##########################################################
# RUN TAGGER
##########################################################
# train combined LM
if [ $MODE = "train" ]&&[ "${#PL_CODES[@]}" -gt 1 ]; then
echo "Training combined language model..."
bash $CODE_DIR/train_combined_lm.sh -l $PL -ord $LM -exp $EXP_DIR
fi
# run clustering
if [ $MODE = "train" ]; then
echo "Training clustering..."
bash src/code/run_clustering.sh -i $datadir/input.clean.filt \
-b $BASELINE -nc $NCLUSTERS -nj $NJOBS -exp $EXP_DIR
fi
echo "Tagging text with cluster ids..."
bash $CODE_DIR/tag_with_clusters.sh -b $BASELINE -n $NCLUSTERS -i $datadir/input.clean.filt -e $EXP_DIR
if [ $MODE = "train" ]; then
echo "Training cipher model..."
python3 $CODE_DIR/train_cipher.py -il $IL -rl $PL -exp $EXP_DIR \
-it $NITERS -rc 100 -lm 2 -b $BASELINE -nc $NCLUSTERS -j $NJOBS -m train -dc 1.1
python3 $CODE_DIR/combine_channels.py -nc $NCLUSTERS -ca $BASELINE -exp $EXP_DIR -it $NITERS \
-il $IL -rl $PL
fi
echo "Decoding with cipher model..."
if [ $INPUT_FORMAT = "xml" ]||[ $INPUT_FORMAT = "txt" ]; then
python3 $CODE_DIR/train_cipher.py -il $IL -rl comb -exp $EXP_DIR \
-o $OUTPUT -tk $datadir/input.raw -tkr $datadir/input.raw.roman \
-fm $INPUT_FORMAT \
-it $NITERS -rc 100 -lm 2 -b $BASELINE -nc $NCLUSTERS -j 1 -m eval -dc 1.1 -ct
elif [ $INPUT_FORMAT = "bio" ]; then
python3 src/code/train_cipher.py -il $IL -rl comb -exp $EXP_DIR \
-o $OUTPUT -tk $INPUT -tkr $datadir/input.raw.roman \
-fm $INPUT_FORMAT \
-it $NITERS -rc 100 -lm 2 -b $BASELINE -nc $NCLUSTERS -j 1 -m eval -dc 1.1 -ct
fi