sp
Author: Heli Qi Affiliation: NAIST Date: 2022.07
SentencePieceTokenizer
Bases: Tokenizer
Tokenizer implementation that converts the input sentence string into subword tokens, i.e., combinations of graphemes, by the sentencepiece package.
References: https://github.com/google/sentencepiece
Source code in speechain/tokenizer/sp.py
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
tensor2text(tensor)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor
|
LongTensor or List
|
|
required |
Returns:
Source code in speechain/tokenizer/sp.py
text2tensor(text, no_sos=False, no_eos=False, return_tensor=True)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
|
required |
no_sos
|
bool
|
|
False
|
no_eos
|
bool
|
|
False
|
return_tensor
|
bool
|
|
True
|
Returns:
Source code in speechain/tokenizer/sp.py
tokenizer_init_fn(token_path, copy_path=None, **kwargs)
Initialize the sentencepiece tokenizer model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
copy_path
|
str
|
str = None The path where you want to paste the given tokenizer model as a backup. If not given, no backup will be saved. |
None
|
token_path
|
str
|
str The path of your specified sentencepiece tokenizer model file. If not given, the model will automatically selected in the same folder as the given token_vocab |
required |