File size: 13,976 Bytes
e685eb9
 
0b65545
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78b32ff
0b65545
 
78b32ff
0b65545
 
 
 
 
 
 
 
 
 
 
78b32ff
0b65545
 
 
 
 
 
 
 
 
 
 
 
 
 
78b32ff
0b65545
 
 
 
 
 
 
 
 
 
 
 
 
78b32ff
0b65545
 
 
 
78b32ff
 
0b65545
 
 
 
 
3d156a7
569b0b1
 
 
 
 
 
 
 
 
 
 
 
 
3d156a7
569b0b1
 
 
 
 
 
 
 
 
 
 
 
 
3d156a7
0b65545
78b32ff
569b0b1
 
 
 
 
 
 
 
 
 
 
3d156a7
569b0b1
 
 
 
 
 
 
 
 
 
 
 
 
3d156a7
569b0b1
 
3d156a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0b65545
 
78b32ff
0b65545
e685eb9
46d69ed
 
 
 
 
 
 
 
 
 
 
 
38cfb69
46d69ed
78b32ff
 
 
42336e1
78b32ff
 
 
 
 
 
 
46d69ed
78b32ff
46d69ed
3246124
46d69ed
e2ec446
78b32ff
 
46d69ed
 
 
78b32ff
46d69ed
78b32ff
46d69ed
 
78b32ff
 
 
 
 
 
 
 
 
46d69ed
 
78b32ff
 
 
 
 
 
 
 
46d69ed
78b32ff
 
 
 
 
 
 
46d69ed
78b32ff
 
 
 
 
 
 
 
 
 
 
 
46d69ed
78b32ff
 
 
 
 
 
 
46d69ed
 
78b32ff
46d69ed
78b32ff
46d69ed
78b32ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46d69ed
 
78b32ff
46d69ed
 
78b32ff
46d69ed
 
 
78b32ff
46d69ed
 
 
 
 
78b32ff
46d69ed
 
 
78b32ff
46d69ed
 
e2ec446
46d69ed
 
 
 
42336e1
78b32ff
 
 
42336e1
78b32ff
46d69ed
78b32ff
 
 
46d69ed
 
78b32ff
 
 
 
42336e1
78b32ff
 
 
 
 
46d69ed
 
 
 
 
 
 
 
 
 
78b32ff
46d69ed
 
78b32ff
46d69ed
 
 
78b32ff
46d69ed
78b32ff
46d69ed
78b32ff
46d69ed
 
 
 
78b32ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
---
license: cc-by-nc-4.0
language:
- en
- de
- es
- fr
library_name: nemo
datasets:
- librispeech_asr
- fisher_corpus
- Switchboard-1
- WSJ-0
- WSJ-1
- National-Singapore-Corpus-Part-1
- National-Singapore-Corpus-Part-6
- vctk
- voxpopuli
- europarl
- multilingual_librispeech
- mozilla-foundation/common_voice_8_0
- MLCommons/peoples_speech
thumbnail: null
tags:
- automatic-speech-recognition
- automatic-speech-translation
- speech
- audio
- Transformer
- FastConformer
- Conformer
- pytorch
- NeMo
- hf-asr-leaderboard
widget:
- example_title: Librispeech sample 1
  src: https://cdn-media.huggingface.co/speech_samples/sample1.flac
- example_title: Librispeech sample 2
  src: https://cdn-media.huggingface.co/speech_samples/sample2.flac
