Views
No views yet
all subset of ReazonSpeech
(the largest speech-transcription paired dataset in Japanese extracted from Japanese TV audio recordings),
which amounts 7,203,957 audio clips (5 sec audio with 18 text tokens in average) after
those transcriptions more than 10 WER are removed (see WER Filter for detail).
The model was trained for 8 epochs with batch size 256 with sampling rate of 16kHz, and the training and evaluation code to reproduce kotoba-whisper is available at https://github.com/kotoba-tech/kotoba-whisper.| model | CommonVoice 8 (Japanese test set) | JSUT Basic 5000 | ReazonSpeech (held out test set) |
|---|---|---|---|
| kotoba-tech/kotoba-whisper-v2.0 | 58.8 | 63.7 | 55.6 |
| kotoba-tech/kotoba-whisper-v1.0 | 59.2 | 64.3 | 56.4 |
| openai/whisper-large-v3 | 55.1 | 59.2 | 60.2 |
| openai/whisper-large-v2 | 59.3 | 63.2 | 74.1 |
| openai/whisper-large | 61.1 | 66.4 | 74.9 |
| openai/whisper-medium | 63.4 | 69.5 | 76 |
| openai/whisper-base | 87.2 | 93 | 91.8 |
| openai/whisper-small | 74.2 | 81.9 | 83 |
| openai/whisper-tiny | 93.8 | 97.6 | 94.9 |
| Model | Params / M | Rel. Latency |
|---|---|---|
| kotoba-tech/kotoba-whisper-v2.0 | 756 | 6.3 |
| kotoba-tech/kotoba-whisper-v1.0 | 756 | 6.3 |
| openai/whisper-large-v3 | 1550 | 1.0 |
1pip install --upgrade pip
2pip install --upgrade transformers acceleratepipeline
class to transcribe short-form audio files (< 30-seconds) as follows:1import torch
2from transformers import pipeline
3from datasets import load_dataset
4
5# config
6model_id = "kotoba-tech/kotoba-whisper-v2.0"
7torch_dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
8device = "cuda:0" if torch.cuda.is_available() else "cpu"
9model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
10generate_kwargs = {"language": "ja", "task": "transcribe"}
11
12# load model
13pipe = pipeline(
14 "automatic-speech-recognition",
15 model=model_id,
16 torch_dtype=torch_dtype,
17 device=device,
18 model_kwargs=model_kwargs
19)
20
21# load sample audio
22dataset = load_dataset("japanese-asr/ja_asr.reazonspeech_test", split="test")
23sample = dataset[0]["audio"]
24
25# run inference
26result = pipe(sample, generate_kwargs=generate_kwargs)
27print(result["text"])1- result = pipe(sample, generate_kwargs=generate_kwargs)
2+ result = pipe("audio.mp3", generate_kwargs=generate_kwargs)return_timestamps=True and return the "chunks" output:1result = pipe(sample, return_timestamps=True, generate_kwargs=generate_kwargs)
2print(result["chunks"])pipeline
class can be used to transcribe long audio files with the sequential algorithm as follows:chunk_length_s parameter to the pipeline. For distil-large-v3, a chunk length of 25-seconds
is optimal. To activate batching over long audio files, pass the argument batch_size:1import torch
2from transformers import pipeline
3from datasets import load_dataset
4
5# config
6model_id = "kotoba-tech/kotoba-whisper-v2.0"
7torch_dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
8device = "cuda:0" if torch.cuda.is_available() else "cpu"
9model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
10generate_kwargs = {"language": "ja", "task": "transcribe"}
11
12# load model
13pipe = pipeline(
14 "automatic-speech-recognition",
15 model=model_id,
16 torch_dtype=torch_dtype,
17 device=device,
18 model_kwargs=model_kwargs,
19 batch_size=16
20)
21
22# load sample audio (concatenate instances to create a long audio)
23dataset = load_dataset("japanese-asr/ja_asr.reazonspeech_test", split="test")
24sample = {"array": np.concatenate([i["array"] for i in dataset[:20]["audio"]]), "sampling_rate": dataset[0]['audio']['sampling_rate']}
25
26# run inference
27result = pipe(sample, chunk_length_s=15, generate_kwargs=generate_kwargs)
28print(result["text"])pip install flash-attn --no-build-isolationattn_implementation="flash_attention_2" to from_pretrained:1- model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
2+ model_kwargs = {"attn_implementation": "flash_attention_2"} if torch.cuda.is_available() else {}1pip install --upgrade pip
2pip install --upgrade transformers datasets[audio] evaluate jiwer1import torch
2from transformers import pipeline
3from datasets import load_dataset
4from evaluate import load
5from transformers.models.whisper.english_normalizer import BasicTextNormalizer
6
7# model config
8model_id = "kotoba-tech/kotoba-whisper-v2.0"
9torch_dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
10device = "cuda:0" if torch.cuda.is_available() else "cpu"
11model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
12generate_kwargs = {"language": "japanese", "task": "transcribe"}
13normalizer = BasicTextNormalizer()
14
15# data config
16dataset_name = "japanese-asr/ja_asr.reazonspeech_test"
17audio_column = 'audio'
18text_column = 'transcription'
19
20# load model
21pipe = pipeline(
22 "automatic-speech-recognition",
23 model=model_id,
24 torch_dtype=torch_dtype,
25 device=device,
26 model_kwargs=model_kwargs,
27 batch_size=16
28)
29
30# load the dataset and sample the audio with 16kHz
31dataset = load_dataset(dataset_name, split="test")
32transcriptions = pipe(dataset['audio'])
33transcriptions = [normalizer(i['text']).replace(" ", "") for i in transcriptions]
34references = [normalizer(i).replace(" ", "") for i in dataset['transcription']]
35
36# compute the CER metric
37cer_metric = load("cer")
38cer = 100 * cer_metric.compute(predictions=transcriptions, references=references)
39print(cer)dataset_name:1- dataset_name = "japanese-asr/ja_asr.reazonspeech_test"
2+ dataset_name = "japanese-asr/ja_asr.jsut_basic5000"