Update README.md
Browse files
README.md
CHANGED
@@ -8,4 +8,329 @@ language:
|
|
8 |
- ja
|
9 |
pipeline_tag: automatic-speech-recognition
|
10 |
library_name: transformers
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
- ja
|
9 |
pipeline_tag: automatic-speech-recognition
|
10 |
library_name: transformers
|
11 |
+
tags:
|
12 |
+
- audio
|
13 |
+
- automatic-speech-recognition
|
14 |
+
- hf-asr-leaderboard
|
15 |
+
---
|
16 |
+
|
17 |
+
# Kotoba-Whisper-Bilingual (v1.0)
|
18 |
+
|
19 |
+
_Kotoba-Whisper-Bilingual_ is a collection of distilled [Whisper](https://arxiv.org/abs/2212.04356) models trained for
|
20 |
+
- **Japanese ASR**
|
21 |
+
- **English ASR**
|
22 |
+
- **Speech-to-text translation (Japanese -> English)**
|
23 |
+
- **Speech-to-text translation (English -> Japanese)**
|
24 |
+
|
25 |
+
developed through the collaboration bewteen
|
26 |
+
[Asahi Ushio](https://asahiushio.com) and [Kotoba Technologies](https://twitter.com/kotoba_tech).
|
27 |
+
Following the original work of distil-whisper ([Robust Knowledge Distillation via Large-Scale Pseudo Labelling](https://arxiv.org/abs/2311.00430)),
|
28 |
+
we employ OpenAI's [Whisper large-v3](https://huggingface.co/openai/whisper-large-v3) as the teacher model for Japanese and English ASR, while we translate the
|
29 |
+
transcription into English and Japanese by [chatgpt](https://openai.com/chatgpt/) to obtain training dataset for speech-to-text translation.
|
30 |
+
We employ [ReazonSpeech](https://huggingface.co/datasets/japanese-asr/ja_asr.reazon_speech_all) for Japanese ASR and Japanese speech to English text translation,
|
31 |
+
and [Multilingual LibriSpeech](https://huggingface.co/datasets/japanese-asr/en_asr.mls) for English ASR and English speech to Japanese text translation.
|
32 |
+
Kotoba-whisper-bilingual's loss objective consists of cross-entropy on both of ASR and translation tasks, while KL divergence loss only for ASR task.
|
33 |
+
The student model consists the full encoder of the teacher large-v3 model and the decoder with two layers initialized from the first and last layer of the large-v3 model.
|
34 |
+
|
35 |
+
Kotoba-Whisper is **6.3x faster than large-v3**, while retaining as low error rate as the large-v3.
|
36 |
+
|
37 |
+
## Evaluation
|
38 |
+
|
39 |
+
### Speech2Text Translation (Japanese->English)
|
40 |
+
|
41 |
+
| model | [CoVoST2 (Ja->En)](https://huggingface.co/datasets/japanese-asr/ja2en.s2t_translation)| [Fleurs (Ja->En)](https://huggingface.co/datasets/japanese-asr/ja2en.s2t_translation) |
|
42 |
+
|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------:|------------------------------------------------------------------------------------------------------:|
|
43 |
+
| [kotoba-tech/kotoba-whisper-bilingual-v1.0](https://huggingface.co/kotoba-tech/kotoba-whisper-bilingual-v1.0) | 73.9 | 98.7 |
|
44 |
+
| [japanese-asr/ja-cascaded-s2t-translation](https://huggingface.co/japanese-asr/ja-cascaded-s2t-translation) ([facebook/nllb-200-3.3B](https://huggingface.co/facebook/nllb-200-3.3B)) | 64.3 | 67.1 |
|
45 |
+
| [japanese-asr/ja-cascaded-s2t-translation](https://huggingface.co/japanese-asr/ja-cascaded-s2t-translation) ([facebook/nllb-200-1.3B](https://huggingface.co/facebook/nllb-200-1.3B)) | 65.4 | 68.9 |
|
46 |
+
| [japanese-asr/ja-cascaded-s2t-translation](https://huggingface.co/japanese-asr/ja-cascaded-s2t-translation) ([facebook/nllb-200-distilled-1.3B](https://huggingface.co/facebook/nllb-200-distilled-1.3B)) | 65.6 | 67.4 |
|
47 |
+
| [japanese-asr/ja-cascaded-s2t-translation](https://huggingface.co/japanese-asr/ja-cascaded-s2t-translation) ([facebook/nllb-200-distilled-600M](https://huggingface.co/facebook/nllb-200-distilled-600M)) | 68.2 | 72.2 |
|
48 |
+
| [openai/whisper-large-v3](https://huggingface.co/openai/whisper-large-v3) | 71 | 86.1 |
|
49 |
+
| [openai/whisper-large-v2](https://huggingface.co/openai/whisper-large-v2) | 66.4 | 78.8 |
|
50 |
+
| [openai/whisper-large](https://huggingface.co/openai/whisper-large) | 66.5 | 86.1 |
|
51 |
+
| [openai/whisper-medium](https://huggingface.co/openai/whisper-medium) | 70.3 | 97.2 |
|
52 |
+
| [openai/whisper-small](https://huggingface.co/openai/whisper-small) | 97.3 | 132.2 |
|
53 |
+
| [openai/whisper-base](https://huggingface.co/openai/whisper-base) | 186.2 | 349.6 |
|
54 |
+
| [openai/whisper-tiny](https://huggingface.co/openai/whisper-tiny) | 377.2 | 474 |
|
55 |
+
|
56 |
+
|
57 |
+
### Speech2Text Translation (English->Japanese)
|
58 |
+
|
59 |
+
| model | [CoVoST2 (En->Ja)](https://huggingface.co/datasets/japanese-asr/en2ja.s2t_translation)| [Fleurs (En->JA)](https://huggingface.co/datasets/japanese-asr/en2ja.s2t_translation) |
|
60 |
+
|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------:|------------------------------------------------------------------------------------------------------:|
|
61 |
+
| [kotoba-tech/kotoba-whisper-bilingual-v1.0](https://huggingface.co/kotoba-tech/kotoba-whisper-bilingual-v1.0) | 69.1 | 74.4 |
|
62 |
+
| [japanese-asr/en-cascaded-s2t-translation](https://huggingface.co/japanese-asr/en-cascaded-s2t-translation) ([facebook/nllb-200-3.3B](https://huggingface.co/facebook/nllb-200-3.3B)) | 62.4 | 63.5 |
|
63 |
+
| [japanese-asr/en-cascaded-s2t-translation](https://huggingface.co/japanese-asr/en-cascaded-s2t-translation) ([facebook/nllb-200-1.3B](https://huggingface.co/facebook/nllb-200-1.3B)) | 64.4 | 67.2 |
|
64 |
+
| [japanese-asr/en-cascaded-s2t-translation](https://huggingface.co/japanese-asr/en-cascaded-s2t-translation) ([facebook/nllb-200-distilled-1.3B](https://huggingface.co/facebook/nllb-200-distilled-1.3B)) | 62.4 | 62.9 |
|
65 |
+
| [japanese-asr/en-cascaded-s2t-translation](https://huggingface.co/japanese-asr/en-cascaded-s2t-translation) ([facebook/nllb-200-distilled-600M](https://huggingface.co/facebook/nllb-200-distilled-600M)) | 63.4 | 66.2 |
|
66 |
+
| [openai/whisper-large-v3](https://huggingface.co/openai/whisper-large-v3) | 178.9 | 209.5 |
|
67 |
+
| [openai/whisper-large-v2](https://huggingface.co/openai/whisper-large-v2) | 179.6 | 201.8 |
|
68 |
+
| [openai/whisper-large](https://huggingface.co/openai/whisper-large) | 178.7 | 201.8 |
|
69 |
+
| [openai/whisper-medium](https://huggingface.co/openai/whisper-medium) | 178.7 | 202 |
|
70 |
+
| [openai/whisper-small](https://huggingface.co/openai/whisper-small) | 178.9 | 206.8 |
|
71 |
+
| [openai/whisper-base](https://huggingface.co/openai/whisper-base) | 179.5 | 214.2 |
|
72 |
+
| [openai/whisper-tiny](https://huggingface.co/openai/whisper-tiny) | 185.2 | 200.5 |
|
73 |
+
|
74 |
+
|
75 |
+
### ASR (Japanese)
|
76 |
+
|
77 |
+
| model | [CommonVoice 8 (Japanese test set)](https://huggingface.co/datasets/japanese-asr/ja_asr.common_voice_8_0) | [JSUT Basic 5000](https://huggingface.co/datasets/japanese-asr/ja_asr.jsut_basic5000) | [ReazonSpeech (held out test set)](https://huggingface.co/datasets/japanese-asr/ja_asr.reazonspeech_test) |
|
78 |
+
|:--------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------:|----------------------------------------------------------------------------------------:|------------------------------------------------------------------------------------------------------------:|
|
79 |
+
| [kotoba-tech/kotoba-whisper-bilingual-v1.0](https://huggingface.co/kotoba-tech/kotoba-whisper-bilingual-v1.0) | 9.8 | 9.3 | 16.8 |
|
80 |
+
| [kotoba-tech/kotoba-whisper-v2.0](https://huggingface.co/kotoba-tech/kotoba-whisper-v2.0) | 9.2 | 8.4 | 11.6 |
|
81 |
+
| [kotoba-tech/kotoba-whisper-v1.0](https://huggingface.co/kotoba-tech/kotoba-whisper-v1.0) | 9.4 | 8.5 | 12.2 |
|
82 |
+
| [openai/whisper-large-v3](https://huggingface.co/openai/whisper-large-v3) | 8.5 | 7.1 | 14.9 |
|
83 |
+
| [openai/whisper-large-v2](https://huggingface.co/openai/whisper-large-v2) | 9.7 | 8.2 | 28.1 |
|
84 |
+
| [openai/whisper-large](https://huggingface.co/openai/whisper-large) | 10 | 8.9 | 34.1 |
|
85 |
+
| [openai/whisper-medium](https://huggingface.co/openai/whisper-medium) | 11.5 | 10 | 33.2 |
|
86 |
+
| [openai/whisper-small](https://huggingface.co/openai/whisper-small) | 15.1 | 14.2 | 41.5 |
|
87 |
+
| [openai/whisper-base](https://huggingface.co/openai/whisper-base) | 28.6 | 24.9 | 70.4 |
|
88 |
+
| [openai/whisper-tiny](https://huggingface.co/openai/whisper-tiny) | 53.7 | 36.5 | 137.9 |
|
89 |
+
| [reazon-research/reazonspeech-nemo-v2](https://huggingface.co/reazon-research/reazonspeech-nemo-v2) | 9.1 | 7.4 | 11.2 |
|
90 |
+
|
91 |
+
|
92 |
+
|
93 |
+
### ASR (English)
|
94 |
+
|
95 |
+
| model | [ESB](https://huggingface.co/datasets/japanese-asr/en_asr.esb_eval) (ami) | [ESB](https://huggingface.co/datasets/japanese-asr/en_asr.esb_eval) (earnings22) | [ESB](https://huggingface.co/datasets/japanese-asr/en_asr.esb_eval) (librispeech) | [ESB](https://huggingface.co/datasets/japanese-asr/en_asr.esb_eval) (tedlium) | [ESB](https://huggingface.co/datasets/japanese-asr/en_asr.esb_eval) (voxpopuli) |
|
96 |
+
|:----------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------:|-----------------------------------------------------------------------------------:|------------------------------------------------------------------------------------:|--------------------------------------------------------------------------------:|----------------------------------------------------------------------------------:|
|
97 |
+
| [kotoba-tech/kotoba-whisper-bilingual-v1.0](https://huggingface.co/kotoba-tech/kotoba-whisper-bilingual-v1.0) | 16.7 | 15.3 | 2.4 | 4.1 | 8.3 |
|
98 |
+
| [openai/whisper-large-v3](https://huggingface.co/openai/whisper-large-v3) | 17.9 | 14.9 | 2.1 | 3.8 | 12.7 |
|
99 |
+
| [openai/whisper-large-v2](https://huggingface.co/openai/whisper-large-v2) | 18.9 | 16.7 | 2.3 | 4.9 | 7.7 |
|
100 |
+
| [openai/whisper-large](https://huggingface.co/openai/whisper-large) | 18.8 | 14.9 | 2.6 | 4.2 | 7.7 |
|
101 |
+
| [openai/whisper-medium](https://huggingface.co/openai/whisper-medium) | 18.3 | 14.9 | 2.5 | 4.3 | 7.9 |
|
102 |
+
| [openai/whisper-small](https://huggingface.co/openai/whisper-small) | 23.1 | 17.2 | 3.5 | 5.3 | 10.8 |
|
103 |
+
| [openai/whisper-base](https://huggingface.co/openai/whisper-base) | 26.6 | 21 | 6 | 6.1 | 11.3 |
|
104 |
+
| [openai/whisper-tiny](https://huggingface.co/openai/whisper-tiny) | 31.9 | 30.5 | 8.2 | 11.7 | 15.1 |
|
105 |
+
| [japanese-asr/distil-whisper-bilingual-v1.0](https://huggingface.co/japanese-asr/distil-whisper-bilingual-v1.0) | 20.7 | 18.6 | 2.4 | 6.4 | 10 |
|
106 |
+
|
107 |
+
|
108 |
+
|
109 |
+
|
110 |
+
|
111 |
+
|
112 |
+
|
113 |
+
- ***Latency***: As kotoba-whisper uses the same architecture as [distil-whisper/distil-large-v3](https://huggingface.co/distil-whisper/distil-large-v3),
|
114 |
+
it inherits the benefit of the improved latency compared to [openai/whisper-large-v3](https://huggingface.co/openai/whisper-large-v3)
|
115 |
+
(**6.3x faster than large-v3**, see the table below taken from [distil-whisper/distil-large-v3](https://huggingface.co/distil-whisper/distil-large-v3)).
|
116 |
+
|
117 |
+
| Model | Params / M | Rel. Latency |
|
118 |
+
|----------------------------------------------------------------------------------------------|------------|--------------|
|
119 |
+
| **[kotoba-tech/kotoba-whisper-v2.0](https://huggingface.co/kotoba-tech/kotoba-whisper-v2.0)**| **756** | **6.3** |
|
120 |
+
| **[kotoba-tech/kotoba-whisper-v1.0](https://huggingface.co/kotoba-tech/kotoba-whisper-v1.0)**| **756** | **6.3** |
|
121 |
+
| [openai/whisper-large-v3](https://huggingface.co/openai/whisper-large-v3) | 1550 | 1.0 |
|
122 |
+
|
123 |
+
|
124 |
+
## Transformers Usage
|
125 |
+
Kotoba-Whisper is supported in the Hugging Face 🤗 Transformers library from version 4.39 onwards. To run the model, first
|
126 |
+
install the latest version of Transformers.
|
127 |
+
|
128 |
+
```bash
|
129 |
+
pip install --upgrade pip
|
130 |
+
pip install --upgrade transformers accelerate
|
131 |
+
```
|
132 |
+
|
133 |
+
### Short-Form Transcription
|
134 |
+
The model can be used with the [`pipeline`](https://huggingface.co/docs/transformers/main_classes/pipelines#transformers.AutomaticSpeechRecognitionPipeline)
|
135 |
+
class to transcribe short-form audio files (< 30-seconds) as follows:
|
136 |
+
|
137 |
+
Download sample audio.
|
138 |
+
```shell
|
139 |
+
wget
|
140 |
+
```
|
141 |
+
|
142 |
+
```python
|
143 |
+
import torch
|
144 |
+
from transformers import pipeline
|
145 |
+
from datasets import load_dataset
|
146 |
+
|
147 |
+
# config
|
148 |
+
torch_dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
|
149 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
150 |
+
model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
|
151 |
+
|
152 |
+
# load model
|
153 |
+
pipe = pipeline(
|
154 |
+
"automatic-speech-recognition",
|
155 |
+
model="kotoba-tech/kotoba-whisper-bilingual-v1.0",
|
156 |
+
torch_dtype=torch_dtype,
|
157 |
+
device=device,
|
158 |
+
model_kwargs=model_kwargs
|
159 |
+
)
|
160 |
+
|
161 |
+
|
162 |
+
generate_kwargs = {"language": "ja", "task": "transcribe"}
|
163 |
+
|
164 |
+
# load sample audio
|
165 |
+
dataset = load_dataset("japanese-asr/ja_asr.reazonspeech_test", split="test")
|
166 |
+
sample = dataset[0]["audio"]
|
167 |
+
|
168 |
+
# run inference
|
169 |
+
result = pipe(sample, generate_kwargs=generate_kwargs)
|
170 |
+
print(result["text"])
|
171 |
+
```
|
172 |
+
|
173 |
+
- To transcribe a local audio file, simply pass the path to your audio file when you call the pipeline (make sure the audio is sampled in 16kHz):
|
174 |
+
```diff
|
175 |
+
- result = pipe(sample, generate_kwargs=generate_kwargs)
|
176 |
+
+ result = pipe("audio.mp3", generate_kwargs=generate_kwargs)
|
177 |
+
```
|
178 |
+
|
179 |
+
- For segment-level timestamps, pass the argument `return_timestamps=True` and return the `"chunks"` output:
|
180 |
+
```python
|
181 |
+
result = pipe(sample, return_timestamps=True, generate_kwargs=generate_kwargs)
|
182 |
+
print(result["chunks"])
|
183 |
+
```
|
184 |
+
|
185 |
+
***Sequential Long-Form:*** Kotoba-whisper is designed to be compatible with OpenAI's sequential long-form transcription algorithm. This algorithm uses a sliding window for buffered
|
186 |
+
inference of long audio files (> 30-seconds), and returns more accurate transcriptions compared to the [chunked long-form algorithm](#chunked-long-form).
|
187 |
+
As default, if long audio files are passed to the model, it will transcribes with the sequential long-form transcription.
|
188 |
+
The sequential long-form algorithm should be used in either of the following scenarios:
|
189 |
+
|
190 |
+
1. Transcription accuracy is the most important factor, and latency is less of a consideration
|
191 |
+
2. You are transcribing **batches** of long audio files, in which case the latency of sequential is comparable to chunked, while being up to 0.5% WER more accurate
|
192 |
+
|
193 |
+
If you are transcribing single long audio files and latency is the most important factor, you should use the chunked algorithm
|
194 |
+
described [below](#chunked-long-form). For a detailed explanation of the different algorithms, refer to Sections 5 of
|
195 |
+
the [Distil-Whisper paper](https://arxiv.org/pdf/2311.00430.pdf). The [`pipeline`](https://huggingface.co/docs/transformers/main_classes/pipelines#transformers.AutomaticSpeechRecognitionPipeline)
|
196 |
+
class can be used to transcribe long audio files with the sequential algorithm as follows:
|
197 |
+
|
198 |
+
|
199 |
+
### Chunked Long-Form
|
200 |
+
This algorithm should be used when a single large audio file is being transcribed and the fastest possible inference is required. In such circumstances,
|
201 |
+
the chunked algorithm is up to 9x faster than OpenAI's sequential long-form implementation (see Table 7 of the [Distil-Whisper paper](https://arxiv.org/pdf/2311.00430.pdf)).
|
202 |
+
To enable chunking, pass the `chunk_length_s` parameter to the `pipeline`. For distil-large-v3, a chunk length of 25-seconds
|
203 |
+
is optimal. To activate batching over long audio files, pass the argument `batch_size`:
|
204 |
+
|
205 |
+
```python
|
206 |
+
import torch
|
207 |
+
from transformers import pipeline
|
208 |
+
from datasets import load_dataset
|
209 |
+
|
210 |
+
# config
|
211 |
+
model_id = "kotoba-tech/kotoba-whisper-v2.0"
|
212 |
+
torch_dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
|
213 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
214 |
+
model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
|
215 |
+
generate_kwargs = {"language": "ja", "task": "transcribe"}
|
216 |
+
|
217 |
+
# load model
|
218 |
+
pipe = pipeline(
|
219 |
+
"automatic-speech-recognition",
|
220 |
+
model=model_id,
|
221 |
+
torch_dtype=torch_dtype,
|
222 |
+
device=device,
|
223 |
+
model_kwargs=model_kwargs,
|
224 |
+
chunk_length_s=15,
|
225 |
+
batch_size=16
|
226 |
+
)
|
227 |
+
|
228 |
+
# load sample audio (concatenate instances to create a long audio)
|
229 |
+
dataset = load_dataset("japanese-asr/ja_asr.reazonspeech_test", split="test")
|
230 |
+
sample = {"array": np.concatenate([i["array"] for i in dataset[:20]["audio"]]), "sampling_rate": dataset[0]['audio']['sampling_rate']}
|
231 |
+
|
232 |
+
# run inference
|
233 |
+
result = pipe(sample, generate_kwargs=generate_kwargs)
|
234 |
+
print(result["text"])
|
235 |
+
```
|
236 |
+
|
237 |
+
|
238 |
+
### Additional Speed & Memory Improvements
|
239 |
+
You can apply additional speed and memory improvements to further reduce the inference speed and VRAM
|
240 |
+
requirements. These optimisations primarily target the attention kernel, swapping it from an eager implementation to a
|
241 |
+
more efficient flash attention version.
|
242 |
+
|
243 |
+
#### Flash Attention 2
|
244 |
+
|
245 |
+
We recommend using [Flash-Attention 2](https://huggingface.co/docs/transformers/main/en/perf_infer_gpu_one#flashattention-2)
|
246 |
+
if your GPU allows for it. To do so, you first need to install [Flash Attention](https://github.com/Dao-AILab/flash-attention):
|
247 |
+
|
248 |
+
```
|
249 |
+
pip install flash-attn --no-build-isolation
|
250 |
+
```
|
251 |
+
|
252 |
+
Then pass `attn_implementation="flash_attention_2"` to `from_pretrained`:
|
253 |
+
|
254 |
+
```diff
|
255 |
+
- model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
|
256 |
+
+ model_kwargs = {"attn_implementation": "flash_attention_2"} if torch.cuda.is_available() else {}
|
257 |
+
```
|
258 |
+
|
259 |
+
|
260 |
+
## Model Details
|
261 |
+
See [https://huggingface.co/distil-whisper/distil-large-v3#model-details](https://huggingface.co/distil-whisper/distil-large-v3#model-details).
|
262 |
+
|
263 |
+
|
264 |
+
## Training
|
265 |
+
Please refer to [https://github.com/kotoba-tech/kotoba-whisper](https://github.com/kotoba-tech/kotoba-whisper) for the model training detail.
|
266 |
+
Datasets used in distillation and the whole model variations can be found at [https://huggingface.co/japanese-asr](https://huggingface.co/japanese-asr).
|
267 |
+
|
268 |
+
|
269 |
+
## Evaluation
|
270 |
+
The following code-snippets demonstrates how to evaluate the kotoba-whisper model on the Japanese subset of the CommonVoice 8.0.
|
271 |
+
First, we need to install the required packages, including 🤗 Datasets to load the audio data, and 🤗 Evaluate to
|
272 |
+
perform the WER calculation:
|
273 |
+
|
274 |
+
```bash
|
275 |
+
pip install --upgrade pip
|
276 |
+
pip install --upgrade transformers datasets[audio] evaluate jiwer
|
277 |
+
```
|
278 |
+
|
279 |
+
Evaluation can then be run end-to-end with the following example:
|
280 |
+
|
281 |
+
```python
|
282 |
+
import torch
|
283 |
+
from transformers import pipeline
|
284 |
+
from datasets import load_dataset
|
285 |
+
from evaluate import load
|
286 |
+
from transformers.models.whisper.english_normalizer import BasicTextNormalizer
|
287 |
+
|
288 |
+
# model config
|
289 |
+
model_id = "kotoba-tech/kotoba-whisper-v2.0"
|
290 |
+
torch_dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
|
291 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
292 |
+
model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
|
293 |
+
generate_kwargs = {"language": "japanese", "task": "transcribe"}
|
294 |
+
normalizer = BasicTextNormalizer()
|
295 |
+
|
296 |
+
# data config
|
297 |
+
dataset_name = "japanese-asr/ja_asr.reazonspeech_test"
|
298 |
+
audio_column = 'audio'
|
299 |
+
text_column = 'transcription'
|
300 |
+
|
301 |
+
# load model
|
302 |
+
pipe = pipeline(
|
303 |
+
"automatic-speech-recognition",
|
304 |
+
model=model_id,
|
305 |
+
torch_dtype=torch_dtype,
|
306 |
+
device=device,
|
307 |
+
model_kwargs=model_kwargs,
|
308 |
+
batch_size=16
|
309 |
+
)
|
310 |
+
|
311 |
+
# load the dataset and sample the audio with 16kHz
|
312 |
+
dataset = load_dataset(dataset_name, split="test")
|
313 |
+
transcriptions = pipe(dataset['audio'])
|
314 |
+
transcriptions = [normalizer(i['text']).replace(" ", "") for i in transcriptions]
|
315 |
+
references = [normalizer(i).replace(" ", "") for i in dataset['transcription']]
|
316 |
+
|
317 |
+
# compute the CER metric
|
318 |
+
cer_metric = load("cer")
|
319 |
+
cer = 100 * cer_metric.compute(predictions=transcriptions, references=references)
|
320 |
+
print(cer)
|
321 |
+
```
|
322 |
+
|
323 |
+
The huggingface links to the major Japanese ASR datasets for evaluation are summarized at [here](https://huggingface.co/collections/japanese-asr/japanese-asr-evaluation-dataset-66051a03d6ca494d40baaa26).
|
324 |
+
For example, to evaluate the model on JSUT Basic5000, change the `dataset_name`:
|
325 |
+
|
326 |
+
```diff
|
327 |
+
- dataset_name = "japanese-asr/ja_asr.reazonspeech_test"
|
328 |
+
+ dataset_name = "japanese-asr/ja_asr.jsut_basic5000"
|
329 |
+
```
|
330 |
+
|
331 |
+
## Acknowledgements
|
332 |
+
* [OpenAI](https://openai.com/) for the Whisper [model](https://huggingface.co/openai/whisper-large-v3).
|
333 |
+
* Hugging Face 🤗 [Transformers](https://github.com/huggingface/transformers) for the model integration.
|
334 |
+
* Hugging Face 🤗 for the [Distil-Whisper codebase](https://github.com/huggingface/distil-whisper).
|
335 |
+
* [Reazon Human Interaction Lab](https://research.reazon.jp/) for the [ReazonSpeech dataset](https://huggingface.co/datasets/reazon-research/reazonspeech).
|
336 |
+
|