kunaldhawan eustlb HF Staff commited on
Commit
c9bd536
·
1 Parent(s): 3fc30f3

Add 🤗 Transformers support (#20)

Browse files

- Upload processor (2af778cf06cfcc4bb943ed309c66a12008d98475)
- Upload Nemotron3_5AsrForRNNT (6f4cda233ca61c8aab428544a3344d96904f9983)
- Add 🤗 Transformers usage to model card (65267afc897a237850eda75e6ce45eb278fa73a4)
- Rebase model card on main; add 🤗 Transformers usage only (153610ad16586dfc19b57ad9060b9bb6e367b04d)
- Drop revision pin from Transformers snippets (not needed post-merge) (be133a9c2559b9f39bad8c7a789832bdc21a3fde)
- Add Pipeline usage snippet to Transformers section (92bc43f5297e5b145773660d07935052f9419a9e)
- config: drop unused joint_hidden_size, add default_prompt_id=101 (auto) (3afa791cd14f1c185541cb7b8c015096db946b66)
- config: drop redundant decoder_start_token_id (carried by generation_config) (299cc89044b022111fef860bee4244296b0eaf95)


Co-authored-by: Eustache Le Bihan <eustlb@users.noreply.huggingface.co>

README.md CHANGED
@@ -49,6 +49,7 @@ datasets:
49
  - europarl
50
  thumbnail: null
51
  tags:
 
52
  - speech-recognition
53
  - cache-aware ASR
54
  - automatic-speech-recognition
@@ -368,6 +369,8 @@ pip install git+https://github.com/NVIDIA/NeMo.git@main#egg=nemo_toolkit[asr]
368
 
369
  The model is available for use in the NeMo Framework, and can be used as a pre-trained checkpoint for inference or for fine-tuning on another dataset.
370
 
 
 
371
  ### Loading the Model
372
 
373
  ```python
@@ -409,6 +412,137 @@ Latency is defined by the `att_context_size` param, where att_context_size = `{n
409
 
410
  Here, chunk size = current frame + right context; each chunk is processed in non-overlapping fashion.
411
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
  ### Input(s): <br>
413
 
414
  **Input Type(s):** Audio, Lang ID <br>
 
49
  - europarl
50
  thumbnail: null
51
  tags:
52
+ - transformers
53
  - speech-recognition
54
  - cache-aware ASR
55
  - automatic-speech-recognition
 
369
 
370
  The model is available for use in the NeMo Framework, and can be used as a pre-trained checkpoint for inference or for fine-tuning on another dataset.
371
 
372
+ You can also run it with [🤗 Transformers](https://github.com/huggingface/transformers) (more below).
373
+
374
  ### Loading the Model
375
 
376
  ```python
 
412
 
413
  Here, chunk size = current frame + right context; each chunk is processed in non-overlapping fashion.
414
 
415
+ ### 🤗 Transformers usage
416
+
417
+ This checkpoint also runs with [🤗 Transformers](https://github.com/huggingface/transformers). The target language is passed through the processor's `language` argument: a locale such as `en-US`/`de-DE`, a bare code such as `de`, or `auto` for automatic language detection. In `auto` mode the model appends an `<xx-XX>` language tag after the transcript's terminal punctuation; it is a special token, so decoding with `skip_special_tokens=True` strips it (clean transcript) and `skip_special_tokens=False` keeps it for language labeling.
418
+
419
+ Until Nemotron3_5Asr is part of an official Transformers release, install Transformers from source:
420
+
421
+ ```bash
422
+ pip install git+https://github.com/huggingface/transformers
423
+ ```
424
+
425
+ <details>
426
+ <summary>➡️ Pipeline</summary>
427
+
428
+ ```python
429
+ from transformers import pipeline
430
+
431
+ pipe = pipeline("automatic-speech-recognition", model="nvidia/nemotron-3.5-asr-streaming-0.6b")
432
+ out = pipe("https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/bcn_weather.mp3")
433
+ print(out)
434
+ ```
435
+
436
+ The pipeline uses the default language prompt (index 0, `en-US`). For explicit language conditioning or automatic detection, pass the processor's `language` argument (see the AutoModel example below).
437
+ </details>
438
+
439
+ <details>
440
+ <summary>➡️ Offline transcription</summary>
441
+
442
+ ```python
443
+ from transformers import AutoModelForRNNT, AutoProcessor
444
+ from transformers.audio_utils import load_audio
445
+
446
+ model_id = "nvidia/nemotron-3.5-asr-streaming-0.6b"
447
+ processor = AutoProcessor.from_pretrained(model_id)
448
+ model = AutoModelForRNNT.from_pretrained(model_id, device_map="auto")
449
+
450
+ audio = load_audio(
451
+ "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/bcn_weather.mp3",
452
+ sampling_rate=processor.feature_extractor.sampling_rate,
453
+ )
454
+
455
+ # Condition on a known language ...
456
+ inputs = processor(audio, sampling_rate=processor.feature_extractor.sampling_rate, language="en-US")
457
+ inputs.to(model.device, dtype=model.dtype)
458
+ output = model.generate(**inputs, return_dict_in_generate=True)
459
+ print(processor.decode(output.sequences, skip_special_tokens=True))
460
+
461
+ # ... or let the model detect it and keep the emitted <xx-XX> language tag.
462
+ inputs = processor(audio, sampling_rate=processor.feature_extractor.sampling_rate, language="auto")
463
+ inputs.to(model.device, dtype=model.dtype)
464
+ output = model.generate(**inputs, return_dict_in_generate=True)
465
+ print(processor.decode(output.sequences, skip_special_tokens=False))
466
+ ```
467
+ </details>
468
+
469
+ <details>
470
+ <summary>➡️ Streaming transcription</summary>
471
+
472
+ ```python
473
+ from threading import Thread
474
+ from transformers import AutoModelForRNNT, AutoProcessor, TextIteratorStreamer
475
+ from transformers.audio_utils import load_audio
476
+
477
+ model_id = "nvidia/nemotron-3.5-asr-streaming-0.6b"
478
+ processor = AutoProcessor.from_pretrained(model_id)
479
+ model = AutoModelForRNNT.from_pretrained(model_id, device_map="auto")
480
+
481
+ processor.set_num_lookahead_tokens(6)
482
+ print(f"Streaming latency: {processor.streaming_latency_ms} ms")
483
+
484
+ # The language prompt rides along on every chunk; use a locale (e.g. "de-DE") or "auto".
485
+ language = "en-US"
486
+
487
+ sampling_rate = processor.feature_extractor.sampling_rate
488
+ audio = load_audio(
489
+ "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/obama.mp3",
490
+ sampling_rate=sampling_rate,
491
+ )
492
+
493
+ first_chunk_inputs = processor(
494
+ audio[: processor.num_samples_first_audio_chunk],
495
+ sampling_rate=sampling_rate,
496
+ is_streaming=True,
497
+ is_first_audio_chunk=True,
498
+ language=language,
499
+ return_tensors="pt",
500
+ )
501
+ first_chunk_inputs = first_chunk_inputs.to(model.device, dtype=model.dtype)
502
+
503
+
504
+ def input_features_generator():
505
+ yield first_chunk_inputs.input_features[:, : processor.num_mel_frames_first_audio_chunk, :]
506
+
507
+ mel_frame_idx = processor.num_mel_frames_first_audio_chunk
508
+ hop_length = processor.feature_extractor.hop_length
509
+ n_fft = processor.feature_extractor.n_fft
510
+
511
+ start_idx = mel_frame_idx * hop_length - n_fft // 2
512
+ while (end_idx := start_idx + processor.num_samples_per_audio_chunk) < audio.shape[0]:
513
+ inputs = processor(
514
+ audio[start_idx:end_idx],
515
+ sampling_rate=sampling_rate,
516
+ is_streaming=True,
517
+ is_first_audio_chunk=False,
518
+ language=language,
519
+ return_tensors="pt",
520
+ )
521
+ inputs = inputs.to(model.device, dtype=model.dtype)
522
+ yield inputs.input_features
523
+
524
+ mel_frame_idx += processor.num_mel_frames_per_audio_chunk
525
+ start_idx = mel_frame_idx * hop_length - n_fft // 2
526
+
527
+
528
+ streamer = TextIteratorStreamer(processor.tokenizer, skip_special_tokens=True)
529
+ generate_kwargs = {
530
+ **first_chunk_inputs,
531
+ "input_features": input_features_generator(),
532
+ "streamer": streamer,
533
+ }
534
+ thread = Thread(target=model.generate, kwargs=generate_kwargs)
535
+ thread.start()
536
+
537
+ print("Model output (streaming):", end=" ", flush=True)
538
+ for text_chunk in streamer:
539
+ print(text_chunk, end="", flush=True)
540
+ thread.join()
541
+ ```
542
+ </details>
543
+
544
+ For more details about usage, please refer to the [Transformers documentation](https://huggingface.co/docs/transformers/en/model_doc/nemotron3_5_asr).
545
+
546
  ### Input(s): <br>
547
 
548
  **Input Type(s):** Audio, Lang ID <br>
config.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Nemotron3_5AsrForRNNT"
4
+ ],
5
+ "blank_token_id": 13087,
6
+ "decoder_hidden_size": 640,
7
+ "dtype": "float32",
8
+ "durations": [],
9
+ "encoder_config": {
10
+ "activation_dropout": 0.1,
11
+ "attention_bias": false,
12
+ "attention_dropout": 0.1,
13
+ "conv_kernel_size": 9,
14
+ "convolution_bias": false,
15
+ "default_num_lookahead_tokens": 3,
16
+ "dropout": 0.1,
17
+ "dropout_positions": 0.0,
18
+ "hidden_act": "silu",
19
+ "hidden_size": 1024,
20
+ "initializer_range": 0.02,
21
+ "intermediate_size": 4096,
22
+ "layerdrop": 0.1,
23
+ "max_position_embeddings": 5000,
24
+ "model_type": "nemotron_asr_streaming_encoder",
25
+ "num_attention_heads": 8,
26
+ "num_hidden_layers": 24,
27
+ "num_key_value_heads": 8,
28
+ "num_mel_bins": 128,
29
+ "scale_input": false,
30
+ "sliding_window": 57,
31
+ "subsampling_conv_channels": 256,
32
+ "subsampling_conv_kernel_size": 3,
33
+ "subsampling_conv_stride": 2,
34
+ "subsampling_factor": 8,
35
+ "supported_num_lookahead_tokens": [
36
+ 3,
37
+ 0,
38
+ 6,
39
+ 13
40
+ ]
41
+ },
42
+ "hidden_act": "relu",
43
+ "initializer_range": 0.02,
44
+ "is_encoder_decoder": true,
45
+ "max_symbols_per_step": 10,
46
+ "model_type": "nemotron3_5_asr",
47
+ "num_decoder_layers": 2,
48
+ "num_prompts": 128,
49
+ "pad_token_id": 0,
50
+ "prompt_intermediate_size": 2048,
51
+ "transformers_version": "5.13.0.dev0",
52
+ "vocab_size": 13088,
53
+ "default_prompt_id": 101
54
+ }
generation_config.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "decoder_start_token_id": 13087,
4
+ "output_attentions": false,
5
+ "output_hidden_states": false,
6
+ "pad_token_id": 0,
7
+ "transformers_version": "5.13.0.dev0"
8
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9eebdd6590289cb3030f310858f3df93256600a800a3e8200c5993d5f967e174
3
+ size 2552062944
processor_config.json ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "blank_token": "<blank>",
3
+ "default_num_lookahead_tokens": 3,
4
+ "feature_extractor": {
5
+ "feature_extractor_type": "NemotronAsrStreamingFeatureExtractor",
6
+ "feature_size": 128,
7
+ "hop_length": 160,
8
+ "n_fft": 512,
9
+ "padding_side": "right",
10
+ "padding_value": 0.0,
11
+ "preemphasis": 0.97,
12
+ "return_attention_mask": true,
13
+ "sampling_rate": 16000,
14
+ "win_length": 400
15
+ },
16
+ "num_prompts": 128,
17
+ "processor_class": "Nemotron3_5AsrProcessor",
18
+ "prompt_dictionary": {
19
+ "af-ZA": 54,
20
+ "am-ET": 49,
21
+ "ar": 7,
22
+ "ar-AR": 7,
23
+ "auto": 101,
24
+ "ay-BO": 81,
25
+ "az-AZ": 66,
26
+ "bg": 30,
27
+ "bg-BG": 30,
28
+ "bn-IN": 36,
29
+ "cs": 22,
30
+ "cs-CZ": 22,
31
+ "da": 25,
32
+ "da-DK": 25,
33
+ "de": 9,
34
+ "de-DE": 9,
35
+ "el": 21,
36
+ "el-GR": 21,
37
+ "en": 0,
38
+ "en-GB": 1,
39
+ "en-US": 0,
40
+ "enGB": 1,
41
+ "es": 3,
42
+ "es-ES": 2,
43
+ "es-US": 3,
44
+ "esES": 2,
45
+ "et": 60,
46
+ "et-EE": 60,
47
+ "fa-IR": 38,
48
+ "fi": 26,
49
+ "fi-FI": 26,
50
+ "fr": 8,
51
+ "fr-CA": 100,
52
+ "fr-FR": 8,
53
+ "gn-PY": 82,
54
+ "gu-IN": 42,
55
+ "ha-NG": 50,
56
+ "haw-US": 97,
57
+ "he-IL": 64,
58
+ "hi": 6,
59
+ "hi-HI": 6,
60
+ "hi-IN": 6,
61
+ "hr": 29,
62
+ "hr-HR": 29,
63
+ "hu": 23,
64
+ "hu-HU": 23,
65
+ "hy-AM": 68,
66
+ "id-ID": 34,
67
+ "ig-NG": 53,
68
+ "it": 15,
69
+ "it-IT": 15,
70
+ "ja-JA": 10,
71
+ "ja-JP": 10,
72
+ "ka-GE": 67,
73
+ "km-KH": 47,
74
+ "kn-IN": 43,
75
+ "ko": 14,
76
+ "ko-KO": 14,
77
+ "ko-KR": 14,
78
+ "ku-TR": 65,
79
+ "ky-KG": 71,
80
+ "ln-CD": 58,
81
+ "lt": 31,
82
+ "lt-LT": 31,
83
+ "lv": 61,
84
+ "lv-LV": 61,
85
+ "mi-NZ": 96,
86
+ "ml-IN": 44,
87
+ "mr-IN": 41,
88
+ "ms-MY": 35,
89
+ "mt-MT": 102,
90
+ "nah-MX": 83,
91
+ "nb": 103,
92
+ "nb-NO": 103,
93
+ "ne-NP": 46,
94
+ "nl": 16,
95
+ "nl-NL": 16,
96
+ "nn": 104,
97
+ "nn-NO": 104,
98
+ "no": 27,
99
+ "no-NO": 27,
100
+ "ny-MW": 57,
101
+ "or-KE": 59,
102
+ "pl": 17,
103
+ "pl-PL": 17,
104
+ "pt": 13,
105
+ "pt-BR": 12,
106
+ "pt-PT": 13,
107
+ "qu-PE": 80,
108
+ "ro": 20,
109
+ "ro-RO": 20,
110
+ "ru": 11,
111
+ "ru-RU": 11,
112
+ "rw-RW": 55,
113
+ "si-LK": 45,
114
+ "sk": 28,
115
+ "sk-SK": 28,
116
+ "sl": 62,
117
+ "sl-SI": 62,
118
+ "sm-WS": 98,
119
+ "so-SO": 56,
120
+ "sv": 24,
121
+ "sv-SE": 24,
122
+ "sw-KE": 48,
123
+ "ta-IN": 39,
124
+ "te-IN": 40,
125
+ "tg-TJ": 70,
126
+ "th-TH": 32,
127
+ "to-TO": 99,
128
+ "tr": 18,
129
+ "tr-TR": 18,
130
+ "uk": 19,
131
+ "uk-UA": 19,
132
+ "ur-PK": 37,
133
+ "uz-UZ": 69,
134
+ "vi-VN": 33,
135
+ "yo-NG": 52,
136
+ "zh-CN": 4,
137
+ "zh-TW": 5,
138
+ "zh-ZH": 4,
139
+ "zu-ZA": 51
140
+ },
141
+ "supported_num_lookahead_tokens": [
142
+ 3,
143
+ 0,
144
+ 6,
145
+ 13
146
+ ]
147
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "clean_up_tokenization_spaces": false,
4
+ "extra_special_tokens": [
5
+ "<ar-AR>",
6
+ "<bg-BG>",
7
+ "<cs-CZ>",
8
+ "<da-DK>",
9
+ "<de-DE>",
10
+ "<el-GR>",
11
+ "<en-GB>",
12
+ "<en-US>",
13
+ "<es-ES>",
14
+ "<es-US>",
15
+ "<et-EE>",
16
+ "<fi-FI>",
17
+ "<fr-CA>",
18
+ "<fr-FR>",
19
+ "<he-IL>",
20
+ "<hi-IN>",
21
+ "<hr-HR>",
22
+ "<hu-HU>",
23
+ "<it-IT>",
24
+ "<ja-JP>",
25
+ "<ko-KR>",
26
+ "<lt-LT>",
27
+ "<lv-LV>",
28
+ "<nb-NO>",
29
+ "<nl-NL>",
30
+ "<nn-NO>",
31
+ "<pl-PL>",
32
+ "<pt-BR>",
33
+ "<pt-PT>",
34
+ "<ro-RO>",
35
+ "<ru-RU>",
36
+ "<sk-SK>",
37
+ "<sl-SL>",
38
+ "<sv-SE>",
39
+ "<th-TH>",
40
+ "<tr-TR>",
41
+ "<uk-UA>",
42
+ "<vi-VN>",
43
+ "<zh-CN>"
44
+ ],
45
+ "model_max_length": 1000000000000000019884624838656,
46
+ "pad_token": "<pad>",
47
+ "processor_class": "Nemotron3_5AsrProcessor",
48
+ "tokenizer_class": "ParakeetTokenizer",
49
+ "unk_token": "<unk>"
50
+ }