eustlb HF Staff commited on
Commit
03e217e
·
verified ·
1 Parent(s): 2317e66

Update README with Transformers usage

Browse files
Files changed (1) hide show
  1. README.md +159 -35
README.md CHANGED
@@ -16,6 +16,7 @@ datasets:
16
  - multilingual_librispeech
17
  - mozilla-foundation/common_voice_8_0
18
  - MLCommons/peoples_speech
 
19
  tags:
20
  - automatic-speech-recognition
21
  - speech
@@ -26,21 +27,19 @@ tags:
26
  - pytorch
27
  - NeMo
28
  - hf-asr-leaderboard
 
29
  license: cc-by-4.0
30
  widget:
31
  - example_title: Librispeech sample 1
32
  src: https://cdn-media.huggingface.co/speech_samples/sample1.flac
33
  - example_title: Librispeech sample 2
34
  src: https://cdn-media.huggingface.co/speech_samples/sample2.flac
35
- metrics:
36
- - wer
37
- pipeline_tag: automatic-speech-recognition
38
  model-index:
39
  - name: parakeet_rnnt_1.1b
40
  results:
41
  - task:
42
- type: automatic-speech-recognition
43
  name: Automatic Speech Recognition
 
44
  dataset:
45
  name: AMI (Meetings test)
46
  type: edinburghcstr/ami
@@ -49,12 +48,12 @@ model-index:
49
  args:
50
  language: en
51
  metrics:
52
- - type: wer
53
- value: 17.1
54
- name: Test WER
55
  - task:
56
- type: automatic-speech-recognition
57
  name: Automatic Speech Recognition
 
58
  dataset:
59
  name: Earnings-22
60
  type: revdotcom/earnings22
@@ -62,12 +61,12 @@ model-index:
62
  args:
63
  language: en
64
  metrics:
65
- - type: wer
 
66
  value: 14.11
67
- name: Test WER
68
  - task:
69
- type: automatic-speech-recognition
70
  name: Automatic Speech Recognition
 
71
  dataset:
72
  name: GigaSpeech
73
  type: speechcolab/gigaspeech
@@ -75,12 +74,12 @@ model-index:
75
  args:
76
  language: en
77
  metrics:
78
- - type: wer
 
79
  value: 9.96
80
- name: Test WER
81
  - task:
82
- type: automatic-speech-recognition
83
  name: Automatic Speech Recognition
 
84
  dataset:
85
  name: LibriSpeech (clean)
86
  type: librispeech_asr
@@ -89,12 +88,23 @@ model-index:
89
  args:
90
  language: en
91
  metrics:
92
- - type: wer
 
93
  value: 1.46
94
- name: Test WER
95
- - type: wer
 
 
 
 
 
 
 
 
 
 
 
96
  value: 2.47
97
- name: Test WER
98
  - task:
99
  type: Automatic Speech Recognition
100
  name: automatic-speech-recognition
@@ -106,9 +116,9 @@ model-index:
106
  args:
107
  language: en
108
  metrics:
109
- - type: wer
 
110
  value: 3.11
111
- name: Test WER
112
  - task:
113
  type: Automatic Speech Recognition
114
  name: automatic-speech-recognition
@@ -120,12 +130,12 @@ model-index:
120
  args:
121
  language: en
122
  metrics:
123
- - type: wer
 
124
  value: 3.92
125
- name: Test WER
126
  - task:
127
- type: automatic-speech-recognition
128
  name: Automatic Speech Recognition
 
129
  dataset:
130
  name: Vox Populi
131
  type: facebook/voxpopuli
@@ -134,9 +144,9 @@ model-index:
134
  args:
135
  language: en
136
  metrics:
137
- - type: wer
 
138
  value: 5.39
139
- name: Test WER
140
  - task:
141
  type: Automatic Speech Recognition
142
  name: automatic-speech-recognition
@@ -148,9 +158,13 @@ model-index:
148
  args:
149
  language: en
150
  metrics:
151
- - type: wer
 
152
  value: 5.79
153
- name: Test WER
 
 
 
154
  ---
155
 
156
  # Parakeet RNNT 1.1B (en)
