-
Couldn't load subscription status.
- Fork 376
Bilingual Japanese / English zipformer recipe (multi_ja_en) and MLS English recipe (mls_english) #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Bilingual Japanese / English zipformer recipe (multi_ja_en) and MLS English recipe (mls_english) #2015
Changes from 135 commits
28f6545
ac0c0ed
a1fc642
defc71b
efe015d
8c1c710
8985259
a34d34a
ce44150
68e3cea
d6e3c98
4ca8ee9
59519a4
f2e0171
fa84782
abebb6a
c83b115
61e81bf
3751441
6d71d9c
5417e09
782e1fb
f4b2987
a8ecb16
3307836
2f1c611
eafbd64
b167ac7
ad1be22
78ee595
fd3fbe6
c77a847
cdf246c
f3e59df
ddc2daa
f6ad423
19b62c0
5f2f684
70a7940
df923f3
5ec9389
de35cc2
f51621b
4e92879
093a035
0f700ed
d5cc030
aee7b87
310aaec
542620c
f7fec4a
154ef43
6012edb
dc4db37
9d93d63
aed139f
dbd8977
1c5d792
c92c606
ba6d8e8
0ab0274
1b8a306
e76b749
313afea
c532a50
24db8c1
996334f
fe88d1d
a8f45bc
eb2168b
2504b23
73dea24
0e86ef8
06e4291
7d462aa
31a37c7
99db0e4
8b035a0
7bea23e
2265e1a
5682978
1093e78
1b1a317
68bff93
b25254f
d136086
b6d43a4
9c318da
065ca31
0a4ed5e
1ddd3cd
606789b
76bae70
ac94174
9c91775
694ecb9
d7ee48e
1996507
ed2c0a4
5fb4bdf
1cf544b
c610c6d
6272827
aeffb15
4475815
a310d8f
60f326b
95f58e6
865b859
b19929c
2f1f419
7b4abba
8dd2c0f
94cf8c3
0ca7595
11df2a8
2d8e3fd
f15a783
c23af2e
ed79fa3
636121c
0967f5f
f210002
ee2a6d6
dee07de
f9ceead
4e05d70
130c2a5
5400f43
8c08c9c
8e18616
556a3f0
36fc1f1
7231cf4
a4c1db5
2859c22
9a940c3
f64a706
ef7664e
bc2560c
ecbe985
a30e80c
9d389cd
8c84639
d74e232
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Introduction | ||
|
|
||
|
|
||
|
|
||
| **Multilingual LibriSpeech (MLS)** is a large multilingual corpus suitable for speech research. The dataset is derived from read audiobooks from LibriVox and consists of 8 languages - English, German, Dutch, Spanish, French, Italian, Portuguese, Polish. It includes about 44.5K hours of English and a total of about 6K hours for other languages. This icefall training recipe was created for the restructured version of the English split of the dataset available on Hugging Face below. | ||
|
|
||
|
|
||
| The dataset is available on Hugging Face. For more details, please visit: | ||
|
|
||
| - Dataset: https://huggingface.co/datasets/parler-tts/mls_eng | ||
| - Original MLS dataset link: https://www.openslr.org/94 | ||
|
|
||
|
|
||
| ## On-the-fly feature computation | ||
|
|
||
| This recipe currently only supports on-the-fly feature bank computation, since `lhotse` manifests and feature banks are not pre-calculated in this recipe. This should mean that the dataset can be streamed from Hugging Face, but we have not tested this yet. We may add a version that supports pre-calculating features to better match existing recipes.\ | ||
| <br> | ||
|
|
||
| [./RESULTS.md](./RESULTS.md) contains the latest results. This MLS English recipe was primarily developed for use in the ```multi_ja_en``` Japanese-English bilingual pipeline, which is based on MLS English and ReazonSpeech. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| ## Results | ||
|
|
||
| ### MLS-English training results (Non-streaming) on zipformer model | ||
|
|
||
| #### Non-streaming | ||
|
|
||
| **WER on Test Set (Epoch 20)** | ||
|
|
||
| | Type | Greedy | Beam search | | ||
| |---------------|--------|-------------| | ||
| | Non-streaming | 6.65 | 6.57 | | ||
|
|
||
|
|
||
| The training command: | ||
|
|
||
| ``` | ||
| ./zipformer/train.py \ | ||
| --world-size 8 \ | ||
| --num-epochs 20 \ | ||
| --start-epoch 9 \ | ||
| --use-fp16 1 \ | ||
| --exp-dir zipformer/exp \ | ||
| --lang-dir data/lang/bpe_2000/ | ||
| ``` | ||
|
|
||
| The decoding command: | ||
|
|
||
| ``` | ||
| ./zipformer/decode.py \ | ||
| --epoch 20 \ | ||
| --exp-dir ./zipformer/exp \ | ||
| --lang-dir data/lang/bpe_2000/ \ | ||
| --decoding-method greedy_search | ||
| ``` | ||
|
|
||
|
|
||
| The pre-trained model is available here : [reazon-research/mls-english | ||
| ](https://huggingface.co/reazon-research/mls-english) | ||
|
|
||
|
|
||
| Please note that this recipe was developed primarily as the source of English input in the bilingual Japanese-English recipe `multi_ja_en`, which uses ReazonSpeech and MLS English. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| RecordingSet, | ||
| SupervisionSet, | ||
| ) | ||
| from lhotse.utils import is_module_available | ||
|
|
||
| # fmt: on | ||
|
|
||
|
|
@@ -48,55 +49,54 @@ | |
|
|
||
|
|
||
| def make_cutset_blueprints( | ||
| manifest_dir: Path, | ||
| mls_eng_hf_dataset_path: str = "parler-tts/mls_eng", | ||
| ) -> List[Tuple[str, CutSet]]: | ||
| cut_sets = [] | ||
|
|
||
| if not is_module_available("datasets"): | ||
| raise ImportError( | ||
| "To process the MLS English HF corpus, please install optional dependency: pip install datasets" | ||
| ) | ||
|
|
||
| from datasets import load_dataset | ||
|
|
||
| print(f"{mls_eng_hf_dataset_path=}") | ||
| dataset = load_dataset(str(mls_eng_hf_dataset_path)) | ||
|
|
||
| # Create test dataset | ||
| logging.info("Creating test cuts.") | ||
| cut_sets.append( | ||
| ( | ||
| "test", | ||
| CutSet.from_manifests( | ||
| recordings=RecordingSet.from_file( | ||
| manifest_dir / "reazonspeech_recordings_test.jsonl.gz" | ||
| ), | ||
| supervisions=SupervisionSet.from_file( | ||
| manifest_dir / "reazonspeech_supervisions_test.jsonl.gz" | ||
| ), | ||
| ), | ||
| CutSet.from_huggingface_dataset(dataset["test"], text_key="transcript"), | ||
| ) | ||
| ) | ||
|
|
||
| # Create dev dataset | ||
| logging.info("Creating dev cuts.") | ||
| cut_sets.append( | ||
| ( | ||
| "dev", | ||
| CutSet.from_manifests( | ||
| recordings=RecordingSet.from_file( | ||
| manifest_dir / "reazonspeech_recordings_dev.jsonl.gz" | ||
| ), | ||
| supervisions=SupervisionSet.from_file( | ||
| manifest_dir / "reazonspeech_supervisions_dev.jsonl.gz" | ||
| try: | ||
| cut_sets.append( | ||
| ( | ||
| "dev", | ||
| CutSet.from_huggingface_dataset(dataset["dev"], text_key="transcript"), | ||
| ) | ||
| ) | ||
| except KeyError: | ||
| cut_sets.append( | ||
| ( | ||
| "dev", | ||
| CutSet.from_huggingface_dataset( | ||
| dataset["validation"], text_key="transcript" | ||
| ), | ||
| ), | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| # Create train dataset | ||
| logging.info("Creating train cuts.") | ||
| cut_sets.append( | ||
| ( | ||
| "train", | ||
| CutSet.from_manifests( | ||
| recordings=RecordingSet.from_file( | ||
| manifest_dir / "reazonspeech_recordings_train.jsonl.gz" | ||
| ), | ||
| supervisions=SupervisionSet.from_file( | ||
| manifest_dir / "reazonspeech_supervisions_train.jsonl.gz" | ||
| ), | ||
| ), | ||
| CutSet.from_huggingface_dataset(dataset["train"], text_key="transcript"), | ||
| ) | ||
| ) | ||
| return cut_sets | ||
|
|
@@ -107,6 +107,8 @@ def get_args(): | |
| formatter_class=argparse.ArgumentDefaultsHelpFormatter, | ||
| ) | ||
| parser.add_argument("-m", "--manifest-dir", type=Path) | ||
| parser.add_argument("-a", "--audio-dir", type=Path) | ||
| parser.add_argument("-d", "--dl-dir", type=Path) | ||
| return parser.parse_args() | ||
|
Comment on lines
+110
to
112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix --dl-dir semantics and resolve the actual dataset path; current code will miss the downloaded ‘mls_english’ subdir. The downloader writes to <dl_dir>/mls_english, but main() passes args.dl_dir directly to load_dataset(), causing failures. Also mark required args. @@
- parser.add_argument("-m", "--manifest-dir", type=Path)
- parser.add_argument("-a", "--audio-dir", type=Path)
- parser.add_argument("-d", "--dl-dir", type=Path)
+ parser.add_argument("-m", "--manifest-dir", type=Path, required=True,
+ help="Directory for manifests and features.")
+ parser.add_argument("-a", "--audio-dir", type=Path, required=True,
+ help="Directory to materialize audio shards.")
+ parser.add_argument("-d", "--dl-dir", type=Path, required=True,
+ help="Base download dir (expects '<dl-dir>/mls_english') or a local HF dataset dir or an HF repo-id.")
@@
- mls_eng_hf_dataset_path = args.dl_dir # "/root/datasets/parler-tts--mls_eng"
- cut_sets = make_cutset_blueprints(mls_eng_hf_dataset_path)
+ # Accept: (1) <dl-dir>/mls_english from our downloader,
+ # (2) a direct local HF dataset dir, or
+ # (3) a repo-id string (if user passes one).
+ if args.dl_dir.is_dir():
+ candidate = args.dl_dir / "mls_english"
+ mls_eng_hf_dataset_path = candidate if candidate.exists() else args.dl_dir
+ else:
+ mls_eng_hf_dataset_path = args.dl_dir # repo-id string allowed
+ cut_sets = make_cutset_blueprints(str(mls_eng_hf_dataset_path))Also applies to: 132-134 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
|
|
@@ -120,26 +122,33 @@ def main(): | |
|
|
||
| logging.basicConfig(format=formatter, level=logging.INFO) | ||
|
|
||
| if (args.manifest_dir / ".reazonspeech-fbank.done").exists(): | ||
| if (args.manifest_dir / ".mls-eng-fbank.done").exists(): | ||
| logging.info( | ||
| "Previous fbank computed for ReazonSpeech found. " | ||
| f"Delete {args.manifest_dir / '.reazonspeech-fbank.done'} to allow recomputing fbank." | ||
| "Previous fbank computed for MLS English found. " | ||
| f"Delete {args.manifest_dir / '.mls-eng-fbank.done'} to allow recomputing fbank." | ||
| ) | ||
| return | ||
| else: | ||
| cut_sets = make_cutset_blueprints(args.manifest_dir) | ||
| mls_eng_hf_dataset_path = args.dl_dir # "/root/datasets/parler-tts--mls_eng" | ||
| cut_sets = make_cutset_blueprints(mls_eng_hf_dataset_path) | ||
| for part, cut_set in cut_sets: | ||
| logging.info(f"Processing {part}") | ||
| cut_set = cut_set.save_audios( | ||
| num_jobs=num_jobs, | ||
| storage_path=(args.audio_dir / part).as_posix(), | ||
| ) # makes new cutset that loads audio from paths to actual audio files | ||
|
|
||
| cut_set = cut_set.compute_and_store_features( | ||
| extractor=extractor, | ||
| num_jobs=num_jobs, | ||
| storage_path=(args.manifest_dir / f"feats_{part}").as_posix(), | ||
| storage_type=LilcomChunkyWriter, | ||
| ) | ||
| cut_set.to_file(args.manifest_dir / f"reazonspeech_cuts_{part}.jsonl.gz") | ||
|
|
||
| logging.info("All fbank computed for ReazonSpeech.") | ||
| (args.manifest_dir / ".reazonspeech-fbank.done").touch() | ||
| cut_set.to_file(args.manifest_dir / f"mls_eng_cuts_{part}.jsonl.gz") | ||
|
|
||
| logging.info("All fbank computed for MLS English.") | ||
| (args.manifest_dir / ".mls-eng-fbank.done").touch() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../librispeech/ASR/local/compute_fbank_musan.py |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,114 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env python3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Copyright 2021 Xiaomi Corp. (authors: Fangjun Kuang) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Copyright 2024 Xiaomi Corp. (authors: Xiaoyu Yang) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # See ../../../../LICENSE for clarification regarding multiple authors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # limitations under the License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # You can install sentencepiece via: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # pip install sentencepiece | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Due to an issue reported in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # https://github.com/google/sentencepiece/pull/642#issuecomment-857972030 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Please install a version >=0.1.96 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import argparse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import shutil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import sentencepiece as spm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_args(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser = argparse.ArgumentParser() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser.add_argument( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--lang-dir", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type=str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| help="""Input and output directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| The generated bpe.model is saved to this directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser.add_argument( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--byte-fallback", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| action="store_true", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| help="""Whether to enable byte_fallback when training bpe.""", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser.add_argument( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--character-coverage", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type=float, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| default=1.0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| help="Character coverage in vocabulary.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser.add_argument( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--transcript", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type=str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| help="Training transcript.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser.add_argument( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--vocab-size", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type=int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| help="Vocabulary size for BPE training", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return parser.parse_args() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
kinanmartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def main(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args = get_args() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vocab_size = args.vocab_size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lang_dir = Path(args.lang_dir) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model_type = "bpe" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model_prefix = f"{lang_dir}/{model_type}_{vocab_size}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| train_text = args.transcript | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input_sentence_size = 100000000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user_defined_symbols = ["<blk>", "<sos/eos>"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unk_id = len(user_defined_symbols) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Note: unk_id is fixed to 2. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # If you change it, you should also change other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # places that are using it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model_file = Path(model_prefix + ".model") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not model_file.is_file(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| spm.SentencePieceTrainer.train( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input=train_text, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vocab_size=vocab_size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model_type=model_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model_prefix=model_prefix, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input_sentence_size=input_sentence_size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| character_coverage=args.character_coverage, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user_defined_symbols=user_defined_symbols, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| byte_fallback=args.byte_fallback, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unk_id=unk_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bos_id=-1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eos_id=-1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"{model_file} exists - skipping") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shutil.copyfile(model_file, f"{lang_dir}/bpe.model") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+91
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Always sync bpe_.model to bpe.model, even when training is skipped. Currently, if the versioned model exists, you return early without copying, leaving bpe.model stale/missing. - if not model_file.is_file():
+ if not model_file.is_file():
spm.SentencePieceTrainer.train(
input=train_text,
@@
)
- else:
- print(f"{model_file} exists - skipping")
- return
-
- shutil.copyfile(model_file, f"{lang_dir}/bpe.model")
+ else:
+ print(f"{model_file} exists - skipping training")
+ # Ensure canonical symlink/copy is updated
+ shutil.copyfile(model_file, f"{lang_dir}/bpe.model")📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| main() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This URL leads to a 404 page. Can you make it public?