Skip to content
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

Merge japanese-to-english multilingual branch #1860

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5062f12
add streaming support to reazonresearch
Aug 1, 2024
5a0c247
update README for streaming
Aug 1, 2024
62eb090
update streaming decoding file
Aug 1, 2024
6317405
update streaming decode
Aug 1, 2024
2d2daf6
remove streaming/greedy_search results folder
Aug 1, 2024
e052481
update for streaming
Aug 1, 2024
529d92f
Add docker images for torch 2.4 (#1704)
csukuangfj Jul 25, 2024
8189d11
remove prints
Aug 1, 2024
916e84d
resolve PR issue
Aug 1, 2024
707a956
Add multi_ja_en
Sep 14, 2024
2e355a8
Update README.md
baileyeet Sep 14, 2024
b6af607
Update README.md
baileyeet Dec 24, 2024
7aedda0
Update RESULTS.md
baileyeet Dec 24, 2024
7b1445b
Update RESULTS.md
baileyeet Dec 25, 2024
4a55a10
Update RESULTS.md
baileyeet Dec 25, 2024
1bc7f07
Delete egs/multi_ja_en/ASR/zipformer/streaming/greedy_search directory
baileyeet Dec 25, 2024
68e1c3c
formatting
baileyeet Nov 25, 2024
a2bb272
formatting
baileyeet Nov 25, 2024
4604be8
add onnx decode
baileyeet Dec 25, 2024
f421001
remove unnecessary folders
baileyeet Dec 25, 2024
564b632
fix repeated definition of tokenize_by_ja_char
baileyeet Jan 7, 2025
5c142d4
Merge branch 'master' into einichi
baileyeet Jan 7, 2025
8a3790c
clean up files
baileyeet Jan 8, 2025
9d6211e
remove test
baileyeet Jan 8, 2025
84c91db
edit prepare.sh
baileyeet Jan 14, 2025
1244de9
update python ver
baileyeet Jan 14, 2025
aa74f6c
update python ver
baileyeet Jan 14, 2025
b574e68
udpate symlink
baileyeet Jan 14, 2025
9ab3021
Reformatted streaming_decode.py with flake8
baileyeet Jan 14, 2025
3eec244
Update RESULTS.md
baileyeet Jan 20, 2025
efc0536
Merge branch 'k2-fsa:master' into einichi
baileyeet Jan 27, 2025
50c3270
Update generate_build_matrix.py
JinZr Jan 28, 2025
b8ce806
Update build-docker-image.yml
JinZr Jan 28, 2025
5cf7e42
Update zipformer.py
JinZr Jan 28, 2025
1cb4594
Update zipformer.py
JinZr Jan 28, 2025
b9efbf8
Update utils.py
JinZr Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/scripts/docker/generate_build_matrix.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please avoid unnecessary modifications to built-in files

Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ def get_torchaudio_version(torch_version):
return torch_version



def get_matrix(min_torch_version):
k2_version = "1.24.4.dev20241029"
kaldifeat_version = "1.25.5.dev20241029"
version = "20241218"

# torchaudio 2.5.0 does not support python 3.13

python_version = ["3.8", "3.9", "3.10", "3.11", "3.12"]
torch_version = []
torch_version += ["1.13.0", "1.13.1"]
Expand All @@ -67,6 +69,7 @@ def get_matrix(min_torch_version):
# Test only torch >= 2.3.0
torch_version += ["2.3.0", "2.3.1"]
torch_version += ["2.4.0"]

torch_version += ["2.4.1"]
torch_version += ["2.5.0"]
torch_version += ["2.5.1"]
Expand All @@ -93,6 +96,7 @@ def get_matrix(min_torch_version):
# torch>=2.5 requires python 3.10
continue


if t == "2.5.1":
k2_version_2 = "1.24.4.dev20241122"
kaldifeat_version_2 = "1.25.5.dev20241126"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-docker-image.yml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please avoid unnecessary modifications to built-in files, thanks

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]