model-index:
- name: canary-1b
  results:
  - task:
      name: Automatic Speech Recognition
      type: automatic-speech-recognition
    dataset:
      name: LibriSpeech (other)
      type: librispeech_asr
      config: other
      split: test
      args:
        language: en
    metrics:
    - name: Test WER
      type: wer
      value: 2.89
  - task:
      type: Automatic Speech Recognition
      name: automatic-speech-recognition
    dataset:
      name: SPGI Speech
      type: kensho/spgispeech
      config: test
      split: test
      args:
        language: en
    metrics:
    - name: Test WER
      type: wer
      value: 4.79
  - task:
      type: Automatic Speech Recognition
      name: automatic-speech-recognition
    dataset:
      name: Mozilla Common Voice 16.1
      type: mozilla-foundation/common_voice_16_1
      config: en
      split: test
      args:
        language: en
    metrics:
    - name: Test WER (En)
      type: wer
      value: 7.97
  - task:
      type: Automatic Speech Recognition
      name: automatic-speech-recognition
    dataset:
      name: Mozilla Common Voice 16.1
      type: mozilla-foundation/common_voice_16_1
      config: de
      split: test
      args:
        language: de
    metrics:
    - name: Test WER (De)
      type: wer
      value: 4.61
  - task:
      type: Automatic Speech Recognition
      name: automatic-speech-recognition
    dataset:
      name: Mozilla Common Voice 16.1
      type: mozilla-foundation/common_voice_16_1
      config: es
      split: test
      args:
        language: es
    metrics:
    - name: Test WER (ES)
      type: wer
      value: 3.99
  - task:
      type: Automatic Speech Recognition
      name: automatic-speech-recognition
    dataset:
      name: Mozilla Common Voice 16.1
      type: mozilla-foundation/common_voice_16_1
      config: fr
      split: test
      args:
        language: fr
    metrics:
    - name: Test WER (Fr)
      type: wer
      value: 6.53
  - task:
      type: Automatic Speech Translation
      name: automatic-speech-translation
    dataset:
      name: FLEURS
      type: google/fleurs
      config: en_us
      split: test
      args:
        language: en-de
    metrics:
    - name: Test BLEU (En->De)
      type: bleu
      value: 22.66
  - task:
      type: Automatic Speech Translation
      name: automatic-speech-translation
    dataset:
      name: FLEURS
      type: google/fleurs
      config: en_us
      split: test
      args:
        language: en-de
    metrics:
    - name: Test BLEU (En->Es)
      type: bleu
      value: 41.11
  - task:
      type: Automatic Speech Translation
      name: automatic-speech-translation
    dataset:
      name: FLEURS
      type: google/fleurs
      config: en_us
      split: test
      args:
        language: en-de
    metrics:
    - name: Test BLEU (En->Fr)
      type: bleu
      value: 40.76
  - task:
      type: Automatic Speech Translation
      name: automatic-speech-translation
    dataset:
      name: FLEURS
      type: google/fleurs
      config: de_de
      split: test
      args:
        language: de-en
    metrics:
    - name: Test BLEU (De->En)
      type: bleu
      value: 32.64
  - task:
      type: Automatic Speech Translation
      name: automatic-speech-translation
    dataset:
      name: FLEURS
      type: google/fleurs
      config: es_419
      split: test
      args:
        language: es-en
    metrics:
    - name: Test BLEU (Es->En)
      type: bleu
      value: 32.15
  - task:
      type: Automatic Speech Translation
      name: automatic-speech-translation
    dataset:
      name: FLEURS
      type: google/fleurs
      config: fr_fr
      split: test
      args:
        language: fr-en
    metrics:
    - name: Test BLEU (Fr->En)
      type: bleu
      value: 23.57
  - task:
      type: Automatic Speech Translation
      name: automatic-speech-translation
    dataset:
      name: COVOST
      type: covost2
      config: de_de
      split: test
      args:
        language: de-en
    metrics:
    - name: Test BLEU (De->En)
      type: bleu
      value: 37.67
  - task:
      type: Automatic Speech Translation
      name: automatic-speech-translation
    dataset:
      name: COVOST
      type: covost2
      config: es_419
      split: test
      args:
        language: es-en
    metrics:
    - name: Test BLEU (Es->En)
      type: bleu
      value: 40.7
  - task:
      type: Automatic Speech Translation
      name: automatic-speech-translation
    dataset:
      name: COVOST
      type: covost2
      config: fr_fr
      split: test
      args:
        language: fr-en
    metrics:
    - name: Test BLEU (Fr->En)
      type: bleu
      value: 40.42
  
metrics:
- wer
- bleu
pipeline_tag: automatic-speech-recognition
---


# Canary 1B

<style>
img {
 display: inline;
}
</style>

