-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for VITS (multilingual TTS) (#466)
* Add custom VITS tokenizer converter * Do not decode if expected input_ids is empty * Update vits tokenizer tests * Implement `VitsTokenizer` * Add support for VITS model * Support VITS through pipeline API * Update JSDoc * Add TTS unit test * Add speecht5 unit test * Fix typo * Fix typo * Update speecht5 model id * Add note about using quantized speecht5 in unit tests * Monkey-patch `BigInt64Array` and `BigUint64Array`
- Loading branch information
Showing
12 changed files
with
336 additions
and
6 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
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,100 @@ | ||
|
||
|
||
def generate_tokenizer_json(tokenizer): | ||
vocab = tokenizer.get_vocab() | ||
|
||
normalizers = [] | ||
|
||
if tokenizer.normalize: | ||
# Lowercase the input string | ||
normalizers.append({ | ||
"type": "Lowercase", | ||
}) | ||
|
||
if tokenizer.language == 'ron': | ||
# Replace diacritics | ||
normalizers.append({ | ||
"type": "Replace", | ||
"pattern": { | ||
"String": "ț", | ||
}, | ||
"content": "ţ", | ||
}) | ||
|
||
if tokenizer.phonemize: | ||
raise NotImplementedError("Phonemization is not implemented yet") | ||
|
||
elif tokenizer.normalize: | ||
# strip any chars outside of the vocab (punctuation) | ||
chars = ''.join(x for x in vocab if len(x) == 1) | ||
escaped = chars.replace('-', r'\-').replace(']', r'\]') | ||
normalizers.append({ | ||
"type": "Replace", | ||
"pattern": { | ||
"Regex": f"[^{escaped}]", | ||
}, | ||
"content": "", | ||
}) | ||
normalizers.append({ | ||
"type": "Strip", | ||
"strip_left": True, | ||
"strip_right": True, | ||
}) | ||
|
||
if tokenizer.add_blank: | ||
# add pad token between each char | ||
normalizers.append({ | ||
"type": "Replace", | ||
"pattern": { | ||
# Add a blank token between each char, except when blank (then do nothing) | ||
"Regex": "(?=.)|(?<!^)$", | ||
}, | ||
"content": tokenizer.pad_token, | ||
}) | ||
|
||
if len(normalizers) == 0: | ||
normalizer = None | ||
elif len(normalizers) == 1: | ||
normalizer = normalizers[0] | ||
else: | ||
normalizer = { | ||
"type": "Sequence", | ||
"normalizers": normalizers, | ||
} | ||
|
||
tokenizer_json = { | ||
"version": "1.0", | ||
"truncation": None, | ||
"padding": None, | ||
"added_tokens": [ | ||
{ | ||
"id": vocab[token], | ||
"content": token, | ||
"single_word": False, | ||
"lstrip": False, | ||
"rstrip": False, | ||
"normalized": False, | ||
"special": True | ||
} | ||
for token in vocab | ||
|
||
# `tokenizer.pad_token` should not be considered an added token | ||
if token in (tokenizer.unk_token, ) | ||
], | ||
"normalizer": normalizer, | ||
"pre_tokenizer": { | ||
"type": "Split", | ||
"pattern": { | ||
"Regex": "" | ||
}, | ||
"behavior": "Isolated", | ||
"invert": False | ||
}, | ||
"post_processor": None, | ||
"decoder": None, # Custom decoder implemented in JS | ||
"model": { | ||
"vocab": vocab | ||
}, | ||
} | ||
|
||
return tokenizer_json |
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
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
Oops, something went wrong.