image: ["torch2.4.1-cuda12.4", "torch2.4.1-cuda12.1", "torch2.4.1-cuda11.8", "torch2.4.0-cuda12.4", "torch2.4.0-cuda12.1", "torch2.4.0-cuda11.8", "torch2.3.1-cuda12.1", "torch2.3.1-cuda11.8", "torch2.2.2-cuda12.1", "torch2.2.2-cuda11.8", "torch2.2.1-cuda12.1", "torch2.2.1-cuda11.8", "torch2.2.0-cuda12.1", "torch2.2.0-cuda11.8", "torch2.1.0-cuda12.1", "torch2.1.0-cuda11.8", "torch2.0.0-cuda11.7", "torch1.13.0-cuda11.6", "torch1.12.1-cuda11.3", "torch1.9.0-cuda10.2"]


steps:
# refer to https://github.com/actions/checkout
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion egs/librispeech/ASR/zipformer/zipformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2459,4 +2459,4 @@ def _test_zipformer_main(causal: bool = False):
torch.set_num_threads(1)
torch.set_num_interop_threads(1)
_test_zipformer_main(False)
_test_zipformer_main(True)
_test_zipformer_main(True)
17 changes: 17 additions & 0 deletions egs/multi_ja_en/ASR/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Introduction

A bilingual Japanese-English ASR model that utilizes ReazonSpeech, developed by the developers of ReazonSpeech.

**ReazonSpeech** is an open-source dataset that contains a diverse set of natural Japanese speech, collected from terrestrial television streams. It contains more than 35,000 hours of audio.


# Included Training Sets

1. LibriSpeech (English)
2. ReazonSpeech (Japanese)

|Datset| Number of hours| URL|
|---|---:|---|
|**TOTAL**|35,960|---|
|LibriSpeech|960|https://www.openslr.org/12/|
|ReazonSpeech (all) |35,000|https://huggingface.co/datasets/reazon-research/reazonspeech|
51 changes: 51 additions & 0 deletions egs/multi_ja_en/ASR/RESULTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
## Results

### Zipformer

#### Non-streaming

The training command is:

```shell
./zipformer/train.py \
--bilingual 1 \
--world-size 4 \
--num-epochs 30 \
--start-epoch 1 \
--use-fp16 1 \
--exp-dir zipformer/exp \
--max-duration 600
```

The decoding command is:

```shell
./zipformer/decode.py \
--epoch 28 \
--avg 15 \
--exp-dir ./zipformer/exp \
--max-duration 600 \
--decoding-method greedy_search
```

To export the model with onnx:

```shell
./zipformer/export-onnx.py --tokens data/lang_bbpe_2000/tokens.txt --use-averaged-model 0 --epoch 35 --avg 1 --exp-dir zipformer/exp --num-encoder-layers "2,2,3,4,3,2" --downsampling-factor "1,2,4,8,4,2" --feedforward-dim "512,768,1024,1536,1024,768" --num-heads "4,4,4,8,4,4" --encoder-dim "192,256,384,512,384,256" --query-head-dim 32 --value-head-dim 12 --pos-head-dim 4 --pos-dim 48 --encoder-unmasked-dim "192,192,256,256,256,192" --cnn-module-kernel "31,31,15,15,15,31" --decoder-dim 512 --joiner-dim 512 --causal False --chunk-size "16,32,64,-1" --left-context-frames "64,128,256,-1" --fp16 True
```
Word Error Rates (WERs) listed below:

| Datasets | ReazonSpeech | ReazonSpeech | LibriSpeech | LibriSpeech |
|----------------------|--------------|---------------|--------------------|-------------------|
| Zipformer WER (%) | dev | test | test-clean | test-other |
| greedy_search | 5.9 | 4.07 | 3.46 | 8.35 |
| modified_beam_search | 4.87 | 3.61 | 3.28 | 8.07 |
| fast_beam_search | 41.04 | 36.59 | 16.14 | 22.0 |


Character Error Rates (CERs) for Japanese listed below:
| Decoding Method | In-Distribution CER | JSUT | CommonVoice | TEDx |
| :------------------: | :-----------------: | :--: | :---------: | :---: |
| greedy search | 12.56 | 6.93 | 9.75 | 9.67 |
| modified beam search | 11.59 | 6.97 | 9.55 | 9.51 |

146 changes: 146 additions & 0 deletions egs/multi_ja_en/ASR/local/compute_fbank_reazonspeech.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/usr/bin/env python3
# Copyright 2023 The University of Electro-Communications (Author: Teo Wen Shen) # noqa
#
# 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.


import argparse
import logging
import os
from pathlib import Path
from typing import List, Tuple

