genienlp/tests/test_calibration.sh

64 lines
1.8 KiB
Bash
Raw Normal View History

2021-03-02 23:19:46 +00:00
#!/usr/bin/env bash
. ./tests/lib.sh
i=0
# test calibration
for hparams in \
2022-08-25 04:04:08 +00:00
"--model TransformerSeq2Seq --pretrained_model sshleifer/bart-tiny-random" ;
2021-03-02 23:19:46 +00:00
do
2022-08-25 04:04:08 +00:00
# train
genienlp train \
$SHARED_TRAIN_HPARAMS \
2022-08-25 04:04:08 +00:00
--train_tasks almond \
--train_batch_tokens 100 \
--val_batch_size 100 \
--train_iterations 6 \
--save $workdir/model_$i \
--data $SRCDIR/dataset/ \
$hparams
2021-03-02 23:19:46 +00:00
2022-08-25 04:04:08 +00:00
# greedy prediction
genienlp predict \
--tasks almond \
--evaluate test \
--path $workdir/model_$i \
--overwrite \
--eval_dir $workdir/model_$i/eval_results/ \
--data $SRCDIR/dataset/ \
--embeddings $EMBEDDING_DIR \
--save_confidence_features \
--confidence_feature_path $workdir/model_$i/confidences.pkl \
--mc_dropout_num 10
2021-03-02 23:19:46 +00:00
2022-08-25 04:04:08 +00:00
# check if confidence file exists
if test ! -f $workdir/model_$i/confidences.pkl ; then
echo "File not found!"
exit 1
fi
2021-03-02 23:19:46 +00:00
2022-08-25 04:04:08 +00:00
# calibrate
genienlp calibrate \
--confidence_path $workdir/model_$i/confidences.pkl \
--save $workdir/model_$i \
--testing \
--name_prefix test_calibrator
2021-03-02 23:19:46 +00:00
2022-08-25 04:04:08 +00:00
# check if calibrator exists
if test ! -f $workdir/model_$i/test_calibrator.calib ; then
echo "File not found!"
exit 1
fi
2021-03-02 23:19:46 +00:00
2022-08-25 04:04:08 +00:00
echo "Testing the server mode after calibration"
# single example in server mode
echo '{"id": "dummy_example_1", "context": "show me .", "question": "translate to thingtalk", "answer": "now => () => notify"}' | genienlp server --path $workdir/model_$i --stdin
# batch in server mode
echo '{"id":"dummy_request_id_1", "instances": [{"example_id": "dummy_example_1", "context": "show me .", "question": "translate to thingtalk", "answer": "now => () => notify"}]}' | genienlp server --path $workdir/model_$i --stdin
2021-03-02 23:19:46 +00:00
2022-08-25 04:04:08 +00:00
rm -rf $workdir/model_$i
2021-03-02 23:19:46 +00:00
2022-08-25 04:04:08 +00:00
i=$((i+1))
2021-03-02 23:19:46 +00:00
done