[![Model architecture](https://img.shields.io/badge/Model_Arch-FastConformer--Transformer-lightgrey#model-badge)](#model-architecture)
| [![Model size](https://img.shields.io/badge/Params-1B-lightgrey#model-badge)](#model-architecture)
| [![Language](https://img.shields.io/badge/Language-multilingual-lightgrey#model-badge)](#datasets)

NVIDIA NeMo Canary is a family of multi-lingual multi-tasking models that achieves state-of-the art performance on multiple benchmarks. With 1 billion parameters, Canary-1B supports automatic speech-to-text recognition (ASR) in 4 languages (English, German, French, Spanish) and translation from English to German/French/Spanish and from German/French/Spanish to English with or without punctuation and capitalization (PnC). 

## Model Architecture

Canary is an encoder-decoder model with FastConformer [1] encoder and Transformer Decoder [2]. 
With audio features extracted from the encoder, task tokens such as `<source language>`, `<target language>`, `<task>` and `<toggle PnC>` 
are fed into the Transformer Decoder to trigger the text generation process. Canary uses a concatenated tokenizer from individual 
SentencePiece [3] tokenizers of each language, which makes it easy to scale up to more languages. 
The Canay-1B model has 24 encoder layers and 24 layers of decoder layers in total.



## NVIDIA NeMo

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 Cython and latest PyTorch version.
```
pip install git+https://github.com/NVIDIA/[email protected]#egg=nemo_toolkit[all]
```


## How to Use this Model

The model is available for use in the NeMo toolkit [4], and can be used as a pre-trained checkpoint for inference or for fine-tuning on another dataset.

### Loading the Model

```python
from nemo.collections.asr.models import EncDecMultiTaskModel

# load model
canary_model = EncDecMultiTaskModel.from_pretrained('nvidia/canary-1b')

# update dcode params
decode_cfg = canary_model.cfg.decoding
decode_cfg.beam.beam_size = 5  # default is greedy with beam_size=1
canary_model.change_decoding_strategy(decode_cfg)
```

### Input Format
The input to the model can be a directory containing audio files, in which case the model will perform ASR on English and produces text with punctuation and capitalization:

```python
predicted_text = canary_model.trancribe(
    audio_dir="<path to directory containing audios>",
    batch_size=16,  # batch size to run the inference with
)
```

or use:

```bash
python [NEMO_GIT_FOLDER]/examples/asr/transcribe_speech.py 
 pretrained_name="nvidia/canary-1b" 
 audio_dir="<path to audio directory>" 
```

Another recommended option is to use a json manifest as input, where each line in the file is a dictionary containing the following fields:
```yaml
# Example of a line in input_manifest.json
{
    "audio_filepath": "/path/to/audio.wav",  # path to the audio file
    "duration": 10000.0,  # duration of the audio
    "taskname": "asr",  # use "s2t_translation" for AST
    "source_lang": "en",  # Set `source_lang`=`target_lang` for ASR, choices=['en','de','es','fr']
    "target_lang": "de",  # choices=['en','de','es','fr']
    "pnc": yes,  # whether to have PnC output, choices=['yes', 'no'] 
}
```

and then use:
```python
predicted_text = canary_model.trancribe(
    paths2audio_files="<path to input manifest file>",
    batch_size=16,  # batch size to run the inference with
)
```

or use:

```bash
python [NEMO_GIT_FOLDER]/examples/asr/transcribe_speech.py 
 pretrained_name="nvidia/canary-1b" 
 dataset_manifest="<path to manifest file>" 
```

### Automatic Speech-to-text Recognition (ASR)

An example manifest for transcribing English audios can be:

```yaml
# Example of a line in input_manifest.json
{
    "audio_filepath": "/path/to/audio.wav",  # path to the audio file
    "duration": 10000.0,  # duration of the audio
    "taskname": "asr",  
    "source_lang": "en", 
    "target_lang": "en", 
    "pnc": yes,  # whether to have PnC output, choices=['yes', 'no'] 
}
```


### Automatic Speech-to-text Translation (AST)

An example manifest for transcribing English audios into German text can be:

```yaml
# Example of a line in input_manifest.json
{
    "audio_filepath": "/path/to/audio.wav",  # path to the audio file
    "duration": 10000.0,  # duration of the audio
    "taskname": "s2t_translation",  
    "source_lang": "en",  
    "target_lang": "de",
    "pnc": yes,  # whether to have PnC output, choices=['yes', 'no'] 
}
```


### Input

This model accepts single channel (mono) audio sampled at 16000 Hz, along with the task/languages/PnC tags as input.

### Output

The model outputs the transcribed/translated text corresponding to the input audio, in the specified target language and with or without punctuation and capitalization.



## Training

Canary-1B is trained using the  NVIDIA NeMo toolkit [4] for 150k steps with dynamic bucketing and a batch duration of 360s per GPU on 128 NVIDIA A100 80GB GPUs in 24 hrs. The model can be trained using this example script and base config.

The tokenizers for these models were built using the text transcripts of the train set with this [script](https://github.com/NVIDIA/NeMo/blob/main/scripts/tokenizers/process_asr_text_tokenizer.py).


### Datasets

The Canary-1B model is trained on a total of 85k hrs of speech data. It consists of 31k hrs of public data, 20k hrs collected by [Suno](https://suno.ai/), and 34k hrs of in-house data. 


## Performance

In both ASR and AST experiments, predictions were generated using beam search with width 5 and length penalty 1.0.

### ASR Performance (w/o PnC) 

The ASR performance is measured with word error rate (WER) on [MCV-16.1](https://commonvoice.mozilla.org/en/datasets) test sets on four languages, and we process the groundtruth and predicted text with [whisper-normalizer](https://pypi.org/project/whisper-normalizer/).


| **Version** | **Model**     | **En**   | **De**   | **Es**   | **Fr**   |
|:---------:|:-----------:|:------:|:------:|:------:|:------:|
| 1.23.0  | canary-1b | 7.97 | 4.61 | 3.99 | 6.53 |


More details on evaluation can be found at [HuggingFace ASR Leaderboard](https://huggingface.co/spaces/hf-audio/open_asr_leaderboard)

### AST Performance

We evaluate AST performance with BLEU score on the [FLEURS](https://huggingface.co/datasets/google/fleurs) test sets on four languages and use their native annotations with punctuation and capitalization.

| **Version** | **Model** | **En->De** | **En->Es** | **En->Fr** | **De->En** | **Es->En** | **Fr->En** |
|:-----------:|:---------:|:----------:|:----------:|:----------:|:----------:|:----------:|:----------:|
| 1.23.0      | canary-1b | 22.66	      | 41.11      | 40.76      | 32.64      | 32.15      | 23.57      |


## NVIDIA Riva: Deployment

[NVIDIA Riva](https://developer.nvidia.com/riva), is an accelerated speech AI SDK deployable on-prem, in all clouds, multi-cloud, hybrid, on edge, and embedded. 
Additionally, Riva provides: 

* World-class out-of-the-box accuracy for the most common languages with model checkpoints trained on proprietary data with hundreds of thousands of GPU-compute hours 
* Best in class accuracy with run-time word boosting (e.g., brand and product names) and customization of acoustic model, language model, and inverse text normalization 
* Streaming speech recognition, Kubernetes compatible scaling, and enterprise-grade support 

Although this model isn’t supported yet by Riva, the [list of supported models](https://huggingface.co/models?other=Riva) is here.  
Check out [Riva live demo](https://developer.nvidia.com/riva#demos). 


## References
[1] [Fast Conformer with Linearly Scalable Attention for Efficient Speech Recognition](https://arxiv.org/abs/2305.05084)

[2] [Attention is all you need](https://arxiv.org/abs/1706.03762)

[3] [Google Sentencepiece Tokenizer](https://github.com/google/sentencepiece)

[4] [NVIDIA NeMo Toolkit](https://github.com/NVIDIA/NeMo)


## Licence

License to use this model is covered by the [CC-BY-NC-4.0](https://creativecommons.org/licenses/by-nc/4.0/deed.en#:~:text=NonCommercial%20%E2%80%94%20You%20may%20not%20use,doing%20anything%20the%20license%20permits.). By downloading the public and release version of the model, you accept the terms and conditions of the CC-BY-NC-4.0 license.