-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_eval.sh
66 lines (55 loc) · 2.8 KB
/
run_eval.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
# Copyright (c) 2020-present, Royal Bank of Canada.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
# SET PATH
export HOME_PATH=absolute/path/to/keyphrase-generation/folder
export EVALSET="kp20k"
export DATASET="kp20k"
export BATCH_SIZE=256
# Specify models configurations that you would like to evaluate
# Un-comment all configurations below if the corresponding models have been trained
EVAL_MODELS=(
copy_seq2seq_attn_mle_greedy.tgt_15.0.copy_18.0
# copy_seq2seq_attn_mle_greedy.tgt_15.0.copy_18.0.futureLoss_1.0.nsteps_2
# copy_seq2seq_attn_mle_greedy.tgt_15.0.copy_18.0.futureLoss_1.0.nsteps_2.future_mle_tgt_copy
)
for BASE_PATH in "${EVAL_MODELS[@]}"
do
BASE_PATH=output/$DATASET/$BASE_PATH
cd output/
sh create_model_tar.sh $HOME_PATH/$BASE_PATH $HOME_PATH/$BASE_PATH/best.th
cd ..
export MODEL_CHECKPOINT=$BASE_PATH/model.tar.gz
export JSON_SAVE_PATH=$BASE_PATH/test_predictions.json
export EVAL_SAVE_DIR=$BASE_PATH/eval_results_$EVALSET
allennlp predict $MODEL_CHECKPOINT data/sample_testset/$EVALSET\_sorted.jsonl \
--include-package keyphrase_generation \
--predictor seq2seq_attn --cuda-device 0 --batch-size $BATCH_SIZE \
--output-file $JSON_SAVE_PATH
python keyphrase_generation/utils/convert_json_to_txts.py \
--json_file_path $JSON_SAVE_PATH \
--save_path $EVAL_SAVE_DIR
find $EVAL_SAVE_DIR/pred.txt -type f -exec sed -i 's/@sep@//g' {} \;
python keyphrase_generation/evaluation/evaluate_prediction.py -pred_file_path $EVAL_SAVE_DIR/pred.txt \
-src_file_path $EVAL_SAVE_DIR/src.txt \
-trg_file_path $EVAL_SAVE_DIR/tgt.txt \
-exp $EVALSET -export_filtered_pred -disable_extra_one_word_filter -invalidate_unk \
-all_ks 5 M -present_ks 5 M -absent_ks 5 M \
-exp_path $EVAL_SAVE_DIR \
-filtered_pred_path $EVAL_SAVE_DIR \
-meng_rui_precision
done
for BASE_PATH in "${EVAL_MODELS[@]}"
do
echo $BASE_PATH
export BASE_PATH=output/$DATASET/$BASE_PATH
export EVAL_SAVE_DIR=$BASE_PATH/eval_results_$EVALSET
# Quality Eval Results
python -u keyphrase_generation/evaluation/parse_results.py --results_file $EVAL_SAVE_DIR/results_log_5_M_5_M_5_M_meng_rui_precision.tsv > $EVAL_SAVE_DIR/quality_eval.txt
cat $EVAL_SAVE_DIR/quality_eval.txt
# Diversity Eval Results
python -u keyphrase_generation/evaluation/diversity_eval.py --pred_file $EVAL_SAVE_DIR/pred.txt > $EVAL_SAVE_DIR/diversity_eval.txt
cat $EVAL_SAVE_DIR/diversity_eval.txt
done