forked from espnet/espnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f51838
commit f7f09b5
Showing
3 changed files
with
37 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bats | ||
# -*- mode:sh -*- | ||
|
||
setup() { | ||
tmpdir=$(mktemp -d test_spm.XXXXXX) | ||
echo $tmpdir | ||
} | ||
|
||
teardown() { | ||
rm -rf $tmpdir | ||
} | ||
|
||
@test "spm_xxx" { | ||
testfile=test/tedlium2.txt | ||
nbpe=100 | ||
bpemode=unigram | ||
bpemodel=$tmpdir/test_spm | ||
|
||
utils/spm_train --user_defined_symbols --input=${testfile} --vocab_size=${nbpe} --model_type=${bpemode} \ | ||
--model_prefix=${bpemodel} --input_sentence_size=100000000 \ | ||
--character_coverage=1.0 --bos_id=-1 --eos_id=-1 \ | ||
--unk_id=0 --user_defined_symbols=[laughter],[noise],[vocalized-noise] | ||
|
||
diff ${bpemodel}.vocab test/tedlium2.vocab | ||
|
||
txt="test sentencepiece.[noise]" | ||
|
||
enc=$(echo $txt | utils/spm_encode --model=${bpemodel}.model --output_format=piece) | ||
[ "$enc" = "▁ te s t ▁ s en t en c e p ie c e . [noise]" ] | ||
|
||
dec=$(echo $enc | utils/spm_decode --model=${bpemodel}.model --input_format=piece) | ||
[ "$dec" = "$txt" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
#!/usr/bin/env python | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the license found in the | ||
# https://github.com/pytorch/fairseq/blob/master/LICENSE | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import shlex | ||
import sys | ||
|
||
import sentencepiece as spm | ||
|
||
|
||
if __name__ == "__main__": | ||
spm.SentencePieceTrainer.Train(" ".join(map(shlex.quote, sys.argv[1:])).replace("\'", "")) | ||
spm.SentencePieceTrainer.Train(" ".join(sys.argv[1:])) |