ZONOS3-Mini-hf / tests /test_languages.py
Gatozu35's picture
Align language support and model card with ZONOS3-Mini
e39d30d
Raw History Blame Contribute Delete
2.5 kB
"""Request-language regressions for the Transformers wrapper (no checkpoint tensors required)."""
from pathlib import Path
import unittest
import torch
from transformers import AutoConfig
from transformers.dynamic_module_utils import get_class_from_dynamic_module
ROOT = Path(__file__).resolve().parents[1]
PASSTHROUGH_LANGUAGES = (
"ar", "bn", "bg", "cs", "da", "nl", "fi", "ka", "el", "gu", "he", "hi", "hu", "id", "kn", "ms", "ml",
"mr", "no", "or", "pl", "pa", "ro", "ru", "sk", "sv", "tl", "ta", "te", "th", "tr", "uk", "ur", "vi",
)
class LanguageTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
model_class = get_class_from_dynamic_module("modeling_zonos3.Zonos3MiniForTextToSpeech", str(ROOT))
checkpoint_config = AutoConfig.from_pretrained(ROOT, trust_remote_code=True)
with torch.device("meta"):
cls.models = {
"checkpoint": model_class(checkpoint_config),
"defaults": model_class(model_class.config_class()),
}
def test_languages_without_grammars_preserve_script_numbers_and_markup(self):
text = "नमस्ते दुनिया!\r\n 123\t$5.32 [laugh]"
expected = "नमस्ते दुनिया! 123 $5.32 [laugh]"
for source, model in self.models.items():
for language in PASSTHROUGH_LANGUAGES:
with self.subTest(config=source, language=language):
self.assertEqual(model.normalize_text(text, language=language), expected)
def test_request_locales_accept_case_whitespace_and_dashes(self):
for source, model in self.models.items():
for language in (" EN-US ", "en-GB", "FR-FR", "PT-BR", " CMN ", " HI ", "TE", "NO"):
with self.subTest(config=source, language=language):
self.assertEqual(
model.normalize_text("One\n two\tthree.", language=language, text_normalization=False),
"One two three.",
)
def test_unsupported_languages_are_rejected_even_without_normalization(self):
for source, model in self.models.items():
for enabled in (False, True):
with self.subTest(config=source, text_normalization=enabled):
with self.assertRaises(ValueError):
model.normalize_text("Hello", language="klingon", text_normalization=enabled)
if __name__ == "__main__":
unittest.main()