diff options
author | snukky <rgrundki@exceed.ed.ac.uk> | 2019-07-27 17:16:49 +0300 |
---|---|---|
committer | snukky <rgrundki@exceed.ed.ac.uk> | 2019-07-27 17:16:49 +0300 |
commit | 01feb431db4d3adc887c266e688bc643f84e7af5 (patch) | |
tree | 2baba6017850ddd9f4b7de8e3656e0348d028a06 | |
parent | 99203c63fb14157033c09ccfc44dab188690a11a (diff) |
Add tests for creating *.spm vocabs
-rwxr-xr-x | data/download-data.sh | 4 | ||||
-rw-r--r-- | tests/sentencepiece/setup.sh | 7 | ||||
-rw-r--r-- | tests/sentencepiece/test_create_joint_spm_vocab.sh | 36 | ||||
-rw-r--r-- | tests/sentencepiece/test_create_spm_vocabs.sh | 41 |
4 files changed, 88 insertions, 0 deletions
diff --git a/data/download-data.sh b/data/download-data.sh index a1e123a..15eed62 100755 --- a/data/download-data.sh +++ b/data/download-data.sh @@ -19,3 +19,7 @@ for file in ${MODEL_FILES[@]}; do fi fi done + +# Get de-BPEed training data +test -s europarl.de-en/corpus.de.gz || pigz -dc europarl.de-en/corpus.bpe.de.gz | sed 's/@@ //g' | pigz > europarl.de-en/corpus.de.gz +test -s europarl.de-en/corpus.en.gz || pigz -dc europarl.de-en/corpus.bpe.en.gz | sed 's/@@ //g' | pigz > europarl.de-en/corpus.en.gz diff --git a/tests/sentencepiece/setup.sh b/tests/sentencepiece/setup.sh new file mode 100644 index 0000000..eff1524 --- /dev/null +++ b/tests/sentencepiece/setup.sh @@ -0,0 +1,7 @@ +# Skip if compiled without SentencePiece +if [ ! $MRT_MARIAN_USE_SENTENCEPIECE ]; then + exit 100 +fi + +test -f $MRT_DATA/europarl.de-en/corpus.en || exit 1 +test -f $MRT_DATA/europarl.de-en/corpus.de || exit 1 diff --git a/tests/sentencepiece/test_create_joint_spm_vocab.sh b/tests/sentencepiece/test_create_joint_spm_vocab.sh new file mode 100644 index 0000000..eeac67b --- /dev/null +++ b/tests/sentencepiece/test_create_joint_spm_vocab.sh @@ -0,0 +1,36 @@ +#!/bin/bash -x + +##################################################################### +# SUMMARY: Create a joint SentencePiece vocabulary +# AUTHOR: snukky +##################################################################### + +# Exit on error +set -e + +# Remove old artifacts and create working directory +rm -rf vocab.joint vocab.joint.*{log,out,diff} +mkdir -p vocab.joint + +# Run marian command +$MRT_MARIAN/marian \ + --no-shuffle --seed 1111 --dim-emb 32 --dim-rnn 64 --maxi-batch 1 --maxi-batch-sort none --after-batches 1 \ + -m vocab.joint/model.npz -t $MRT_DATA/europarl.de-en/corpus.{en,de} \ + --dim-vocabs 8000 -v vocab.joint/vocab.ende.spm vocab.joint/vocab.ende.spm \ + --log vocab.joint.log + +# Check if files exist +test -e vocab.joint/model.npz +test -e vocab.joint/vocab.ende.spm +test -e vocab.joint.log + +# Check logging messages +grep -q "Creating SentencePiece vocabulary.* vocab.ende.spm" vocabs.joint.log +grep -q "Sampling from.* corpus.en.* corpus.de" vocabs.joint.log + +# Extract a textual vocabulary and compare with the expected output +$MRT_MRT/spm_export_vocab --model vocab.joint/vocab.ende.spm > vocab.joint.out +$MRT_TOOLS/diff-nums.py vocab.joint.out vocab.joint.expected -o vocab.joint.diff + +# Exit with success code +exit 0 diff --git a/tests/sentencepiece/test_create_spm_vocabs.sh b/tests/sentencepiece/test_create_spm_vocabs.sh new file mode 100644 index 0000000..700bdc1 --- /dev/null +++ b/tests/sentencepiece/test_create_spm_vocabs.sh @@ -0,0 +1,41 @@ +#!/bin/bash -x + +##################################################################### +# SUMMARY: Create SentencePiece vocabularies +# AUTHOR: snukky +##################################################################### + +# Exit on error +set -e + +# Remove old artifacts and create working directory +rm -rf vocabs vocabs.*{log,out,diff} +mkdir -p vocabs + +# Run marian command +$MRT_MARIAN/marian \ + --no-shuffle --seed 1111 --dim-emb 32 --dim-rnn 64 --maxi-batch 1 --maxi-batch-sort none \ + -m vocabs/model.npz -t $MRT_DATA/europarl.de-en/corpus.{en,de} \ + --dim-vocabs 4000 4000 -v vocabs/vocab.en.spm vocabs/vocab.de.spm \ + --after-batches 1 \ + --log vocabs.log + +# Check if files exist +test -e vocabs/model.npz +test -e vocabs/vocab.en.spm +test -e vocabs/vocab.de.spm +test -e vocabs.log + +# Check logging messages +grep -q "Creating SentencePiece vocabulary.* vocabs.en.spm" vocabs.log +grep -q "Creating SentencePiece vocabulary.* vocabs.de.spm" vocabs.log + +# Extract a textual vocabulary and compare with the expected output +$MRT_MRT/spm_export_vocab --model vocabs/vocab.en.spm > vocabs.en.out +$MRT_TOOLS/diff-nums.py vocabs.en.out vocabs.en.expected -o vocabs.en.diff + +$MRT_MRT/spm_export_vocab --model vocabs/vocab.de.spm > vocabs.de.out +$MRT_TOOLS/diff-nums.py vocabs.de.out vocabs.de.expected -o vocabs.de.diff + +# Exit with success code +exit 0 |