genienlp/tests/test_e2e_dialogues.sh

79 lines
2.2 KiB
Bash
Raw Normal View History

2022-02-25 18:52:48 +00:00
#!/usr/bin/env bash
. ./tests/lib.sh
# test e2e dialogue tasks
hparams=(
"--pretrained_model Helsinki-NLP/opus-mt-en-de"
2022-02-25 18:52:48 +00:00
"--pretrained_model sshleifer/bart-tiny-random"
2022-06-29 21:00:50 +00:00
"--pretrained_model Helsinki-NLP/opus-mt-en-de"
2022-02-25 18:52:48 +00:00
)
tasks=(
bitod
bitod_dst
2022-06-29 21:00:50 +00:00
risawoz
2022-02-25 18:52:48 +00:00
)
for i in ${!hparams[*]};
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 ${tasks[i]} \
--train_batch_tokens 100 \
--val_batch_size 300 \
--train_iterations 4 \
--min_output_length 2 \
--save $workdir/model_$i \
2022-08-26 01:37:49 +00:00
--data $SRCDIR/dataset/bitod \
${hparams[i]}
2022-02-25 18:52:48 +00:00
2022-08-25 04:04:08 +00:00
# greedy prediction
genienlp predict \
--tasks ${tasks[i]} \
--evaluate test \
--path $workdir/model_$i \
--overwrite \
--eval_dir $workdir/model_$i/eval_results/ \
--data $SRCDIR/dataset/bitod \
--embeddings $EMBEDDING_DIR \
--extra_metrics e2e_dialogue_score
2022-02-25 18:52:48 +00:00
2022-08-25 04:04:08 +00:00
# e2e prediction
genienlp predict \
--tasks ${tasks[i]} \
--evaluate test \
--path $workdir/model_$i \
--overwrite \
--eval_dir $workdir/model_$i/e2e_eval_results/ \
--data $SRCDIR/dataset/bitod \
--embeddings $EMBEDDING_DIR \
--extra_metrics e2e_dialogue_score \
--e2e_dialogue_evaluation
2022-08-25 04:04:08 +00:00
# check if result file exists
if ! [[ -f $workdir/model_$i/eval_results/test/${tasks[i]}.tsv || -f $workdir/model_$i/e2e_eval_results/test/e2e_dialogue_preds.json ]] ; then
echo "File not found!"
exit 1
fi
2022-08-25 04:04:08 +00:00
# check export and server mode
if [ $i == 0 ] ; then
echo "Testing export"
genienlp export --path $workdir/model_$i --output $workdir/model_"$i"_exported
2022-02-25 18:52:48 +00:00
2022-08-25 04:04:08 +00:00
echo "Testing the server mode"
echo '{"id": "dummy_example_1", "context": "show me .", "question": "translate to thingtalk", "answer": "now => () => notify"}' | genienlp server --path $workdir/model_$i --stdin
fi
2022-02-25 18:52:48 +00:00
2022-08-25 04:04:08 +00:00
if [ $i == 0 ] ; then
# check if predictions matches expected_results
diff -u $SRCDIR/expected_results/bitod/bitod.tsv $workdir/model_$i/eval_results/test/bitod.tsv
diff -u $SRCDIR/expected_results/bitod/e2e_dialogue_preds.json $workdir/model_$i/e2e_eval_results/test/e2e_dialogue_preds.json
fi
2022-02-25 18:52:48 +00:00
2022-08-25 04:04:08 +00:00
rm -rf $workdir/model_$i $workdir/model_"$i"_exported
2022-02-25 18:52:48 +00:00
done