@@ -184,25 +198,27 @@ NVIDIA Developer [Nemotron](https://developer.nvidia.com/nemotron)<br>
184
  [NVIDIA Riva Speech](https://developer.nvidia.com/riva?sortBy=developer_learning_library%2Fsort%2Ffeatured_in.riva%3Adesc%2Ctitle%3Aasc#demos)<br>
185
  [NeMo Documentation](https://docs.nvidia.com/nemo-framework/user-guide/latest/nemotoolkit/asr/models.html)<br>
186
 
187
- ## NVIDIA NeMo: Training
 
 
 
 
 
 
188
 
189
  To train, fine-tune or play with the model you will need to install [NVIDIA NeMo](https://github.com/NVIDIA/NeMo). We recommend you install it after you've installed latest PyTorch version.
190
  ```
191
  pip install nemo_toolkit['all']
192
  ```
193
 
194
- ## How to Use this Model
195
-
196
- The model is available for use in the NeMo toolkit [3], and can be used as a pre-trained checkpoint for inference or for fine-tuning on another dataset.
197
-
198
- ### Automatically instantiate the model
199
 
200
  ```python
201
  import nemo.collections.asr as nemo_asr
202
  asr_model = nemo_asr.models.EncDecRNNTBPEModel.from_pretrained(model_name="nvidia/parakeet-rnnt-1.1b")
203
  ```
204
 
205
- ### Transcribing using Python
206
  First, let's get a sample
207
  ```
208
  wget https://dldata-public.s3.us-east-2.amazonaws.com/2086-149220-0033.wav
@@ -213,7 +229,7 @@ output = asr_model.transcribe(['2086-149220-0033.wav'])
213
  print(output[0].text)
214
  ```
215
 
216
- ### Transcribing many audio files
217
 
218
  ```shell
219
  python [NEMO_GIT_FOLDER]/examples/asr/transcribe_speech.py
@@ -221,6 +237,114 @@ python [NEMO_GIT_FOLDER]/examples/asr/transcribe_speech.py
221
  audio_dir="<DIRECTORY CONTAINING AUDIO FILES>"
222
  ```
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  ### Input
225
 
226
  This model accepts 16000 Hz mono-channel audio (wav files) as input.
 
16
  - multilingual_librispeech
17
  - mozilla-foundation/common_voice_8_0
18
  - MLCommons/peoples_speech
19
+ thumbnail: null
20
  tags:
21
  - automatic-speech-recognition
22
  - speech
 
27
  - pytorch
28
  - NeMo
29
  - hf-asr-leaderboard
30
+ - transformers
31
  license: cc-by-4.0
32
  widget:
33
  - example_title: Librispeech sample 1
34
  src: https://cdn-media.huggingface.co/speech_samples/sample1.flac
35
  - example_title: Librispeech sample 2
36
  src: https://cdn-media.huggingface.co/speech_samples/sample2.flac
 
 
 
37
  model-index:
38
  - name: parakeet_rnnt_1.1b
39
  results:
40
  - task:
 
41
  name: Automatic Speech Recognition
42
+ type: automatic-speech-recognition
43
  dataset:
44
  name: AMI (Meetings test)
45
  type: edinburghcstr/ami
 
48
  args:
49
  language: en
50
  metrics:
51
+ - name: Test WER
52
+ type: wer
53
+ value: 17.10
54
  - task:
 
55
  name: Automatic Speech Recognition
56
+ type: automatic-speech-recognition
57
  dataset:
58
  name: Earnings-22
59
  type: revdotcom/earnings22
 
61
  args:
62
  language: en
63
  metrics:
64
+ - name: Test WER
65
+ type: wer
66
  value: 14.11
 
67
  - task:
 
68
  name: Automatic Speech Recognition
69
+ type: automatic-speech-recognition
70
  dataset:
71
  name: GigaSpeech
72
  type: speechcolab/gigaspeech
 
74
  args:
75
  language: en
76
  metrics:
77
+ - name: Test WER
78
+ type: wer
79
  value: 9.96
 
80
  - task:
 
81
  name: Automatic Speech Recognition
82
+ type: automatic-speech-recognition
83
  dataset:
84
  name: LibriSpeech (clean)
85
  type: librispeech_asr
 
88
  args:
89
  language: en
90
  metrics:
91
+ - name: Test WER
92
+ type: wer
93
  value: 1.46
94
+ - task:
95
+ name: Automatic Speech Recognition
96
+ type: automatic-speech-recognition
97
+ dataset:
98
+ name: LibriSpeech (other)
99
+ type: librispeech_asr
100
+ config: other
101
+ split: test
102
+ args:
103
+ language: en
104
+ metrics:
105
+ - name: Test WER
106
+ type: wer
107
  value: 2.47
 
108
  - task:
109
  type: Automatic Speech Recognition
110
  name: automatic-speech-recognition
 
116
  args:
117
  language: en
118
  metrics:
119
+ - name: Test WER
120
+ type: wer
121
  value: 3.11
 
122
  - task:
123
  type: Automatic Speech Recognition
124
  name: automatic-speech-recognition
 
130
  args:
131
  language: en
132
  metrics:
133
+ - name: Test WER
134
+ type: wer
135
  value: 3.92
 
136
  - task:
 
137
  name: Automatic Speech Recognition
138
+ type: automatic-speech-recognition
139
  dataset:
140
  name: Vox Populi
141
  type: facebook/voxpopuli
 
144
  args:
145
  language: en
146
  metrics:
147
+ - name: Test WER
148
+ type: wer
149
  value: 5.39
 
150
  - task:
151
  type: Automatic Speech Recognition
152
  name: automatic-speech-recognition
 
158
  args:
159
  language: en
160
  metrics:
161
+ - name: Test WER
162
+ type: wer
163
  value: 5.79
164
+
165
+ metrics:
166
+ - wer
167
+ pipeline_tag: automatic-speech-recognition
168
  ---
169
 
170
  # Parakeet RNNT 1.1B (en)
 
198
  [NVIDIA Riva Speech](https://developer.nvidia.com/riva?sortBy=developer_learning_library%2Fsort%2Ffeatured_in.riva%3Adesc%2Ctitle%3Aasc#demos)<br>
199
  [NeMo Documentation](https://docs.nvidia.com/nemo-framework/user-guide/latest/nemotoolkit/asr/models.html)<br>
200
 
201
+ ## How to Use this Model
202
+
203
+ The model is available for use in the NeMo toolkit [3], and can be used as a pre-trained checkpoint for inference or for fine-tuning on another dataset.
204
+
205
+ You can also run Parakeet RNNT with [Transformers](https://github.com/huggingface/transformers) 🤗 (more below).
206
+
207
+ ### 1) NeMo usage
208
 
209
  To train, fine-tune or play with the model you will need to install [NVIDIA NeMo](https://github.com/NVIDIA/NeMo). We recommend you install it after you've installed latest PyTorch version.
210
  ```
211
  pip install nemo_toolkit['all']
212
  ```
213
 
214
+ #### Automatically instantiate the model
 
 
 
 
215
 
216
  ```python
217
  import nemo.collections.asr as nemo_asr
218
  asr_model = nemo_asr.models.EncDecRNNTBPEModel.from_pretrained(model_name="nvidia/parakeet-rnnt-1.1b")
219
  ```
220
 
221
+ #### Transcribing using Python
222
  First, let's get a sample
223
  ```
224
  wget https://dldata-public.s3.us-east-2.amazonaws.com/2086-149220-0033.wav
 
229
  print(output[0].text)
230
  ```
231
 
232
+ #### Transcribing many audio files
233
 
234
  ```shell
235
  python [NEMO_GIT_FOLDER]/examples/asr/transcribe_speech.py
 
237
  audio_dir="<DIRECTORY CONTAINING AUDIO FILES>"
238
  ```
239
 
240
+ ### 2) [Transformers](https://github.com/huggingface/transformers) 🤗 usage
241
+
242
+
243
+ Until Parakeet RNNT is part of an official Transformers release, you can use it by installing from source.
244
+
245
+ ```bash
246
+ pip install git+https://github.com/huggingface/transformers
247
+ ```
248
+
249
+ <details>
250
+ <summary>➡️ Pipeline usage</summary>
251
+
252
+ ```python
253
+ from transformers import pipeline
254
+
255
+ pipe = pipeline("automatic-speech-recognition", model="eustlb/parakeet-rnnt-1.1b")
256
+ out = pipe("https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/bcn_weather.mp3")
257
+ print(out)
258
+ ```
259
+ </details>
260
+
261
+ <details>
262
+ <summary>➡️ AutoModel</summary>
263
+
264
+ ```python
265
+ from transformers import AutoModelForRNNT, AutoProcessor
266
+ from datasets import load_dataset, Audio
267
+
268
+ num_samples = 3
269
+
270
+ model_id = "eustlb/parakeet-rnnt-1.1b"
271
+ processor = AutoProcessor.from_pretrained(model_id)
272
+ model = AutoModelForRNNT.from_pretrained(model_id, dtype="auto", device_map="auto")
273
+
274
+ ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
275
+ ds = ds.cast_column("audio", Audio(sampling_rate=processor.feature_extractor.sampling_rate))
276
+ speech_samples = [el["array"] for el in ds["audio"][:num_samples]]
277
+
278
+ inputs = processor(speech_samples, sampling_rate=processor.feature_extractor.sampling_rate)
279
+ inputs.to(model.device, dtype=model.dtype)
280
+ output = model.generate(**inputs, return_dict_in_generate=True)
281
+ print(processor.decode(output.sequences, skip_special_tokens=True))
282
+ ```
283
+ </details>
284
+
285
+
286
+ <details>
287
+ <summary>➡️ Timestamping</summary>
288
+
289
+ ```python
290
+ from datasets import Audio, load_dataset
291
+ from transformers import AutoModelForRNNT, AutoProcessor
292
+
293
+ num_samples = 3
294
+
295
+ model_id = "eustlb/parakeet-rnnt-1.1b"
296
+ processor = AutoProcessor.from_pretrained(model_id)
297
+ model = AutoModelForRNNT.from_pretrained(model_id, dtype="auto", device_map="auto")
298
+
299
+ ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
300
+ ds = ds.cast_column("audio", Audio(sampling_rate=processor.feature_extractor.sampling_rate))
301
+ speech_samples = [el["array"] for el in ds["audio"][:num_samples]]
302
+
303
+ inputs = processor(speech_samples, sampling_rate=processor.feature_extractor.sampling_rate)
304
+ inputs.to(model.device, dtype=model.dtype)
305
+ output = model.generate(**inputs, return_dict_in_generate=True)
306
+ decoded_output, decoded_timestamps = processor.decode(
307
+ output.sequences,
308
+ durations=output.durations,
309
+ skip_special_tokens=True,
310
+ )
311
+ print("Transcription:", decoded_output)
312
+ print("Timestamped tokens:", decoded_timestamps)
313
+ ```
314
+ </details>
315
+
316
+ <details>
317
+ <summary>➡️ Training</summary>
318
+
319
+ ```python
320
+ from transformers import AutoModelForRNNT, AutoProcessor
321
+ from datasets import load_dataset, Audio
322
+ import torch
323
+
324
+ model_id = "eustlb/parakeet-rnnt-1.1b"
325
+ NUM_SAMPLES = 4
326
+
327
+ processor = AutoProcessor.from_pretrained(model_id)
328
+ model = AutoModelForRNNT.from_pretrained(model_id, dtype=torch.bfloat16, device_map="auto")
329
+ model.train()
330
+
331
+ ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
332
+ ds = ds.cast_column("audio", Audio(sampling_rate=processor.feature_extractor.sampling_rate))
333
+ speech_samples = [el["array"] for el in ds["audio"][:NUM_SAMPLES]]
334
+ text_samples = ds["text"][:NUM_SAMPLES]
335
+
336
+ # passing `text` to the processor will prepare inputs' `labels` key
337
+ inputs = processor(audio=speech_samples, text=text_samples, sampling_rate=processor.feature_extractor.sampling_rate)
338
+ inputs.to(device=model.device, dtype=model.dtype)
339
+
340
+ outputs = model(**inputs)
341
+ print("Loss:", outputs.loss.item())
342
+ outputs.loss.backward()
343
+ ```
344
+ </details>
345
+
346
+ For more details about usage, please refer to the [Transformers' documentation](https://huggingface.co/docs/transformers/en/model_doc/parakeet).
347
+
348
  ### Input
349
 
350
  This model accepts 16000 Hz mono-channel audio (wav files) as input.