-
Notifications
You must be signed in to change notification settings - Fork 0
/
prep-cuis.sh.TEMPLATE
executable file
·206 lines (174 loc) · 7.3 KB
/
prep-cuis.sh.TEMPLATE
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
202
203
204
205
206
#!/bin/bash
## Most, if not all, of these environment variables will need to be
## customized to match your running environment.
export ENSEMBLE_DIR=/data/software/ots-ensemble-systems
export ENSEMBLE_CONDA=/data/software/anaconda3/envs/ensemble-py3.8
export ETUDE_DIR=/data/software/etude
export ETUDE_CONDA=/data/software/anaconda3/envs/etude
export CONFIG_DIR=/data/software/etude-engine-configs
export TASK=2019_n2c2_track3
export N2C2_2019_DIR=/data/n2c2_corpora/2019_n2c2_track-3
## N2C2_2019_DIR
## |-- train
## | |-- train_norm
## | `-- train_note
## |-- test
## | |-- test_norm
## | |-- test_norm_cui_replaced_with_unk
## | `-- test_note
## `-- top10_outputs
## |-- submission_Ali.txt
## |-- submission_KP.txt
## |-- submission_MDQ.txt
## |-- submission_MIT.txt
## |-- submission_NaCT.txt
## |-- submission_TTI.txt
## |-- submission_UAZ.txt
## |-- submission_UAv.txt
## |-- submission_UWM.txt
## `-- submission_ezDI.txt
export RESULT_DIR=/data/experiments/ots-ensemble-paper
export RESULT_FILE=${RESULT_DIR}/${TASK}/${TASK}_results.csv
mkdir -p "${RESULT_DIR}/${TASK}"
echo "Method Classifiers Accuracy Coverage MinVote Split" \
> ${RESULT_FILE}
## RESULT_DIR/2019_n2c2_track3
## |-- 2019_n2c2_track3_results.csv
## |-- etude
## | |-- voting_1_1.log
## | |-- voting_1_2.log
## | |-- voting_1_3.log
## | |-- ...
## | |-- voting_1_123.log
## | |-- ...
## | |-- voting_2_123.log
## | |-- ...
## | `-- voting_3_123.log
## `-- merged
## | |-- consolidated.xmi
## | |-- ...
## | `-- files.xmi
## `-- voting
## |-- processed.xmi
## |-- ...
## `-- files.xmi
export MERGED_OUT=${RESULT_DIR}/${TASK}/merged
mkdir -p "${MERGED_OUT}"
export REF_DIR=${RESULT_DIR}/${TASK}/ref
mkdir -p "${REF_DIR}"
mkdir -p ${RESULT_DIR}/${TASK}/etude
export METHOD=voting
export SYS_DIR=${RESULT_DIR}/${TASK}/${METHOD}
mkdir -p ${SYS_DIR}
## Merge the oracle/reference annotation with the above classifiers to
## generate a single input corpus for the meta-classifier ensemble
## system to read in
${ENSEMBLE_CONDA}/bin/python3 \
${ENSEMBLE_DIR}/medspaCy/n2c2-2019-track3-converter.py \
--input-text ${N2C2_2019_DIR}/test/test_note \
--input-norm ${N2C2_2019_DIR}/test/test_norm \
--input-systems ${N2C2_2019_DIR}/top10_outputs \
--file-list ${N2C2_2019_DIR}/test/test_file_list.txt \
--output-dir ${MERGED_OUT}
## Create an reference corpus in the same format
${ENSEMBLE_CONDA}/bin/python3 \
${ENSEMBLE_DIR}/medspaCy/oracleEnsemble.py \
--types-dir ${ENSEMBLE_DIR}/types \
--input-dir "${MERGED_OUT}" \
--voting-unit span \
--ref-dir ${REF_DIR}
export METHOD=decisionTemplate
export MODEL_DIR=${RESULT_DIR}/${TASK}/${METHOD}-models
mkdir -p ${MODEL_DIR}
export MINVOTES=1
for CLASSIFIERS in {1..10}
do
export SYS_DIR=${RESULT_DIR}/${TASK}/${METHOD}/${MINVOTES}_${CLASSIFIERS}
export SYS_TRAIN_DIR=${RESULT_DIR}/${TASK}/${METHOD}/${MINVOTES}_${CLASSIFIERS}/train
export SYS_TEST_DIR=${RESULT_DIR}/${TASK}/${METHOD}/${MINVOTES}_${CLASSIFIERS}/test
mkdir -p ${SYS_DIR}
mkdir -p ${SYS_TRAIN_DIR}
mkdir -p ${SYS_TEST_DIR}
## Train Decision Template ensemble system
${ENSEMBLE_CONDA}/bin/python3 \
${ENSEMBLE_DIR}/medspaCy/decisionTemplate.py \
--types-dir ${ENSEMBLE_DIR}/types \
--phase train \
--voting-unit span \
--input-dir "${MERGED_OUT}" \
--classifier-list ${CLASSIFIERS} \
--overlap-strategy rank \
--zero-strategy drop \
--decision-profiles-file "${MODEL_DIR}/${MINVOTES}_${CLASSIFIERS}.pkl"
## Test Decision Template ensemble system
${ENSEMBLE_CONDA}/bin/python3 \
${ENSEMBLE_DIR}/medspaCy/decisionTemplate.py \
--types-dir ${ENSEMBLE_DIR}/types \
--phase test \
--voting-unit span \
--input-dir "${MERGED_OUT}" \
--classifier-list ${CLASSIFIERS} \
--overlap-strategy rank \
--zero-strategy drop \
--decision-profiles-file "${MODEL_DIR}/${MINVOTES}_${CLASSIFIERS}.pkl" \
--output-dir ${SYS_DIR}
${ETUDE_CONDA}/bin/python3 ${ETUDE_DIR}/etude.py \
--reference-conf ${CONFIG_DIR}/uima/ensemble_note-nlp_xmi.conf \
--reference-input ${REF_DIR} \
--test-conf ${CONFIG_DIR}/uima/ensemble_note-nlp_xmi.conf \
--test-input ${SYS_TRAIN_DIR} \
--file-suffix ".xmi" \
--fuzzy-match-flags exact \
--score-normalization note_nlp_source_concept_id \
--metrics Accuracy TP FP FN TN \
> ${RESULT_DIR}/${TASK}/etude/${METHOD}_${MINVOTES}_${CLASSIFIERS}_train.log
export COVERAGE=`grep micro ${RESULT_DIR}/${TASK}/etude/${METHOD}_${MINVOTES}_${CLASSIFIERS}_train.log | cut -f 2 | head -n 1 | tr '\n' '\t'`
export ACCURACY=`grep micro ${RESULT_DIR}/${TASK}/etude/${METHOD}_${MINVOTES}_${CLASSIFIERS}_train.log | cut -f 2 | tail -n 1 | tr '\n' '\t'`
echo "${METHOD} ${CLASSIFIERS} ${ACCURACY}${COVERAGE}${MINVOTES} trn" \
>> ${RESULT_FILE}
${ETUDE_CONDA}/bin/python3 ${ETUDE_DIR}/etude.py \
--reference-conf ${CONFIG_DIR}/uima/ensemble_note-nlp_xmi.conf \
--reference-input ${REF_DIR} \
--test-conf ${CONFIG_DIR}/uima/ensemble_note-nlp_xmi.conf \
--test-input ${SYS_TEST_DIR} \
--file-suffix ".xmi" \
--fuzzy-match-flags exact \
--score-normalization note_nlp_source_concept_id \
--metrics Accuracy TP FP FN TN \
> ${RESULT_DIR}/${TASK}/etude/${METHOD}_${MINVOTES}_${CLASSIFIERS}_test.log
export COVERAGE=`grep micro ${RESULT_DIR}/${TASK}/etude/${METHOD}_${MINVOTES}_${CLASSIFIERS}_test.log | cut -f 2 | head -n 1 | tr '\n' '\t'`
export ACCURACY=`grep micro ${RESULT_DIR}/${TASK}/etude/${METHOD}_${MINVOTES}_${CLASSIFIERS}_test.log | cut -f 2 | tail -n 1 | tr '\n' '\t'`
echo "${METHOD} ${CLASSIFIERS} ${ACCURACY}${COVERAGE}${MINVOTES} tst" \
>> ${RESULT_FILE}
done
export METHOD=voting
export MINVOTES=1
for CLASSIFIERS in {1..10}
do
export SYS_DIR=${RESULT_DIR}/${TASK}/${METHOD}/${MINVOTES}_${CLASSIFIERS}
mkdir -p ${SYS_DIR}
## Simple voting ensemble system
${ENSEMBLE_CONDA}/bin/python3 \
${ENSEMBLE_DIR}/medspaCy/votingEnsemble.py \
--types-dir ${ENSEMBLE_DIR}/types \
--input-dir "${MERGED_OUT}" \
--voting-unit span \
--classifier-list ${CLASSIFIERS} \
--min-votes ${MINVOTES} \
--zero-strategy drop \
--output-dir ${SYS_DIR}
${ETUDE_CONDA}/bin/python3 ${ETUDE_DIR}/etude.py \
--reference-conf ${CONFIG_DIR}/uima/ensemble_note-nlp_xmi.conf \
--reference-input ${REF_DIR} \
--test-conf ${CONFIG_DIR}/uima/ensemble_note-nlp_xmi.conf \
--test-input ${SYS_DIR} \
--file-suffix ".xmi" \
--fuzzy-match-flags exact \
--score-normalization note_nlp_source_concept_id \
--metrics Accuracy TP FP FN TN \
> ${RESULT_DIR}/${TASK}/etude/${METHOD}_${MINVOTES}_${CLASSIFIERS}.log
export COVERAGE=`grep micro ${RESULT_DIR}/${TASK}/etude/${METHOD}_${MINVOTES}_${CLASSIFIERS}.log | cut -f 2 | head -n 1 | tr '\n' '\t'`
export ACCURACY=`grep micro ${RESULT_DIR}/${TASK}/etude/${METHOD}_${MINVOTES}_${CLASSIFIERS}.log | cut -f 2 | tail -n 1 | tr '\n' '\t'`
echo "${METHOD} ${CLASSIFIERS} ${ACCURACY}${COVERAGE}${MINVOTES} all" \
>> ${RESULT_FILE}
done