import torch

# fmt: off
from lhotse import ( # See the following for why LilcomChunkyWriter is preferred; https://github.com/k2-fsa/icefall/pull/404; https://github.com/lhotse-speech/lhotse/pull/527
CutSet,
Fbank,
FbankConfig,
LilcomChunkyWriter,
RecordingSet,
SupervisionSet,
)

# fmt: on

# Torch's multithreaded behavior needs to be disabled or
# it wastes a lot of CPU and slow things down.
# Do this outside of main() in case it needs to take effect
# even when we are not invoking the main (e.g. when spawning subprocesses).
torch.set_num_threads(1)
torch.set_num_interop_threads(1)

RNG_SEED = 42
concat_params = {"gap": 1.0, "maxlen": 10.0}


def make_cutset_blueprints(
manifest_dir: Path,
) -> List[Tuple[str, CutSet]]:
cut_sets = []

# 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"
),
),
)
)

# 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"
),
),
)
)

# 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"
),
),
)
)
return cut_sets


def get_args():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("-m", "--manifest-dir", type=Path)
return parser.parse_args()


def main():
args = get_args()

extractor = Fbank(FbankConfig(num_mel_bins=80))
num_jobs = min(16, os.cpu_count())

formatter = "%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s"

logging.basicConfig(format=formatter, level=logging.INFO)

if (args.manifest_dir / ".reazonspeech-fbank.done").exists():
logging.info(
"Previous fbank computed for ReazonSpeech found. "
f"Delete {args.manifest_dir / '.reazonspeech-fbank.done'} to allow recomputing fbank."
)
return
else:
cut_sets = make_cutset_blueprints(args.manifest_dir)
for part, cut_set in cut_sets:
logging.info(f"Processing {part}")
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()


if __name__ == "__main__":
main()
58 changes: 58 additions & 0 deletions egs/multi_ja_en/ASR/local/display_manifest_statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python3
# Copyright 2021 Xiaomi Corp. (authors: Fangjun Kuang)
# 2022 The University of Electro-Communications (author: Teo Wen Shen) # noqa
#
# 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.

import argparse
from pathlib import Path

from lhotse import CutSet, load_manifest

ARGPARSE_DESCRIPTION = """
This file displays duration statistics of utterances in a manifest.
You can use the displayed value to choose minimum/maximum duration
to remove short and long utterances during the training.

See the function `remove_short_and_long_utt()` in
pruned_transducer_stateless5/train.py for usage.
"""


def get_parser():
parser = argparse.ArgumentParser(
description=ARGPARSE_DESCRIPTION,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)

parser.add_argument("--manifest-dir", type=Path, help="Path to cutset manifests")

return parser.parse_args()


def main():
args = get_parser()

for part in ["train", "dev"]:
path = args.manifest_dir / f"reazonspeech_cuts_{part}.jsonl.gz"
cuts: CutSet = load_manifest(path)

print("\n---------------------------------\n")
print(path.name + ":")
cuts.describe()


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions egs/multi_ja_en/ASR/local/prepare_char.py
66 changes: 66 additions & 0 deletions egs/multi_ja_en/ASR/local/prepare_for_bpe_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
# Copyright 2023 Xiaomi Corp. (authors: Zengrui Jin)
#
# 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.

# This script tokenizes the training transcript by CJK characters
# and saves the result to transcript_chars.txt, which is used
# to train the BPE model later.

import argparse
import re
from pathlib import Path

from tqdm.auto import tqdm

from icefall.utils import tokenize_by_ja_char


def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--lang-dir",
type=str,
help="""Output directory.
The generated transcript_chars.txt is saved to this directory.
""",
)

parser.add_argument(
"--text",
type=str,
help="Training transcript.",
)

return parser.parse_args()


def main():
args = get_args()
lang_dir = Path(args.lang_dir)
text = Path(args.text)

assert lang_dir.exists() and text.exists(), f"{lang_dir} or {text} does not exist!"

transcript_path = lang_dir / "transcript_chars.txt"

with open(text, "r", encoding="utf-8") as fin:
with open(transcript_path, "w+", encoding="utf-8") as fout:
for line in tqdm(fin):
fout.write(tokenize_by_ja_char(line) + "\n")


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions egs/multi_ja_en/ASR/local/prepare_lang.py
Loading
Loading