Datasets:
Download eval/tests/test_ctc.py from fishaudio/nanori: direct link, hf CLI and curl.
- Browser
- Download file 1.74 kB
-
https://huggingface.co/datasets/fishaudio/nanori/resolve/main/eval/tests/test_ctc.py
- Command line
-
hf download hf://datasets/fishaudio/nanori/eval/tests/test_ctc.py
-
curl -L -o test_ctc.py https://huggingface.co/datasets/fishaudio/nanori/resolve/main/eval/tests/test_ctc.py
1.74 kB
| """kana CTC judge: text side and pins (no model download; the scoring itself is checked by acceptance/check_ctc.py).""" | |
| import hashlib | |
| import os | |
| import pytest | |
| from conftest import make_item | |
| from nanori_eval import constants as C | |
| from nanori_eval.items import normalise | |
| HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| def test_ctc_text_is_the_frozen_copy(): | |
| # pinned sha256 of the shipped text module (acceptance/check_ctc.py compares its code with the frozen scorer) | |
| with open(os.path.join(HERE, 'nanori_eval', 'ctc_text.py'), 'rb') as f: | |
| assert hashlib.sha256(f.read()).hexdigest() == '1cf086c05019b27118e1b48f7c6eb001e57bdd7c9f30f0137fb3c21e7837f619' | |
| def test_pins(): | |
| assert C.CTC_MODEL['id'] == 'vumichien/wav2vec2-large-xlsr-japanese-hiragana' | |
| assert C.CTC_MODEL['revision'].startswith('017225bb') | |
| assert C.CTC_MODEL['files']['model.safetensors'].startswith('a109c55d') | |
| def test_case_of(): | |
| pytest.importorskip('pyopenjtalk') | |
| from nanori_eval.ctc import case_of | |
| it = normalise(make_item('X-1', 'JA-PLACE', 'P-H/F1', accepted=('ぽぽろ', 'ぽぽら'), known_wrong=('ぼぼろ',))) | |
| c = case_of(it) | |
| t = c['targets'][0] | |
| assert t['expected'] == {'kana': 'ぽぽろ'} and t['accepted_alternatives'] == ['ぽぽら'] | |
| assert t['known_wrong'] == ['ぼぼろ'] and c['infer_text'] == it['text'] | |
| def test_verify_model_dir_rejects_wrong_files(tmp_path): | |
| pytest.importorskip('numpy') | |
| pytest.importorskip('pyopenjtalk') # nanori_eval.ctc needs the [ctc] extra | |
| from nanori_eval import ctc | |
| for name in C.CTC_MODEL['files']: | |
| (tmp_path / name).write_bytes(b'x') | |
| with pytest.raises(SystemExit): | |
| ctc.verify_model_dir(str(tmp_path)) | |