Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_create_spm_vocabs.sh « sentencepiece « tests - github.com/marian-nmt/marian-regression-tests.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2781964913d3b3f688384a8e76c021a4e6a7d4d2 (plain)
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
#!/bin/bash -x

#####################################################################
# SUMMARY: Create SentencePiece vocabularies
# AUTHOR: snukky
# TAGS: sentencepiece
#####################################################################

# 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.small.{en,de}.gz \
    --dim-vocabs 4000 4000 -v vocabs/vocab.en.spm vocabs/vocab.de.spm --sentencepiece-options "--num_threads=1" \
    --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 "Training SentencePiece vocabulary .*vocab.en.spm" vocabs.log
grep -q "Training SentencePiece vocabulary .*vocab.de.spm" vocabs.log
grep -q "Setting vocabulary size .* to 4,\?000" vocabs.log
grep -q "Loading SentencePiece vocabulary .*vocab.en.spm" vocabs.log
grep -q "Loading SentencePiece vocabulary .*vocab.de.spm" vocabs.log

# Extract a textual vocabulary and compare with the expected output
LC_ALL=C $MRT_MARIAN/spm_export_vocab --model vocabs/vocab.en.spm | head -n 3980 | sort > vocabs.en.out
LC_ALL=C $MRT_MARIAN/spm_export_vocab --model vocabs/vocab.de.spm | sort > vocabs.de.out

$MRT_TOOLS/diff-nums.py vocabs.en.out vocabs.en.expected -o vocabs.en.diff
$MRT_TOOLS/diff-nums.py vocabs.de.out vocabs.de.expected -o vocabs.de.diff

# Exit with success code
exit 0