mhenrichsen commited on
Commit
d382915
·
verified ·
1 Parent(s): dfe25e7

Upload fine-tuned Danish ASR (hviske v5.1) — coral_read_aloud WER 19.5%, coral_conversation WER 25.5%

Browse files
config.json ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "CohereAsrForConditionalGeneration"
4
+ ],
5
+ "auto_map": {
6
+ "AutoConfig": "configuration_cohere_asr.CohereAsrConfig",
7
+ "AutoFeatureExtractor": "processing_cohere_asr.CohereAsrFeatureExtractor",
8
+ "AutoModel": "modeling_cohere_asr.CohereAsrModel",
9
+ "AutoModelForSpeechSeq2Seq": "modeling_cohere_asr.CohereAsrForConditionalGeneration",
10
+ "AutoProcessor": "processing_cohere_asr.CohereAsrProcessor",
11
+ "AutoTokenizer": "tokenization_cohere_asr.CohereAsrTokenizer"
12
+ },
13
+ "batch_size": 128,
14
+ "decoding": {
15
+ "beam": {
16
+ "beam_size": 1,
17
+ "len_pen": 0.0,
18
+ "max_generation_delta": 50
19
+ },
20
+ "return_best_hypothesis": true,
21
+ "strategy": "beam"
22
+ },
23
+ "dtype": "bfloat16",
24
+ "encoder": {
25
+ "att_context_size": [
26
+ -1,
27
+ -1
28
+ ],
29
+ "causal_downsampling": false,
30
+ "conv_context_size": null,
31
+ "conv_kernel_size": 9,
32
+ "conv_norm_type": "batch_norm",
33
+ "d_model": 1280,
34
+ "dropout": 0,
35
+ "dropout_att": 0,
36
+ "dropout_emb": 0,
37
+ "dropout_pre_encoder": 0,
38
+ "feat_in": 128,
39
+ "feat_out": -1,
40
+ "ff_expansion_factor": 4,
41
+ "n_heads": 8,
42
+ "n_layers": 48,
43
+ "pos_emb_max_len": 5000,
44
+ "reduction": null,
45
+ "reduction_factor": 1,
46
+ "reduction_position": null,
47
+ "self_attention_model": "rel_pos",
48
+ "subsampling": "dw_striding",
49
+ "subsampling_conv_channels": 256,
50
+ "subsampling_factor": 8,
51
+ "untie_biases": true,
52
+ "xscaling": false
53
+ },
54
+ "head": {
55
+ "activation": "relu",
56
+ "dropout": 0,
57
+ "hidden_size": 1024,
58
+ "log_softmax": true,
59
+ "num_classes": 16384,
60
+ "num_layers": 1,
61
+ "use_transformer_init": true
62
+ },
63
+ "is_encoder_decoder": true,
64
+ "log_batch_stats": false,
65
+ "log_prediction": true,
66
+ "max_audio_clip_s": 35,
67
+ "max_seq_len": 1024,
68
+ "min_energy_window_samples": 1600,
69
+ "model_defaults": {
70
+ "asr_enc_hidden": 1280,
71
+ "lm_dec_hidden": 1024,
72
+ "lm_enc_hidden": 1024
73
+ },
74
+ "model_type": "cohere_asr",
75
+ "multitask_metrics_cfg": {
76
+ "log_predictions": true,
77
+ "metrics": {
78
+ "wer": {
79
+ "constraint": ".source_lang==.target_lang"
80
+ }
81
+ }
82
+ },
83
+ "overlap_chunk_second": 5,
84
+ "preprocessor": {
85
+ "dither": 1e-05,
86
+ "features": 128,
87
+ "frame_splicing": 1,
88
+ "log": true,
89
+ "n_fft": 512,
90
+ "normalize": "per_feature",
91
+ "pad_to": 0,
92
+ "pad_value": 0.0,
93
+ "sample_rate": 16000,
94
+ "window": "hann",
95
+ "window_size": 0.025,
96
+ "window_stride": 0.01
97
+ },
98
+ "prompt_defaults": [
99
+ {
100
+ "role": "user",
101
+ "slots": {
102
+ "decodercontext": "",
103
+ "diarize": "<|nodiarize|>",
104
+ "emotion": "<|emo:undefined|>",
105
+ "itn": "<|noitn|>",
106
+ "pnc": "<|pnc|>",
107
+ "source_lang": "<|en|>",
108
+ "target_lang": "<|en|>",
109
+ "timestamp": "<|notimestamp|>"
110
+ }
111
+ },
112
+ {
113
+ "role": "user_partial",
114
+ "slots": {
115
+ "decodercontext": ""
116
+ }
117
+ }
118
+ ],
119
+ "prompt_format": "cohere_asr",
120
+ "sample_rate": 16000,
121
+ "supported_languages": [
122
+ "en",
123
+ "fr",
124
+ "de",
125
+ "es",
126
+ "it",
127
+ "pt",
128
+ "nl",
129
+ "pl",
130
+ "el",
131
+ "ar",
132
+ "ja",
133
+ "zh",
134
+ "vi",
135
+ "ko",
136
+ "da"
137
+ ],
138
+ "transf_decoder": {
139
+ "config_dict": {
140
+ "attn_layer_dropout": 0,
141
+ "attn_score_dropout": 0,
142
+ "embedding_dropout": 0,
143
+ "ffn_dropout": 0,
144
+ "hidden_act": "relu",
145
+ "hidden_size": 1024,
146
+ "inner_size": 4096,
147
+ "learn_positional_encodings": false,
148
+ "lm_dec_hidden": 1280,
149
+ "max_sequence_length": 1024,
150
+ "num_attention_heads": 8,
151
+ "num_layers": 8,
152
+ "num_token_types": 0,
153
+ "pre_ln": true,
154
+ "vocab_size": "None"
155
+ },
156
+ "encoder": null,
157
+ "model_name": null,
158
+ "pre_ln_final_layer_norm": true,
159
+ "pretrained": false
160
+ },
161
+ "transf_encoder": {
162
+ "attn_layer_dropout": 0,
163
+ "attn_score_dropout": 0,
164
+ "ffn_dropout": 0,
165
+ "hidden_size": 1024,
166
+ "inner_size": 4096,
167
+ "mask_future": false,
168
+ "num_attention_heads": 8,
169
+ "num_layers": 0,
170
+ "pre_ln": true,
171
+ "pre_ln_final_layer_norm": true
172
+ },
173
+ "transformers_version": "4.57.6",
174
+ "use_loss_mask_for_prompt": false,
175
+ "vocab_size": 16384
176
+ }
configuration_cohere_asr.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import PretrainedConfig
3
+
4
+ DEFAULT_SUPPORTED_LANGUAGES = ["ar", "de", "el", "en", "es", "fr", "it", "ja", "ko", "nl", "pl", "pt", "vi", "zh"]
5
+ NO_SPACE_LANGS = {"ja", "zh"}
6
+
7
+
8
+ class CohereAsrConfig(PretrainedConfig):
9
+ """Configuration for the Cohere ASR remote-code model."""
10
+
11
+ model_type = "cohere_asr"
12
+
13
+ def __init__(
14
+ self,
15
+ vocab_size=16384,
16
+ encoder=None,
17
+ transf_decoder=None,
18
+ head=None,
19
+ preprocessor=None,
20
+ max_audio_clip_s=35,
21
+ overlap_chunk_second=5,
22
+ min_energy_window_samples=1600,
23
+ batch_size=64,
24
+ sample_rate=16000,
25
+ supported_languages=None,
26
+ **kwargs,
27
+ ):
28
+ kwargs.setdefault("is_encoder_decoder", True)
29
+ self.vocab_size = vocab_size
30
+ self.encoder = encoder
31
+ self.transf_decoder = transf_decoder
32
+ self.head = head
33
+ self.preprocessor = preprocessor
34
+ self.max_audio_clip_s = max_audio_clip_s
35
+ self.overlap_chunk_second = overlap_chunk_second
36
+ self.min_energy_window_samples = min_energy_window_samples
37
+ self.batch_size = batch_size
38
+ self.sample_rate = sample_rate
39
+ self.supported_languages = (
40
+ list(supported_languages) if supported_languages is not None else list(DEFAULT_SUPPORTED_LANGUAGES)
41
+ )
42
+ super().__init__(**kwargs)
43
+
44
+ @property
45
+ def num_hidden_layers(self):
46
+ return self.transf_decoder["config_dict"]["num_layers"]
47
+
48
+
49
+ if hasattr(torch, "_dynamo") and hasattr(torch._dynamo, "disable"):
50
+ _dynamo_disable = torch._dynamo.disable
51
+ else:
52
+
53
+ def _dynamo_disable(fn):
54
+ return fn
generation_config.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 4,
4
+ "decoder_start_token_id": 13764,
5
+ "eos_token_id": 3,
6
+ "pad_token_id": 2,
7
+ "transformers_version": "4.57.6"
8
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a6289b4dbbb0f757ce959f548e39563fa000c57a397296c9c84a06b33a979315
3
+ size 4131796208
modeling_cohere_asr.py ADDED
@@ -0,0 +1,1533 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import atexit
2
+ import logging
3
+ import math
4
+ import multiprocessing as mp
5
+ from concurrent.futures import ProcessPoolExecutor
6
+ from typing import Optional
7
+
8
+ import librosa
9
+ import numpy as np
10
+ import soundfile as sf
11
+ import torch
12
+ import torch._dynamo
13
+ import torch.nn as nn
14
+ import torch.nn.functional as F
15
+ from transformers import PreTrainedModel
16
+ from transformers.activations import ACT2FN
17
+ from transformers.cache_utils import DynamicCache, EncoderDecoderCache, StaticCache
18
+ from transformers.modeling_outputs import BaseModelOutput, Seq2SeqLMOutput
19
+
20
+ from .configuration_cohere_asr import NO_SPACE_LANGS, CohereAsrConfig, _dynamo_disable
21
+
22
+ logging.getLogger("torch.fx.experimental.symbolic_shapes").setLevel(logging.ERROR)
23
+
24
+
25
+ class CohereAsrPreTrainedModel(PreTrainedModel):
26
+ config_class = CohereAsrConfig
27
+ base_model_prefix = "model"
28
+ main_input_name = "input_features"
29
+ supports_gradient_checkpointing = False
30
+ _no_split_modules = ["ConformerLayer", "TransformerDecoderLayer"]
31
+ _supports_cache_class = True
32
+ _supports_static_cache = True
33
+
34
+ @property
35
+ def all_tied_weights_keys(self):
36
+ return {}
37
+
38
+ def _init_weights(self, module):
39
+ if isinstance(module, (nn.Linear, nn.Conv1d, nn.Conv2d)):
40
+ module.weight.data.normal_(mean=0.0, std=0.02)
41
+ if module.bias is not None:
42
+ module.bias.data.zero_()
43
+ elif isinstance(module, nn.Embedding):
44
+ module.weight.data.normal_(mean=0.0, std=0.02)
45
+ if module.padding_idx is not None:
46
+ module.weight.data[module.padding_idx].zero_()
47
+
48
+
49
+ # --- Encoder Components (Conformer) ---
50
+
51
+
52
+ class MaskedConvSequential(nn.Sequential):
53
+ def forward(self, x, lengths):
54
+ # x: (batch, channels, time, features)
55
+ current_lengths = lengths.clone().float()
56
+ mask = self._create_mask(x, current_lengths.long())
57
+ for layer in self:
58
+ x = self.apply_channel_mask(x, mask)
59
+ x = layer(x)
60
+ if hasattr(layer, "stride") and layer.stride != (1, 1):
61
+ current_lengths = self.calculate_conv_output_size(
62
+ current_lengths, layer.kernel_size[0], layer.stride[0], layer.padding
63
+ )
64
+ mask = self._create_mask(x, current_lengths.long())
65
+ x = self.apply_channel_mask(x, mask)
66
+ return x, current_lengths.long()
67
+
68
+ def _create_mask(self, tensor, lengths):
69
+ batch_size, _, time, features = tensor.shape
70
+ time_mask = torch.arange(time, device=tensor.device).expand(batch_size, time) < lengths.unsqueeze(1)
71
+ return time_mask.unsqueeze(-1).expand(batch_size, time, features).to(tensor.dtype)
72
+
73
+ def apply_channel_mask(self, tensor, mask):
74
+ batch_size, channels, time, features = tensor.shape
75
+ expanded_mask = mask.unsqueeze(1).expand(batch_size, channels, time, features)
76
+ return tensor * expanded_mask
77
+
78
+ def calculate_conv_output_size(
79
+ self,
80
+ input_size: torch.Tensor,
81
+ kernel_size: int,
82
+ stride: int,
83
+ padding: tuple[int, int],
84
+ ):
85
+ return (input_size + padding[0] + padding[1] - kernel_size) // stride + 1
86
+
87
+
88
+ class ConvSubsampling(nn.Module):
89
+ def __init__(self, config):
90
+ super().__init__()
91
+ feat_in = int(config["feat_in"])
92
+ conv_channels = int(config["subsampling_conv_channels"])
93
+ self._conv_channels = conv_channels
94
+ feat_out = int(config["feat_out"])
95
+ if feat_out <= 0:
96
+ feat_out = int(config["d_model"])
97
+ subsampling_factor = int(config["subsampling_factor"])
98
+
99
+ self.conv = MaskedConvSequential(
100
+ nn.Conv2d(1, conv_channels, kernel_size=3, stride=2, padding=1),
101
+ nn.ReLU(),
102
+ nn.Conv2d(conv_channels, conv_channels, kernel_size=3, stride=2, padding=1, groups=conv_channels),
103
+ nn.Conv2d(conv_channels, conv_channels, kernel_size=1),
104
+ nn.ReLU(),
105
+ nn.Conv2d(conv_channels, conv_channels, kernel_size=3, stride=2, padding=1, groups=conv_channels),
106
+ nn.Conv2d(conv_channels, conv_channels, kernel_size=1),
107
+ nn.ReLU(),
108
+ )
109
+ self.out = nn.Linear(conv_channels * (feat_in // subsampling_factor), feat_out)
110
+
111
+ def _check_input_shape(self, x):
112
+ max_size_32bit = 2_147_483_647
113
+ B, C, T, F = x.shape
114
+ out_T = (T + 2 - 3) // 2 + 1
115
+ out_F = (F + 2 - 3) // 2 + 1
116
+ projected = B * self._conv_channels * out_T * out_F
117
+
118
+ if projected > max_size_32bit:
119
+ valid_batch_size = max_size_32bit // (self._conv_channels * out_T * out_F)
120
+ raise RuntimeError(
121
+ f"Batch too large for first conv: projected output numel={projected}, "
122
+ f"input shape={(B, C, T, F)}. Reduce batch size to {valid_batch_size} or lower. "
123
+ "You can try commenting out this code but depending on your pytorch version you may get an error like: \n"
124
+ "'RuntimeError: Expected canUse32BitIndexMath(input) && canUse32BitIndexMath(output) to be true, but got false.'"
125
+ )
126
+
127
+ @_dynamo_disable
128
+ def _needs_conv_split(self, x: torch.Tensor) -> bool:
129
+ """Check if input would exceed PyTorch's 2^31 int32 CUDA indexing limit
130
+ after the first Conv2d (stride=2) expands channels to conv_channels."""
131
+ B, C, T, F = x.shape
132
+ out_T = (T + 2 - 3) // 2 + 1
133
+ out_F = (F + 2 - 3) // 2 + 1
134
+ projected = B * self._conv_channels * out_T * out_F
135
+ return projected > 2_147_483_647
136
+
137
+ @_dynamo_disable
138
+ def _conv_split_by_batch(self, x: torch.Tensor, lengths: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
139
+ """Split input along batch dim, run conv on each chunk, then concatenate.
140
+
141
+ This is to work around the PyTorch/CUDA int32 indexing limit (https://github.com/pytorch/pytorch/issues/80020).
142
+ """
143
+ b = x.size(0)
144
+ _, _, t, f = x.shape
145
+ out_t = (t + 2 - 3) // 2 + 1
146
+ out_f = (f + 2 - 3) // 2 + 1
147
+ per_sample_projected = self._conv_channels * out_t * out_f
148
+ max_size_32bit = 2_147_483_647
149
+ max_batch_for_first_conv = max_size_32bit // per_sample_projected
150
+ safe_batch = min(b, max_batch_for_first_conv)
151
+ # Prefer power-of-two chunk sizes for better kernel utilization while
152
+ # still respecting the first-conv int32 indexing limit.
153
+ chunk_size = 1 << max(0, safe_batch.bit_length() - 1)
154
+ parts = []
155
+ for chunk, ln in zip(
156
+ torch.split(x, chunk_size, 0),
157
+ torch.split(lengths, chunk_size, 0),
158
+ ):
159
+ self._check_input_shape(chunk)
160
+ parts.append(self.conv(chunk, ln))
161
+ return (
162
+ torch.cat([p[0] for p in parts], dim=0),
163
+ torch.cat([p[1] for p in parts], dim=0),
164
+ )
165
+
166
+ def forward(self, x, lengths):
167
+ # x: (B, feat_in, T) -> (B, 1, T, feat_in)
168
+ x = x.transpose(1, 2).unsqueeze(1)
169
+
170
+ if self._needs_conv_split(x):
171
+ x, lengths = self._conv_split_by_batch(x, lengths)
172
+ else:
173
+ self._check_input_shape(x)
174
+ x, lengths = self.conv(x, lengths)
175
+
176
+ b, c, t, f = x.size()
177
+ x = x.transpose(1, 2).reshape(b, t, -1)
178
+ x = self.out(x)
179
+ return x, lengths
180
+
181
+
182
+ class RelPositionalEncoding(nn.Module):
183
+ def __init__(self, d_model, max_len=5000):
184
+ super().__init__()
185
+ self.d_model = d_model
186
+ self.max_len = max_len
187
+
188
+ def _create_pe(self, positions: torch.Tensor, dtype: torch.dtype) -> torch.Tensor:
189
+ pos_length = positions.size(0)
190
+ pe = torch.zeros(pos_length, self.d_model, device=positions.device)
191
+ div_term = torch.exp(
192
+ torch.arange(0, self.d_model, 2, dtype=torch.float32, device=positions.device)
193
+ * -(math.log(10000.0) / self.d_model)
194
+ )
195
+ pe[:, 0::2] = torch.sin(positions * div_term)
196
+ pe[:, 1::2] = torch.cos(positions * div_term)
197
+ return pe.unsqueeze(0).to(dtype)
198
+
199
+ @_dynamo_disable
200
+ def _materialize_pe(self, length: int, device: torch.device, dtype: torch.dtype):
201
+ needed_size = 2 * length - 1
202
+ if hasattr(self, "pe") and self.pe.size(1) >= needed_size:
203
+ if self.pe.device != device:
204
+ self.pe = self.pe.to(device=device)
205
+ if self.pe.dtype != dtype:
206
+ self.pe = self.pe.to(dtype=dtype)
207
+ return
208
+ effective_length = max(length, self.max_len)
209
+ positions = torch.arange(
210
+ effective_length - 1, -effective_length, -1, dtype=torch.float32, device=device
211
+ ).unsqueeze(1)
212
+ pe = self._create_pe(positions=positions, dtype=dtype)
213
+ if hasattr(self, "pe"):
214
+ self.pe = pe
215
+ else:
216
+ self.register_buffer("pe", pe, persistent=False)
217
+
218
+ def forward(self, x):
219
+ self._materialize_pe(length=x.size(1), device=x.device, dtype=x.dtype)
220
+ # center_pos would be the index of position 0
221
+ # negative positions would be used for right and
222
+ # positive for left tokens
223
+ # for input of length L, 2*L-1 positions are needed,
224
+ # positions from (L-1) to -(L-1)
225
+ input_len = x.size(1)
226
+ center_pos = self.pe.size(1) // 2 + 1
227
+ start_pos = center_pos - input_len
228
+ end_pos = center_pos + input_len - 1
229
+ pos_emb = self.pe[:, start_pos:end_pos]
230
+
231
+ return x, pos_emb
232
+
233
+
234
+ class ConformerFeedForward(nn.Module):
235
+ def __init__(self, d_model, d_ff, dropout):
236
+ super().__init__()
237
+ self.linear1 = nn.Linear(d_model, d_ff)
238
+ self.activation = nn.SiLU()
239
+ self.dropout = nn.Dropout(dropout)
240
+ self.linear2 = nn.Linear(d_ff, d_model)
241
+
242
+ def forward(self, x):
243
+ x = self.linear1(x)
244
+ x = self.activation(x)
245
+ x = self.dropout(x)
246
+ x = self.linear2(x)
247
+ return x
248
+
249
+
250
+ class ConformerConvolution(nn.Module):
251
+ def __init__(self, d_model, kernel_size):
252
+ super().__init__()
253
+ self.pointwise_conv1 = nn.Conv1d(d_model, d_model * 2, kernel_size=1)
254
+ self.depthwise_conv = nn.Conv1d(
255
+ d_model, d_model, kernel_size=kernel_size, groups=d_model, padding=(kernel_size - 1) // 2
256
+ )
257
+ self.batch_norm = nn.BatchNorm1d(d_model)
258
+ self.activation = nn.SiLU()
259
+ self.pointwise_conv2 = nn.Conv1d(d_model, d_model, kernel_size=1)
260
+
261
+ def forward(self, x, pad_mask=None):
262
+ x = x.transpose(1, 2)
263
+ x = self.pointwise_conv1(x)
264
+ x = nn.functional.glu(x, dim=1)
265
+ if pad_mask is not None:
266
+ x = x.masked_fill(pad_mask.unsqueeze(1), 0.0)
267
+ x = self.depthwise_conv(x)
268
+ x = self.batch_norm(x)
269
+ x = self.activation(x)
270
+ x = self.pointwise_conv2(x)
271
+ return x.transpose(1, 2)
272
+
273
+
274
+ class RelPositionMultiHeadAttention(nn.Module):
275
+ def __init__(self, n_head, n_feat, dropout_rate):
276
+ super().__init__()
277
+ self.d_k = n_feat // n_head
278
+ self.h = n_head
279
+ self.linear_q = nn.Linear(n_feat, n_feat)
280
+ self.linear_k = nn.Linear(n_feat, n_feat)
281
+ self.linear_v = nn.Linear(n_feat, n_feat)
282
+ self.linear_pos = nn.Linear(n_feat, n_feat, bias=False)
283
+ self.linear_out = nn.Linear(n_feat, n_feat)
284
+ self.dropout = nn.Dropout(dropout_rate)
285
+ self.scaling = self.d_k**-0.5
286
+ self.pos_bias_u = nn.Parameter(torch.zeros(self.h, self.d_k))
287
+ self.pos_bias_v = nn.Parameter(torch.zeros(self.h, self.d_k))
288
+
289
+ def rel_shift(self, x):
290
+ """Compute relative positional encoding.
291
+ Args:
292
+ x (torch.Tensor): (batch, nheads, time, 2*time-1)
293
+ """
294
+ b, h, qlen, pos_len = x.size() # (b, h, t1, t2)
295
+ # need to add a column of zeros on the left side of
296
+ # last dimension to perform the relative shifting
297
+ x = torch.nn.functional.pad(x, pad=(1, 0)) # (b, h, t1, t2+1)
298
+ x = x.view(b, h, -1, qlen) # (b, h, t2+1, t1)
299
+ # need to drop the first row
300
+ x = x[:, :, 1:].view(b, h, qlen, pos_len) # (b, h, t1, t2)
301
+ return x
302
+
303
+ def forward(self, x, pos_emb, mask=None):
304
+ batch_size = x.size(0)
305
+ q = self.linear_q(x).view(batch_size, -1, self.h, self.d_k).transpose(1, 2)
306
+ k = self.linear_k(x).view(batch_size, -1, self.h, self.d_k).transpose(1, 2)
307
+ v = self.linear_v(x).view(batch_size, -1, self.h, self.d_k).transpose(1, 2)
308
+
309
+ # pos_emb might be shared across batch
310
+ if pos_emb.size(0) == 1 and batch_size > 1:
311
+ pos_emb = pos_emb.expand(batch_size, -1, -1)
312
+ p = self.linear_pos(pos_emb).view(batch_size, -1, self.h, self.d_k).transpose(1, 2)
313
+
314
+ q_with_u = q + self.pos_bias_u.unsqueeze(0).unsqueeze(2)
315
+ q_with_v = q + self.pos_bias_v.unsqueeze(0).unsqueeze(2)
316
+ matrix_ac = torch.matmul(q_with_u, k.transpose(-1, -2))
317
+ matrix_bd = torch.matmul(q_with_v, p.transpose(-1, -2))
318
+ matrix_bd = self.rel_shift(matrix_bd)
319
+
320
+ # drops extra elements in the matrix_bd to match the matrix_ac's size
321
+ matrix_bd = matrix_bd[:, :, :, : matrix_ac.size(-1)]
322
+ scores = (matrix_ac + matrix_bd) * self.scaling
323
+
324
+ if mask is not None:
325
+ expanded_mask = mask.unsqueeze(1)
326
+ scores = scores.masked_fill(expanded_mask, -1e9)
327
+
328
+ attn = torch.softmax(scores, dim=-1)
329
+ if mask is not None:
330
+ attn = attn.masked_fill(expanded_mask, 0.0)
331
+ x = torch.matmul(self.dropout(attn), v)
332
+ x = x.transpose(1, 2).contiguous().view(batch_size, -1, self.h * self.d_k)
333
+ return self.linear_out(x)
334
+
335
+
336
+ class ConformerLayer(nn.Module):
337
+ def __init__(self, d_model, d_ff, n_heads, conv_kernel_size, dropout):
338
+ super().__init__()
339
+ self.norm_feed_forward1 = nn.LayerNorm(d_model)
340
+ self.feed_forward1 = ConformerFeedForward(d_model, d_ff, dropout)
341
+ self.norm_self_att = nn.LayerNorm(d_model)
342
+ self.self_attn = RelPositionMultiHeadAttention(n_heads, d_model, dropout)
343
+ self.norm_conv = nn.LayerNorm(d_model)
344
+ self.conv = ConformerConvolution(d_model, conv_kernel_size)
345
+ self.norm_feed_forward2 = nn.LayerNorm(d_model)
346
+ self.feed_forward2 = ConformerFeedForward(d_model, d_ff, dropout)
347
+ self.norm_out = nn.LayerNorm(d_model)
348
+ self.dropout = nn.Dropout(dropout)
349
+
350
+ def forward(self, x, pos_emb, mask=None, pad_mask=None):
351
+ residual = x
352
+ x = self.norm_feed_forward1(x)
353
+ x = residual + 0.5 * self.dropout(self.feed_forward1(x))
354
+
355
+ residual = x
356
+ x = self.norm_self_att(x)
357
+ x = residual + self.dropout(self.self_attn(x, pos_emb, mask))
358
+
359
+ residual = x
360
+ x = self.norm_conv(x)
361
+ x = residual + self.dropout(self.conv(x, pad_mask=pad_mask))
362
+
363
+ residual = x
364
+ x = self.norm_feed_forward2(x)
365
+ x = residual + 0.5 * self.dropout(self.feed_forward2(x))
366
+
367
+ return self.norm_out(x)
368
+
369
+
370
+ class ConformerEncoder(nn.Module):
371
+ """
372
+ Fast Conformer encoder.
373
+
374
+ Follows [Fast Conformer with Linearly Scalable Attention for Efficient Speech
375
+ Recognition](https://arxiv.org/abs/2305.05084).
376
+ """
377
+
378
+ main_input_name = "input_features"
379
+
380
+ def __init__(self, config):
381
+ super().__init__()
382
+ enc_config = config.encoder
383
+ self.d_model = enc_config["d_model"]
384
+ d_ff = self.d_model * enc_config["ff_expansion_factor"]
385
+ n_heads = enc_config["n_heads"]
386
+ conv_kernel_size = enc_config["conv_kernel_size"]
387
+ dropout = enc_config["dropout"]
388
+ n_layers = enc_config["n_layers"]
389
+ pos_emb_max_len = enc_config["pos_emb_max_len"]
390
+
391
+ self.pre_encode = ConvSubsampling(enc_config)
392
+ self.pos_enc = RelPositionalEncoding(self.d_model, pos_emb_max_len)
393
+
394
+ self.layers = nn.ModuleList(
395
+ [ConformerLayer(self.d_model, d_ff, n_heads, conv_kernel_size, dropout) for _ in range(n_layers)]
396
+ )
397
+
398
+ def _create_masks(self, padding_length, max_audio_length, device):
399
+ att_mask = torch.ones(1, max_audio_length, max_audio_length, dtype=torch.bool, device=device)
400
+ pad_mask = torch.arange(0, max_audio_length, device=device).expand(
401
+ padding_length.size(0), -1
402
+ ) < padding_length.unsqueeze(-1)
403
+ pad_mask_for_att_mask = pad_mask.unsqueeze(1).repeat([1, max_audio_length, 1])
404
+ pad_mask_for_att_mask = torch.logical_and(pad_mask_for_att_mask, pad_mask_for_att_mask.transpose(1, 2))
405
+ att_mask = torch.logical_and(att_mask.to(pad_mask_for_att_mask.device), pad_mask_for_att_mask)
406
+ att_mask = ~att_mask
407
+ pad_mask = ~pad_mask
408
+ return pad_mask, att_mask
409
+
410
+ def forward(
411
+ self,
412
+ input_features=None,
413
+ length=None,
414
+ return_dict: bool = False,
415
+ **kwargs,
416
+ ):
417
+ if input_features is None:
418
+ raise ValueError("Expected `input_features` for encoder forward.")
419
+ if length is None:
420
+ length = torch.full(
421
+ (input_features.shape[0],),
422
+ input_features.shape[-1],
423
+ device=input_features.device,
424
+ dtype=torch.long,
425
+ )
426
+ conv_dtype = self.pre_encode.conv[0].weight.dtype
427
+ if input_features.dtype != conv_dtype:
428
+ input_features = input_features.to(dtype=conv_dtype)
429
+ x, length = self.pre_encode(input_features, length)
430
+ length = length.to(torch.int64)
431
+ max_audio_length = x.size(1)
432
+ x, pos_emb = self.pos_enc(x)
433
+ pad_mask, att_mask = self._create_masks(
434
+ padding_length=length,
435
+ max_audio_length=max_audio_length,
436
+ device=x.device,
437
+ )
438
+ for i, layer in enumerate(self.layers):
439
+ x = layer(x, pos_emb, mask=att_mask, pad_mask=pad_mask)
440
+ if return_dict:
441
+ return BaseModelOutput(last_hidden_state=x)
442
+ return x, length
443
+
444
+
445
+ # --- Decoder Components ---
446
+
447
+
448
+ class FixedPositionalEncoding(nn.Module):
449
+ def __init__(self, hidden_size, max_sequence_length=512):
450
+ super().__init__()
451
+ self.hidden_size = hidden_size
452
+ self.max_sequence_length = max_sequence_length
453
+
454
+ pos_enc = torch.zeros(max_sequence_length, hidden_size)
455
+ position = torch.arange(0.0, max_sequence_length).unsqueeze(1)
456
+ coef = -math.log(10000.0) / hidden_size
457
+ div_term = torch.exp(coef * torch.arange(0.0, hidden_size, 2))
458
+ pos_enc[:, 0::2] = torch.sin(position * div_term)
459
+ pos_enc[:, 1::2] = torch.cos(position * div_term)
460
+ pos_enc.div_(math.sqrt(hidden_size))
461
+ self.register_buffer("pos_enc", pos_enc)
462
+
463
+ def forward(self, position_ids):
464
+ return torch.index_select(self.pos_enc, 0, position_ids.reshape(-1)).reshape(*position_ids.shape, -1)
465
+
466
+
467
+ class DecoderAttention(nn.Module):
468
+ def __init__(self, hidden_size, num_heads, layer_idx):
469
+ super().__init__()
470
+ self.hidden_size = hidden_size
471
+ self.num_heads = num_heads
472
+ self.layer_idx = layer_idx
473
+ self.head_dim = hidden_size // num_heads
474
+ self.scale = self.head_dim**-0.5
475
+ self.query_net = nn.Linear(hidden_size, hidden_size)
476
+ self.key_net = nn.Linear(hidden_size, hidden_size)
477
+ self.value_net = nn.Linear(hidden_size, hidden_size)
478
+ self.out_projection = nn.Linear(hidden_size, hidden_size)
479
+
480
+ def _reshape(self, x):
481
+ b, t, _ = x.shape
482
+ return x.view(b, t, self.num_heads, self.head_dim).transpose(1, 2)
483
+
484
+ def forward(
485
+ self,
486
+ hidden_states,
487
+ context_states=None,
488
+ attention_mask=None,
489
+ past_key_values=None,
490
+ cache_position=None,
491
+ is_cross_attention=False,
492
+ kv_seq_len=None,
493
+ ):
494
+ query = self._reshape(self.query_net(hidden_states))
495
+ source = hidden_states if context_states is None else context_states
496
+ cache_layer = None
497
+ is_cross_cache_updated = False
498
+ if past_key_values is not None and isinstance(past_key_values, EncoderDecoderCache):
499
+ is_cross_cache_updated = past_key_values.is_updated.get(self.layer_idx, False)
500
+ if is_cross_attention:
501
+ cache_layer = past_key_values.cross_attention_cache
502
+ else:
503
+ cache_layer = past_key_values.self_attention_cache
504
+ elif past_key_values is not None and isinstance(past_key_values, DynamicCache):
505
+ cache_layer = past_key_values
506
+
507
+ if is_cross_attention and cache_layer is not None and is_cross_cache_updated:
508
+ key, value = _get_cache_kv(cache_layer, self.layer_idx)
509
+ else:
510
+ key = self._reshape(self.key_net(source))
511
+ value = self._reshape(self.value_net(source))
512
+ if cache_layer is not None:
513
+ cache_kwargs = None
514
+ if not is_cross_attention and cache_position is not None:
515
+ cache_kwargs = {"cache_position": cache_position}
516
+ key, value = cache_layer.update(key, value, self.layer_idx, cache_kwargs=cache_kwargs)
517
+ if not is_cross_attention and kv_seq_len is not None:
518
+ key = key[:, :, :kv_seq_len]
519
+ value = value[:, :, :kv_seq_len]
520
+ if is_cross_attention:
521
+ past_key_values.is_updated[self.layer_idx] = True
522
+
523
+ attn_output = F.scaled_dot_product_attention(
524
+ query, key, value, attn_mask=attention_mask, dropout_p=0.0, scale=self.scale
525
+ )
526
+ attn_output = (
527
+ attn_output.transpose(1, 2)
528
+ .contiguous()
529
+ .view(hidden_states.shape[0], hidden_states.shape[1], self.hidden_size)
530
+ )
531
+ return self.out_projection(attn_output)
532
+
533
+
534
+ class DecoderFeedForward(nn.Module):
535
+ def __init__(self, hidden_size, inner_size, hidden_act="relu"):
536
+ super().__init__()
537
+ self.dense_in = nn.Linear(hidden_size, inner_size)
538
+ hidden_act = str(hidden_act).lower().replace("swish", "silu")
539
+ if hidden_act not in ACT2FN:
540
+ raise ValueError(f"Unsupported decoder hidden_act: {hidden_act}")
541
+ self.activation = ACT2FN[hidden_act]
542
+ self.dense_out = nn.Linear(inner_size, hidden_size)
543
+
544
+ def forward(self, x):
545
+ return self.dense_out(self.activation(self.dense_in(x)))
546
+
547
+
548
+ class TransformerDecoderLayer(nn.Module):
549
+ def __init__(self, hidden_size, inner_size, num_heads, layer_idx, hidden_act="relu"):
550
+ super().__init__()
551
+ self.layer_norm_1 = nn.LayerNorm(hidden_size)
552
+ self.first_sub_layer = DecoderAttention(hidden_size, num_heads, layer_idx=layer_idx)
553
+ self.layer_norm_2 = nn.LayerNorm(hidden_size)
554
+ self.second_sub_layer = DecoderAttention(hidden_size, num_heads, layer_idx=layer_idx)
555
+ self.layer_norm_3 = nn.LayerNorm(hidden_size)
556
+ self.third_sub_layer = DecoderFeedForward(hidden_size, inner_size, hidden_act=hidden_act)
557
+
558
+ def forward(
559
+ self,
560
+ hidden_states,
561
+ encoder_hidden_states=None,
562
+ self_attention_mask=None,
563
+ cross_attention_mask=None,
564
+ past_key_values=None,
565
+ cache_position=None,
566
+ kv_seq_len=None,
567
+ ):
568
+ residual = hidden_states
569
+ hidden_states = self.layer_norm_1(hidden_states)
570
+ self_out = self.first_sub_layer(
571
+ hidden_states,
572
+ context_states=None,
573
+ attention_mask=self_attention_mask,
574
+ past_key_values=past_key_values,
575
+ cache_position=cache_position,
576
+ is_cross_attention=False,
577
+ kv_seq_len=kv_seq_len,
578
+ )
579
+ hidden_states = residual + self_out
580
+
581
+ residual = hidden_states
582
+ hidden_states = self.layer_norm_2(hidden_states)
583
+ cross_out = self.second_sub_layer(
584
+ hidden_states,
585
+ context_states=encoder_hidden_states,
586
+ attention_mask=cross_attention_mask,
587
+ past_key_values=past_key_values,
588
+ cache_position=cache_position,
589
+ is_cross_attention=True,
590
+ )
591
+ hidden_states = residual + cross_out
592
+
593
+ residual = hidden_states
594
+ hidden_states = self.layer_norm_3(hidden_states)
595
+ hidden_states = residual + self.third_sub_layer(hidden_states)
596
+ return hidden_states
597
+
598
+
599
+ class TransformerDecoderEmbedding(nn.Module):
600
+ def __init__(self, vocab_size, hidden_size, max_sequence_length, padding_idx=2):
601
+ super().__init__()
602
+ self.token_embedding = nn.Embedding(vocab_size, hidden_size, padding_idx)
603
+ self.position_embedding = FixedPositionalEncoding(hidden_size, max_sequence_length)
604
+ self.layer_norm = nn.LayerNorm(hidden_size)
605
+
606
+ def forward(self, input_ids, positions):
607
+ return self.layer_norm(self.token_embedding(input_ids) + self.position_embedding(positions))
608
+
609
+
610
+ class TransformerDecoderCore(nn.Module):
611
+ def __init__(self, hidden_size, inner_size, num_heads, num_layers, hidden_act="relu"):
612
+ super().__init__()
613
+ self.layers = nn.ModuleList(
614
+ [
615
+ TransformerDecoderLayer(hidden_size, inner_size, num_heads, layer_idx=i, hidden_act=hidden_act)
616
+ for i in range(num_layers)
617
+ ]
618
+ )
619
+ self.final_layer_norm = nn.LayerNorm(hidden_size)
620
+
621
+ def forward(
622
+ self,
623
+ hidden_states,
624
+ encoder_hidden_states=None,
625
+ self_attention_mask=None,
626
+ cross_attention_mask=None,
627
+ past_key_values=None,
628
+ cache_position=None,
629
+ kv_seq_len=None,
630
+ ):
631
+ for layer in self.layers:
632
+ hidden_states = layer(
633
+ hidden_states,
634
+ encoder_hidden_states=encoder_hidden_states,
635
+ self_attention_mask=self_attention_mask,
636
+ cross_attention_mask=cross_attention_mask,
637
+ past_key_values=past_key_values,
638
+ cache_position=cache_position,
639
+ kv_seq_len=kv_seq_len,
640
+ )
641
+ return self.final_layer_norm(hidden_states), past_key_values
642
+
643
+
644
+ class TransformerDecoderWrapper(nn.Module):
645
+ def __init__(self, config):
646
+ super().__init__()
647
+ dec_config = config.transf_decoder["config_dict"]
648
+ hidden_size = dec_config["hidden_size"]
649
+ self._embedding = TransformerDecoderEmbedding(
650
+ vocab_size=config.head["num_classes"],
651
+ hidden_size=hidden_size,
652
+ max_sequence_length=dec_config["max_sequence_length"],
653
+ padding_idx=2,
654
+ )
655
+ self._decoder = TransformerDecoderCore(
656
+ hidden_size=hidden_size,
657
+ inner_size=dec_config["inner_size"],
658
+ num_heads=dec_config["num_attention_heads"],
659
+ num_layers=dec_config["num_layers"],
660
+ hidden_act=dec_config.get("hidden_act", "relu"),
661
+ )
662
+
663
+ def forward(
664
+ self,
665
+ input_ids,
666
+ positions,
667
+ encoder_hidden_states=None,
668
+ self_attention_mask=None,
669
+ cross_attention_mask=None,
670
+ past_key_values=None,
671
+ cache_position=None,
672
+ kv_seq_len=None,
673
+ ):
674
+ hidden_states = self._embedding(input_ids, positions)
675
+ return self._decoder(
676
+ hidden_states,
677
+ encoder_hidden_states=encoder_hidden_states,
678
+ self_attention_mask=self_attention_mask,
679
+ cross_attention_mask=cross_attention_mask,
680
+ past_key_values=past_key_values,
681
+ cache_position=cache_position,
682
+ kv_seq_len=kv_seq_len,
683
+ )
684
+
685
+
686
+ # --- Top-level Model ---
687
+
688
+
689
+ class CohereAsrModel(CohereAsrPreTrainedModel):
690
+ def __init__(self, config):
691
+ super().__init__(config)
692
+ self.encoder = ConformerEncoder(config)
693
+ self.transf_decoder = TransformerDecoderWrapper(config)
694
+ self.decoder_hidden_size = config.transf_decoder["config_dict"]["hidden_size"]
695
+
696
+ if self.encoder.d_model != self.decoder_hidden_size:
697
+ self.encoder_decoder_proj = nn.Linear(self.encoder.d_model, self.decoder_hidden_size)
698
+ else:
699
+ self.encoder_decoder_proj = None
700
+
701
+ def forward(
702
+ self,
703
+ input_ids,
704
+ positions,
705
+ input_features,
706
+ length,
707
+ attention_mask=None,
708
+ cross_attention_mask=None,
709
+ past_key_values=None,
710
+ ):
711
+ encoder_hidden_states, _ = self.encoder(input_features, length)
712
+ if self.encoder_decoder_proj is not None:
713
+ encoder_hidden_states = self.encoder_decoder_proj(encoder_hidden_states)
714
+
715
+ return self.transf_decoder(
716
+ input_ids=input_ids,
717
+ positions=positions,
718
+ encoder_hidden_states=encoder_hidden_states,
719
+ self_attention_mask=attention_mask,
720
+ cross_attention_mask=cross_attention_mask,
721
+ past_key_values=past_key_values,
722
+ )
723
+
724
+
725
+ class TokenClassifierHead(nn.Module):
726
+ def __init__(self, hidden_size, num_classes, log_softmax=False):
727
+ super().__init__()
728
+ self.mlp = nn.Module()
729
+ self.mlp.layer0 = nn.Linear(hidden_size, num_classes)
730
+ self.use_log_softmax = log_softmax
731
+
732
+ def forward(self, hidden_states):
733
+ logits = self.mlp.layer0(hidden_states)
734
+ if self.use_log_softmax:
735
+ return torch.log_softmax(logits, dim=-1)
736
+ return logits
737
+
738
+
739
+ class CohereAsrForConditionalGeneration(CohereAsrPreTrainedModel):
740
+ """Encoder-decoder Cohere ASR model with generation and transcription helpers."""
741
+
742
+ _keys_to_ignore_on_load_unexpected = [
743
+ "preprocessor.featurizer.window",
744
+ "preprocessor.featurizer.fb",
745
+ ]
746
+
747
+ def _supports_default_dynamic_cache(self):
748
+ return True
749
+
750
+ def __init__(self, config):
751
+ super().__init__(config)
752
+ self.encoder = ConformerEncoder(config)
753
+ self.transf_decoder = TransformerDecoderWrapper(config)
754
+ self.decoder_hidden_size = config.transf_decoder["config_dict"]["hidden_size"]
755
+ if self.encoder.d_model != self.decoder_hidden_size:
756
+ self.encoder_decoder_proj = nn.Linear(self.encoder.d_model, self.decoder_hidden_size)
757
+ else:
758
+ self.encoder_decoder_proj = None
759
+ self.log_softmax = TokenClassifierHead(
760
+ hidden_size=config.head["hidden_size"],
761
+ num_classes=config.head["num_classes"],
762
+ log_softmax=bool(config.head.get("log_softmax", False)),
763
+ )
764
+ # Tie token classifier head weights to decoder token embeddings.
765
+ self.log_softmax.mlp.layer0.weight = self.transf_decoder._embedding.token_embedding.weight
766
+ self._decode_pool = None
767
+ self._decode_pool_spm_model_file = None
768
+
769
+ def _infer_encoder_lengths_from_raw(self, raw_length: torch.Tensor) -> torch.Tensor:
770
+ lengths = raw_length.to(dtype=torch.long)
771
+ for layer in self.encoder.pre_encode.conv:
772
+ if isinstance(layer, nn.Conv2d):
773
+ if layer.stride[0] > 1:
774
+ lengths = (lengths + 2 * layer.padding[0] - layer.kernel_size[0]) // layer.stride[0] + 1
775
+ return torch.clamp(lengths, min=1)
776
+
777
+ def forward(
778
+ self,
779
+ input_ids=None,
780
+ positions=None,
781
+ input_features=None,
782
+ length=None,
783
+ attention_mask=None,
784
+ cross_attention_mask=None,
785
+ past_key_values=None,
786
+ cache_position=None,
787
+ labels=None,
788
+ decoder_input_ids=None,
789
+ decoder_attention_mask=None,
790
+ encoder_outputs=None,
791
+ **kwargs,
792
+ ):
793
+ if input_ids is None and decoder_input_ids is not None:
794
+ input_ids = decoder_input_ids
795
+ if input_ids is None:
796
+ raise ValueError("Expected `input_ids` or `decoder_input_ids`.")
797
+ if positions is None:
798
+ positions = (
799
+ torch.arange(input_ids.shape[1], device=input_ids.device).unsqueeze(0).expand(input_ids.shape[0], -1)
800
+ )
801
+
802
+ encoder_lengths = None
803
+ if encoder_outputs is not None:
804
+ if hasattr(encoder_outputs, "last_hidden_state"):
805
+ encoder_hidden_states = encoder_outputs.last_hidden_state
806
+ else:
807
+ encoder_hidden_states = encoder_outputs
808
+ if self.encoder_decoder_proj is not None:
809
+ encoder_hidden_states = self.encoder_decoder_proj(encoder_hidden_states)
810
+ else:
811
+ encoder_hidden_states, encoder_lengths = self.encoder(input_features, length)
812
+ if self.encoder_decoder_proj is not None:
813
+ encoder_hidden_states = self.encoder_decoder_proj(encoder_hidden_states)
814
+
815
+ # Wrap encoder_hidden_states in BaseModelOutput for return_dict compatibility if needed
816
+ if encoder_outputs is None:
817
+ encoder_outputs = BaseModelOutput(last_hidden_state=encoder_hidden_states)
818
+
819
+ dtype = encoder_hidden_states.dtype
820
+ batch_size, tgt_len = input_ids.shape
821
+ past_len = _get_cache_seq_length(past_key_values)
822
+ total_kv_len = past_len + tgt_len
823
+ static_max_cache_len = _get_static_cache_len(past_key_values)
824
+ if static_max_cache_len is not None and cache_position is None:
825
+ raise ValueError(
826
+ "cache_position is required when using StaticCache. "
827
+ "Ensure generate() or the caller passes cache_position."
828
+ )
829
+
830
+ query_positions = torch.arange(past_len, past_len + tgt_len, device=input_ids.device)[:, None]
831
+ key_positions = torch.arange(total_kv_len, device=input_ids.device)[None, :]
832
+ causal_bool = key_positions > query_positions
833
+ self_attention_mask = torch.zeros((batch_size, 1, tgt_len, total_kv_len), device=input_ids.device, dtype=dtype)
834
+ self_attention_mask.masked_fill_(causal_bool[None, None, :, :], float("-inf"))
835
+
836
+ effective_decoder_mask = decoder_attention_mask if decoder_attention_mask is not None else attention_mask
837
+ if effective_decoder_mask is not None:
838
+ effective_decoder_mask = _align_decoder_attention_mask(effective_decoder_mask, total_kv_len=total_kv_len)
839
+ key_padding = (1.0 - effective_decoder_mask[:, None, None, :].to(dtype=dtype)) * -1e9
840
+ self_attention_mask = self_attention_mask + key_padding
841
+
842
+ effective_cross_attention_mask = cross_attention_mask
843
+ if effective_cross_attention_mask is None:
844
+ if encoder_lengths is None and length is not None:
845
+ encoder_lengths = self._infer_encoder_lengths_from_raw(length)
846
+ if encoder_lengths is not None:
847
+ src_len = encoder_hidden_states.shape[1]
848
+ enc_positions = torch.arange(src_len, device=encoder_hidden_states.device)[None, :]
849
+ valid = enc_positions < encoder_lengths.to(device=encoder_hidden_states.device)[:, None]
850
+ effective_cross_attention_mask = (1.0 - valid[:, None, None, :].to(dtype=dtype)) * -1e9
851
+
852
+ kv_seq_len = total_kv_len if static_max_cache_len is not None else None
853
+
854
+ outputs, updated_cache = self.transf_decoder(
855
+ input_ids=input_ids,
856
+ positions=positions,
857
+ encoder_hidden_states=encoder_hidden_states,
858
+ self_attention_mask=self_attention_mask,
859
+ cross_attention_mask=effective_cross_attention_mask,
860
+ past_key_values=past_key_values,
861
+ cache_position=cache_position,
862
+ kv_seq_len=kv_seq_len,
863
+ )
864
+
865
+ logits = self.log_softmax(outputs)
866
+
867
+ loss = None
868
+ if labels is not None:
869
+ loss_fct = nn.CrossEntropyLoss()
870
+ loss = loss_fct(logits.view(-1, self.config.head["num_classes"]), labels.view(-1))
871
+
872
+ return Seq2SeqLMOutput(
873
+ loss=loss,
874
+ logits=logits,
875
+ past_key_values=updated_cache,
876
+ encoder_last_hidden_state=encoder_outputs.last_hidden_state,
877
+ )
878
+
879
+ def get_encoder(self):
880
+ return self.encoder
881
+
882
+ def get_decoder(self):
883
+ return self.transf_decoder
884
+
885
+ def generate(self, input_features=None, input_ids=None, length=None, attention_mask=None, **kwargs):
886
+ # If input_ids is provided, use it as decoder_input_ids
887
+ # This matches the multimodal encoder-decoder expectation where the prompt is the decoder start
888
+ decoder_input_ids = kwargs.pop("decoder_input_ids", None)
889
+ if input_ids is not None and decoder_input_ids is None:
890
+ decoder_input_ids = input_ids
891
+ # We must provide some input_ids to super().generate to avoid validation errors,
892
+ # but for encoder-decoder it usually expects encoder input_ids.
893
+ # Here input_features is the encoder input.
894
+ input_ids = None
895
+
896
+ decoder_attention_mask = kwargs.pop("decoder_attention_mask", None)
897
+ if decoder_input_ids is not None and decoder_attention_mask is None:
898
+ decoder_attention_mask = torch.ones_like(
899
+ decoder_input_ids, dtype=torch.long, device=decoder_input_ids.device
900
+ )
901
+
902
+ generation_kwargs = dict(kwargs)
903
+ generation_kwargs["input_features"] = input_features
904
+ generation_kwargs["length"] = length
905
+ generation_kwargs["decoder_input_ids"] = decoder_input_ids
906
+ generation_kwargs["decoder_attention_mask"] = decoder_attention_mask
907
+
908
+ decoder_start_token_id = getattr(self.config, "decoder_start_token_id", None)
909
+ eos_token_id = getattr(self.config, "eos_token_id", None)
910
+ pad_token_id = getattr(self.config, "pad_token_id", None)
911
+ if decoder_start_token_id is not None:
912
+ generation_kwargs["bos_token_id"] = decoder_start_token_id
913
+ if eos_token_id is not None:
914
+ generation_kwargs["eos_token_id"] = eos_token_id
915
+ if pad_token_id is not None:
916
+ generation_kwargs["pad_token_id"] = pad_token_id
917
+ if input_ids is not None:
918
+ generation_kwargs["input_ids"] = input_ids
919
+ if attention_mask is not None:
920
+ generation_kwargs["attention_mask"] = attention_mask
921
+ if "cache_implementation" not in generation_kwargs:
922
+ generation_kwargs["cache_implementation"] = "static"
923
+
924
+ # Fall back to dynamic cache when static cache is incompatible:
925
+ # - transformers 4.52-4.55: _supports_static_cache gate + StaticCache
926
+ # reads config.hidden_size which our nested config doesn't expose.
927
+ # - transformers >= 5.3: StaticCache.update() API changed (cache_position
928
+ # shape must match key_states, breaking our usage).
929
+ if generation_kwargs.get("cache_implementation") == "static":
930
+ _skip_static = hasattr(PreTrainedModel, "_supports_static_cache")
931
+ if not _skip_static:
932
+ import transformers
933
+
934
+ _v = tuple(int(x) for x in transformers.__version__.split(".")[:2])
935
+ _skip_static = _v >= (5, 3)
936
+ if _skip_static:
937
+ generation_kwargs.pop("cache_implementation", None)
938
+
939
+ # We disable_compile for generate() because when passing "cache_implementation"="static"
940
+ # transformers will auto-compile the forward pass setting dynamic=False.
941
+ # We need dynamic=True to avoid excessive recompilation. Note that this doesn't
942
+ # control whether we compile the encoder layers which is set according to
943
+ # the transcribe(...,compile=True) flag.
944
+ generation_kwargs["disable_compile"] = True
945
+
946
+ return super().generate(**generation_kwargs)
947
+
948
+ def _setup_compile(self, processor=None):
949
+ if getattr(self, "_compiled", False):
950
+ return
951
+ if not hasattr(torch, "compile"):
952
+ self._compiled = True
953
+ return
954
+
955
+ # Dynamo guards on submodule identity per layer, so each ConformerLayer
956
+ # causes a recompilation. Raise the limit so no layers fall back to eager.
957
+ needed = len(self.encoder.layers) + 4
958
+ if torch._dynamo.config.cache_size_limit < needed:
959
+ torch._dynamo.config.cache_size_limit = needed
960
+
961
+ for layer in self.encoder.layers:
962
+ layer.forward = torch.compile(layer.forward, dynamic=True)
963
+
964
+ if (
965
+ processor is not None
966
+ and hasattr(processor, "feature_extractor")
967
+ and hasattr(processor.feature_extractor, "filterbank")
968
+ ):
969
+ filterbank = processor.feature_extractor.filterbank
970
+ filterbank.forward = torch.compile(filterbank.forward)
971
+
972
+ self._compiled = True
973
+
974
+ def _validate_transcribe_language(self, language: str) -> None:
975
+ supported_languages = set(getattr(self.config, "supported_languages", []))
976
+ if language not in supported_languages:
977
+ supported_joined = ", ".join(sorted(supported_languages))
978
+ raise ValueError(f"Unsupported language '{language}'. Supported languages: {supported_joined}.")
979
+
980
+ def build_prompt(self, language: str, punctuation: bool = True) -> str:
981
+ """Build the decoder prompt prefix for language and punctuation settings."""
982
+ pnc_token = "<|pnc|>" if punctuation else "<|nopnc|>"
983
+ task_token = "<|noitn|>"
984
+ return (
985
+ "<|startofcontext|><|startoftranscript|><|emo:undefined|>"
986
+ f"<|{language}|><|{language}|>{pnc_token}{task_token}<|notimestamp|><|nodiarize|>"
987
+ )
988
+
989
+ def _load_and_resample_audio(
990
+ self,
991
+ target_sample_rate: int,
992
+ audio_file: Optional[str] = None,
993
+ audio_array: Optional[np.ndarray] = None,
994
+ sample_rate: Optional[int] = None,
995
+ ) -> tuple[np.ndarray, int]:
996
+ if (audio_file is None) == (audio_array is None):
997
+ raise ValueError("Exactly one of audio_file or audio_array must be provided.")
998
+
999
+ if audio_file is not None:
1000
+ audio, loaded_sample_rate = sf.read(audio_file)
1001
+ arr = np.asarray(audio, dtype=np.float32)
1002
+ sample_rate_int = int(loaded_sample_rate)
1003
+ else:
1004
+ if sample_rate is None:
1005
+ raise ValueError("sample_rate is required when audio_array is provided.")
1006
+ arr = np.asarray(audio_array, dtype=np.float32)
1007
+ sample_rate_int = int(sample_rate)
1008
+
1009
+ if arr.ndim > 1:
1010
+ arr = arr.mean(axis=1)
1011
+ if arr.ndim != 1:
1012
+ raise ValueError(f"Expected mono waveform (1D), got shape={arr.shape}")
1013
+
1014
+ if sample_rate_int != target_sample_rate:
1015
+ arr = librosa.resample(
1016
+ arr,
1017
+ orig_sr=sample_rate_int,
1018
+ target_sr=target_sample_rate,
1019
+ ).astype(np.float32, copy=False)
1020
+ sample_rate_int = target_sample_rate
1021
+
1022
+ return arr, sample_rate_int
1023
+
1024
+ def _prepare_segments(
1025
+ self,
1026
+ waveforms: list[np.ndarray],
1027
+ sample_rates: list[int],
1028
+ max_audio_clip_s: float,
1029
+ overlap_chunk_second: float,
1030
+ min_energy_window_samples: int,
1031
+ ) -> tuple[list[np.ndarray], list[int], list[tuple[int, Optional[int]]]]:
1032
+ segment_waveforms: list[np.ndarray] = []
1033
+ segment_sample_rates: list[int] = []
1034
+ segment_meta: list[tuple[int, Optional[int]]] = []
1035
+ fast_path_threshold_s = max(0.0, max_audio_clip_s - overlap_chunk_second)
1036
+
1037
+ for sample_idx, (waveform, sample_rate) in enumerate(zip(waveforms, sample_rates)):
1038
+ duration_s = float(waveform.shape[0]) / float(sample_rate)
1039
+ if duration_s <= fast_path_threshold_s:
1040
+ segment_waveforms.append(waveform)
1041
+ segment_sample_rates.append(sample_rate)
1042
+ segment_meta.append((sample_idx, None))
1043
+ continue
1044
+
1045
+ chunks = split_audio_chunks_energy(
1046
+ waveform=waveform,
1047
+ sample_rate=sample_rate,
1048
+ max_audio_clip_s=max_audio_clip_s,
1049
+ overlap_chunk_second=overlap_chunk_second,
1050
+ min_energy_window_samples=min_energy_window_samples,
1051
+ )
1052
+ for chunk_idx, chunk in enumerate(chunks):
1053
+ segment_waveforms.append(chunk)
1054
+ segment_sample_rates.append(sample_rate)
1055
+ segment_meta.append((sample_idx, chunk_idx))
1056
+
1057
+ return segment_waveforms, segment_sample_rates, segment_meta
1058
+
1059
+ def transcribe(
1060
+ self,
1061
+ processor,
1062
+ language: str,
1063
+ audio_files: Optional[list[str]] = None,
1064
+ audio_arrays: Optional[list[np.ndarray]] = None,
1065
+ sample_rates: Optional[list[int]] = None,
1066
+ punctuation: bool = True,
1067
+ batch_size: Optional[int] = None,
1068
+ compile: bool = False,
1069
+ pipeline_detokenization: bool = False,
1070
+ ) -> list[str]:
1071
+ """Transcribe one or more audio inputs into text.
1072
+
1073
+ Audio longer than ``max_audio_clip_s`` (default 35 s) is automatically split into overlapping
1074
+ chunks and reassembled.
1075
+
1076
+ Args:
1077
+ processor: ``AutoProcessor`` instance for this model.
1078
+ language: ISO 639-1 language code. The model does not perform language detection, so this
1079
+ is required. Supported: en, fr, de, es, it, pt, nl, pl, el, ar, ja, zh, vi, ko.
1080
+ audio_files: List of audio file paths. Mutually exclusive with *audio_arrays*.
1081
+ audio_arrays: List of 1-D numpy float arrays (raw waveforms). Requires *sample_rates*.
1082
+ sample_rates: Sample rate for each entry in *audio_arrays*.
1083
+ punctuation: Include punctuation in output (default ``True``).
1084
+ batch_size: GPU batch size. Defaults to ``config.batch_size``.
1085
+ compile: ``torch.compile`` encoder layers on first call for faster throughput (default
1086
+ ``False``). The first call incurs a one-time warmup cost; subsequent calls are faster.
1087
+ pipeline_detokenization: Overlap CPU detokenization with GPU inference using a background
1088
+ process (default ``False``). Beneficial when more audio segments than *batch_size* are
1089
+ passed in a single call, so that detokenization of one batch overlaps with inference on
1090
+ the next.
1091
+
1092
+ Returns:
1093
+ List of transcription strings, one per input audio.
1094
+ """
1095
+ if (audio_files is None) == (audio_arrays is None):
1096
+ raise ValueError("Provide exactly one of audio_files or audio_arrays.")
1097
+ if audio_arrays is not None and sample_rates is None:
1098
+ raise ValueError("sample_rates is required when audio_arrays is provided.")
1099
+ if audio_arrays is not None and len(audio_arrays) != len(sample_rates):
1100
+ raise ValueError(
1101
+ f"audio_arrays and sample_rates must have same length, got {len(audio_arrays)} and {len(sample_rates)}."
1102
+ )
1103
+
1104
+ if compile:
1105
+ self._setup_compile(processor=processor)
1106
+
1107
+ total_inputs = len(audio_files) if audio_files is not None else len(audio_arrays)
1108
+ if total_inputs == 0:
1109
+ return []
1110
+ if pipeline_detokenization:
1111
+ self._ensure_decode_pool(processor=processor)
1112
+
1113
+ self._validate_transcribe_language(language)
1114
+ prompt_text = self.build_prompt(language=language, punctuation=punctuation)
1115
+
1116
+ effective_batch_size = int(batch_size) if batch_size is not None else int(self.config.batch_size)
1117
+ max_audio_clip_s = float(self.config.max_audio_clip_s)
1118
+ overlap_chunk_second = float(self.config.overlap_chunk_second)
1119
+ min_energy_window_samples = int(self.config.min_energy_window_samples)
1120
+ target_sample_rate = int(self.config.sample_rate)
1121
+
1122
+ waveforms: list[np.ndarray] = []
1123
+ normalized_sample_rates: list[int] = []
1124
+ if audio_files is not None:
1125
+ for audio_file in audio_files:
1126
+ waveform, waveform_sr = self._load_and_resample_audio(
1127
+ audio_file=audio_file, target_sample_rate=target_sample_rate
1128
+ )
1129
+ waveforms.append(waveform)
1130
+ normalized_sample_rates.append(waveform_sr)
1131
+ else:
1132
+ for audio, sample_rate in zip(audio_arrays, sample_rates):
1133
+ waveform, waveform_sr = self._load_and_resample_audio(
1134
+ audio_array=audio, sample_rate=sample_rate, target_sample_rate=target_sample_rate
1135
+ )
1136
+ waveforms.append(waveform)
1137
+ normalized_sample_rates.append(waveform_sr)
1138
+
1139
+ segment_waveforms, segment_sample_rates, segment_meta = self._prepare_segments(
1140
+ waveforms=waveforms,
1141
+ sample_rates=normalized_sample_rates,
1142
+ max_audio_clip_s=max_audio_clip_s,
1143
+ overlap_chunk_second=overlap_chunk_second,
1144
+ min_energy_window_samples=min_energy_window_samples,
1145
+ )
1146
+ segment_texts = self._transcribe_waveforms_batched(
1147
+ processor=processor,
1148
+ waveforms=segment_waveforms,
1149
+ sample_rates=segment_sample_rates,
1150
+ prompt_text=prompt_text,
1151
+ batch_size=effective_batch_size,
1152
+ max_new_tokens=256,
1153
+ pipeline_detokenization=pipeline_detokenization,
1154
+ )
1155
+
1156
+ outputs = [""] * total_inputs
1157
+ chunked_outputs: dict[int, list[tuple[int, str]]] = {}
1158
+ for (sample_idx, chunk_idx), text in zip(segment_meta, segment_texts):
1159
+ if chunk_idx is None:
1160
+ outputs[sample_idx] = text
1161
+ continue
1162
+ if sample_idx not in chunked_outputs:
1163
+ chunked_outputs[sample_idx] = []
1164
+ chunked_outputs[sample_idx].append((chunk_idx, text))
1165
+
1166
+ for sample_idx, chunk_items in chunked_outputs.items():
1167
+ chunk_items.sort(key=lambda item: item[0])
1168
+ outputs[sample_idx] = join_chunk_texts(
1169
+ [text for _, text in chunk_items], separator=get_chunk_separator(language)
1170
+ )
1171
+
1172
+ return outputs
1173
+
1174
+ def _transcribe_waveforms_batched(
1175
+ self,
1176
+ processor,
1177
+ waveforms: list[np.ndarray],
1178
+ sample_rates: list[int],
1179
+ prompt_text: str,
1180
+ batch_size: int,
1181
+ max_new_tokens: int,
1182
+ pipeline_detokenization: bool = False,
1183
+ ) -> list[str]:
1184
+ if not waveforms:
1185
+ return []
1186
+
1187
+ transcriptions = [""] * len(waveforms)
1188
+ tokenizer = processor.tokenizer
1189
+ pad_token_id = tokenizer.pad_token_id
1190
+ eos_token_id = tokenizer.eos_token_id
1191
+ ordered_indices = sorted(range(len(waveforms)), key=lambda idx: waveforms[idx].shape[0], reverse=True)
1192
+ previous_batch_decode_job = None
1193
+ previous_batch_indices: Optional[list[int]] = None
1194
+
1195
+ for batch_order_indices in _batched_indices(len(ordered_indices), batch_size):
1196
+ batch_indices = [ordered_indices[i] for i in batch_order_indices]
1197
+ batch_waves = [waveforms[i] for i in batch_indices]
1198
+ batch_srs = [sample_rates[i] for i in batch_indices]
1199
+ if not all(sr == batch_srs[0] for sr in batch_srs):
1200
+ raise ValueError("Batched waveforms require a shared sampling rate.")
1201
+ prompts = [prompt_text] * len(batch_waves)
1202
+ inputs = processor(audio=batch_waves, text=prompts, sampling_rate=batch_srs[0], return_tensors="pt")
1203
+ inputs = {k: v.to(self.device) for k, v in inputs.items()}
1204
+ if "input_ids" in inputs and "decoder_input_ids" not in inputs:
1205
+ inputs["decoder_input_ids"] = inputs.pop("input_ids")
1206
+ if "decoder_input_ids" in inputs and "decoder_attention_mask" not in inputs:
1207
+ if pad_token_id is None:
1208
+ inputs["decoder_attention_mask"] = torch.ones(
1209
+ inputs["decoder_input_ids"].shape,
1210
+ dtype=torch.long,
1211
+ device=inputs["decoder_input_ids"].device,
1212
+ )
1213
+ else:
1214
+ inputs["decoder_attention_mask"] = inputs["decoder_input_ids"].ne(pad_token_id).long()
1215
+
1216
+ with torch.inference_mode():
1217
+ generated_ids = self.generate(
1218
+ **inputs,
1219
+ max_new_tokens=max_new_tokens,
1220
+ do_sample=False,
1221
+ num_beams=1,
1222
+ decoder_start_token_id=int(inputs["decoder_input_ids"][0, 0].item()),
1223
+ use_cache=True,
1224
+ )
1225
+
1226
+ if "decoder_attention_mask" in inputs:
1227
+ prompt_lens = inputs["decoder_attention_mask"].sum(dim=1)
1228
+ elif "decoder_input_ids" in inputs:
1229
+ if pad_token_id is None:
1230
+ prompt_lens = torch.full(
1231
+ (inputs["decoder_input_ids"].shape[0],),
1232
+ inputs["decoder_input_ids"].shape[1],
1233
+ dtype=torch.long,
1234
+ device=inputs["decoder_input_ids"].device,
1235
+ )
1236
+ else:
1237
+ prompt_lens = inputs["decoder_input_ids"].ne(pad_token_id).sum(dim=1)
1238
+ elif "attention_mask" in inputs:
1239
+ prompt_lens = inputs["attention_mask"].sum(dim=1)
1240
+ else:
1241
+ if pad_token_id is None:
1242
+ prompt_lens = torch.full(
1243
+ (inputs["input_ids"].shape[0],),
1244
+ inputs["input_ids"].shape[1],
1245
+ dtype=torch.long,
1246
+ device=inputs["input_ids"].device,
1247
+ )
1248
+ else:
1249
+ prompt_lens = inputs["input_ids"].ne(pad_token_id).sum(dim=1)
1250
+
1251
+ generated_ids = generated_ids.cpu().tolist()
1252
+ prompt_lens = prompt_lens.cpu().tolist()
1253
+
1254
+ decoder_input_ids = None
1255
+ if "decoder_input_ids" in inputs:
1256
+ decoder_input_ids = inputs["decoder_input_ids"].cpu().tolist()
1257
+
1258
+ trimmed_token_ids = []
1259
+ for row_idx, prompt_len in enumerate(prompt_lens):
1260
+ token_ids = generated_ids[row_idx]
1261
+ prompt_ids = decoder_input_ids[row_idx][:prompt_len]
1262
+ starts_with_prompt = (
1263
+ prompt_len > 0 and len(token_ids) >= prompt_len and token_ids[:prompt_len] == prompt_ids
1264
+ )
1265
+ if starts_with_prompt:
1266
+ token_ids = token_ids[prompt_len:]
1267
+
1268
+ if eos_token_id is not None:
1269
+ try:
1270
+ token_ids = token_ids[: token_ids.index(eos_token_id)]
1271
+ except ValueError:
1272
+ pass
1273
+
1274
+ trimmed_token_ids.append(token_ids)
1275
+
1276
+ if pipeline_detokenization:
1277
+ # We use python multiprocessing to decode the tokens in a separate process so that, for all but
1278
+ # the final batch, CPU decoding can take place concurrently with GPU inference. This is only
1279
+ # necessary because we aren't using a fast rust tokenizer. The current tokenizer is slow and
1280
+ # steals the GIL if it is run in the main thread.
1281
+ if previous_batch_decode_job is not None and previous_batch_indices is not None:
1282
+ ready_texts = previous_batch_decode_job.result()
1283
+ for row_idx, text in enumerate(ready_texts):
1284
+ transcriptions[previous_batch_indices[row_idx]] = text.strip()
1285
+
1286
+ previous_batch_decode_job = self._decode_pool.submit(decode_worker_fn, trimmed_token_ids, True)
1287
+ previous_batch_indices = batch_indices
1288
+ else:
1289
+ texts = tokenizer.batch_decode(trimmed_token_ids, skip_special_tokens=True)
1290
+ for row_idx, text in enumerate(texts):
1291
+ transcriptions[batch_indices[row_idx]] = text.strip()
1292
+
1293
+ if previous_batch_decode_job is not None and previous_batch_indices is not None:
1294
+ ready_texts = previous_batch_decode_job.result()
1295
+ for row_idx, text in enumerate(ready_texts):
1296
+ transcriptions[previous_batch_indices[row_idx]] = text.strip()
1297
+
1298
+ return transcriptions
1299
+
1300
+ def prepare_inputs_for_generation(
1301
+ self,
1302
+ input_ids,
1303
+ past_key_values=None,
1304
+ attention_mask=None,
1305
+ decoder_input_ids=None,
1306
+ decoder_attention_mask=None,
1307
+ cache_position=None,
1308
+ next_sequence_length=None,
1309
+ **kwargs,
1310
+ ):
1311
+ if next_sequence_length is not None:
1312
+ input_ids = input_ids[:, -next_sequence_length:]
1313
+ else:
1314
+ past_length = _get_cache_seq_length(past_key_values)
1315
+ if past_length > 0:
1316
+ input_ids = input_ids[:, -1:]
1317
+
1318
+ if cache_position is not None:
1319
+ position_ids = cache_position[-input_ids.shape[1] :].unsqueeze(0).expand(input_ids.shape[0], -1)
1320
+ else:
1321
+ past_length = _get_cache_seq_length(past_key_values)
1322
+ position_ids = torch.arange(past_length, past_length + input_ids.shape[1], device=input_ids.device)
1323
+ position_ids = position_ids.unsqueeze(0).expand(input_ids.shape[0], -1)
1324
+
1325
+ return {
1326
+ "input_ids": input_ids,
1327
+ "positions": position_ids,
1328
+ "past_key_values": past_key_values,
1329
+ "cache_position": cache_position,
1330
+ "input_features": kwargs.get("input_features"),
1331
+ "encoder_outputs": kwargs.get("encoder_outputs"),
1332
+ "length": kwargs.get("length"),
1333
+ "attention_mask": attention_mask,
1334
+ "cross_attention_mask": kwargs.get("cross_attention_mask"),
1335
+ "decoder_input_ids": decoder_input_ids,
1336
+ "decoder_attention_mask": decoder_attention_mask,
1337
+ "use_cache": kwargs.get("use_cache"),
1338
+ }
1339
+
1340
+ def _ensure_decode_pool(self, processor):
1341
+ """
1342
+ Creates a single worker process for decoding tokens in a separate process.
1343
+ """
1344
+ tokenizer = processor.tokenizer
1345
+ if tokenizer is None:
1346
+ raise ValueError("processor.tokenizer is required for decode worker initialization.")
1347
+
1348
+ spm_model_file = tokenizer.spm_model_file
1349
+ if not spm_model_file:
1350
+ raise ValueError("Tokenizer must expose spm_model_file for decode worker initialization.")
1351
+
1352
+ if self._decode_pool is not None and self._decode_pool_spm_model_file == spm_model_file:
1353
+ return
1354
+ if self._decode_pool is not None:
1355
+ self._shutdown_decode_pool()
1356
+
1357
+ tokenizer_init_kwargs = {
1358
+ "spm_model_file": spm_model_file,
1359
+ "bos_token": tokenizer.bos_token,
1360
+ "eos_token": tokenizer.eos_token,
1361
+ "unk_token": tokenizer.unk_token,
1362
+ "pad_token": tokenizer.pad_token,
1363
+ "additional_special_tokens": list(tokenizer.additional_special_tokens),
1364
+ "split_special_tokens": bool(getattr(tokenizer, "split_special_tokens", False)),
1365
+ "add_prefix_space": bool(getattr(tokenizer, "add_prefix_space", False)),
1366
+ "sp_model_kwargs": dict(getattr(tokenizer, "sp_model_kwargs", {}) or {}),
1367
+ }
1368
+ self._decode_pool = ProcessPoolExecutor(
1369
+ max_workers=1,
1370
+ mp_context=mp.get_context("fork"),
1371
+ initializer=decode_worker_init,
1372
+ initargs=(tokenizer_init_kwargs,),
1373
+ )
1374
+ self._decode_pool_spm_model_file = spm_model_file
1375
+ atexit.register(self._shutdown_decode_pool)
1376
+
1377
+ def _shutdown_decode_pool(self):
1378
+ if self._decode_pool is None:
1379
+ return
1380
+ self._decode_pool.shutdown(wait=True)
1381
+ self._decode_pool = None
1382
+ self._decode_pool_spm_model_file = None
1383
+
1384
+
1385
+ def _batched_indices(total: int, batch_size: int) -> list[list[int]]:
1386
+ if batch_size <= 0:
1387
+ raise ValueError(f"batch_size must be > 0, got {batch_size}")
1388
+ return [list(range(i, min(i + batch_size, total))) for i in range(0, total, batch_size)]
1389
+
1390
+
1391
+ DECODE_WORKER_TOKENIZER = None
1392
+
1393
+
1394
+ def decode_worker_init(tokenizer_init_kwargs: dict):
1395
+ from .tokenization_cohere_asr import CohereAsrTokenizer
1396
+
1397
+ global DECODE_WORKER_TOKENIZER
1398
+ DECODE_WORKER_TOKENIZER = CohereAsrTokenizer(**tokenizer_init_kwargs)
1399
+
1400
+
1401
+ def decode_worker_fn(trimmed_token_ids: list[list[int]], skip_special_tokens: bool) -> list[str]:
1402
+ if DECODE_WORKER_TOKENIZER is None:
1403
+ raise RuntimeError("Decode worker tokenizer was not initialized.")
1404
+ return DECODE_WORKER_TOKENIZER.batch_decode(trimmed_token_ids, skip_special_tokens=skip_special_tokens)
1405
+
1406
+
1407
+ def _align_decoder_attention_mask(decoder_attention_mask: torch.Tensor, total_kv_len: int) -> torch.Tensor:
1408
+ current_len = int(decoder_attention_mask.shape[-1])
1409
+ if current_len < total_kv_len:
1410
+ # Decoder masks are prefix-aligned and should grow toward the right as
1411
+ # autoregressive generation appends tokens.
1412
+ pad = torch.ones(
1413
+ (decoder_attention_mask.shape[0], total_kv_len - current_len),
1414
+ device=decoder_attention_mask.device,
1415
+ dtype=decoder_attention_mask.dtype,
1416
+ )
1417
+ return torch.cat([decoder_attention_mask, pad], dim=-1)
1418
+ if current_len > total_kv_len:
1419
+ return decoder_attention_mask[:, -total_kv_len:]
1420
+ return decoder_attention_mask
1421
+
1422
+
1423
+ def _get_cache_seq_length(past_key_values) -> int:
1424
+ if past_key_values is None:
1425
+ return 0
1426
+ if hasattr(past_key_values, "get_seq_length"):
1427
+ return int(past_key_values.get_seq_length())
1428
+ if isinstance(past_key_values, tuple) and past_key_values:
1429
+ return int(past_key_values[0][0][0].shape[-2])
1430
+ return 0
1431
+
1432
+
1433
+ def _get_static_cache_len(past_key_values) -> Optional[int]:
1434
+ """Return self-attention max_cache_len for StaticCache, otherwise None."""
1435
+ cache = past_key_values
1436
+ if isinstance(cache, EncoderDecoderCache):
1437
+ cache = cache.self_attention_cache
1438
+ if isinstance(cache, StaticCache) and cache.layers:
1439
+ return cache.layers[0].max_cache_len
1440
+ return None
1441
+
1442
+
1443
+ def _get_cache_kv(cache_layer, layer_idx: int):
1444
+ if hasattr(cache_layer, "layers"):
1445
+ if layer_idx < len(cache_layer.layers):
1446
+ layer = cache_layer.layers[layer_idx]
1447
+ return layer.keys, layer.values
1448
+ return None, None
1449
+
1450
+ key_cache = getattr(cache_layer, "key_cache", None)
1451
+ value_cache = getattr(cache_layer, "value_cache", None)
1452
+ if key_cache is not None and value_cache is not None and layer_idx < len(key_cache):
1453
+ return key_cache[layer_idx], value_cache[layer_idx]
1454
+
1455
+ return None, None
1456
+
1457
+
1458
+ # --- Automatic chunking helper functions ---
1459
+
1460
+
1461
+ def split_audio_chunks_energy(
1462
+ waveform: np.ndarray,
1463
+ sample_rate: int,
1464
+ max_audio_clip_s: float,
1465
+ overlap_chunk_second: float,
1466
+ min_energy_window_samples: int,
1467
+ ) -> list[np.ndarray]:
1468
+ """
1469
+ Split audio waveform into chunks based on energy-based boundaries.
1470
+ """
1471
+ if waveform.ndim != 1:
1472
+ raise ValueError(f"Expected mono waveform (1D), got shape={waveform.shape}")
1473
+ chunk_size = max(1, int(round(max_audio_clip_s * sample_rate)))
1474
+ # NeMo parity: overlap_chunk_second in energy_split mode is the split-search
1475
+ # context near the chunk boundary, not literal waveform overlap between chunks.
1476
+ boundary_context_size = max(1, int(round(overlap_chunk_second * sample_rate)))
1477
+ total_samples = waveform.shape[0]
1478
+ if total_samples <= chunk_size:
1479
+ return [waveform.copy()]
1480
+
1481
+ chunks_meta: list[tuple[int, int]] = []
1482
+ idx = 0
1483
+ while idx < total_samples:
1484
+ if idx + chunk_size >= total_samples:
1485
+ chunks_meta.append((idx, total_samples))
1486
+ break
1487
+
1488
+ search_start = max(idx, idx + chunk_size - boundary_context_size)
1489
+ search_end = min(idx + chunk_size, total_samples)
1490
+ if search_end <= search_start:
1491
+ split_point = idx + chunk_size
1492
+ else:
1493
+ split_point = _find_split_point_energy(
1494
+ waveform,
1495
+ start_idx=search_start,
1496
+ end_idx=search_end,
1497
+ min_energy_window_samples=min_energy_window_samples,
1498
+ )
1499
+ split_point = max(idx + 1, min(split_point, total_samples))
1500
+ chunks_meta.append((idx, split_point))
1501
+ idx = split_point
1502
+
1503
+ return [waveform[start:end].copy() for start, end in chunks_meta if end > start]
1504
+
1505
+
1506
+ def _find_split_point_energy(
1507
+ waveform: np.ndarray, start_idx: int, end_idx: int, min_energy_window_samples: int
1508
+ ) -> int:
1509
+ segment = waveform[start_idx:end_idx]
1510
+ if segment.shape[0] <= min_energy_window_samples:
1511
+ return (start_idx + end_idx) // 2
1512
+
1513
+ min_energy = float("inf")
1514
+ quietest_idx = start_idx
1515
+ upper = segment.shape[0] - min_energy_window_samples
1516
+ for i in range(0, upper, min_energy_window_samples):
1517
+ window = segment[i : i + min_energy_window_samples]
1518
+ energy = float(np.sqrt(np.mean(window * window)))
1519
+ if energy < min_energy:
1520
+ min_energy = energy
1521
+ quietest_idx = start_idx + i
1522
+ return quietest_idx
1523
+
1524
+
1525
+ def join_chunk_texts(texts: list[str], separator: str = " ") -> str:
1526
+ parts = [piece.strip() for piece in texts if piece and piece.strip()]
1527
+ if not parts:
1528
+ return ""
1529
+ return separator.join(parts)
1530
+
1531
+
1532
+ def get_chunk_separator(language: str) -> str:
1533
+ return "" if language in NO_SPACE_LANGS else " "
preprocessor_config.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "auto_map": {
3
+ "AutoFeatureExtractor": "processing_cohere_asr.CohereAsrFeatureExtractor"
4
+ },
5
+ "dither": 1e-05,
6
+ "feature_extractor_type": "CohereAsrFeatureExtractor",
7
+ "feature_size": 128,
8
+ "frame_splicing": 1,
9
+ "log": true,
10
+ "n_fft": 512,
11
+ "n_window_size": 400,
12
+ "n_window_stride": 160,
13
+ "normalize": "per_feature",
14
+ "pad_to": 0,
15
+ "padding_value": 0.0,
16
+ "sampling_rate": 16000,
17
+ "window": "hann"
18
+ }
processing_cohere_asr.py ADDED
@@ -0,0 +1,545 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ import math
3
+ import random
4
+ from pathlib import Path
5
+
6
+ import librosa
7
+ import numpy as np
8
+ import torch
9
+ import torch.nn.functional as F
10
+ from safetensors.torch import load_file as safetensors_load_file
11
+ from torch import nn
12
+ from transformers import AutoFeatureExtractor, AutoTokenizer, BatchFeature
13
+ from transformers.feature_extraction_sequence_utils import SequenceFeatureExtractor
14
+ from transformers.processing_utils import ProcessorMixin
15
+
16
+ from .configuration_cohere_asr import _dynamo_disable
17
+
18
+ logger = logging.getLogger(__name__)
19
+
20
+ DITHER_CONSTANT = 1e-5
21
+
22
+
23
+ class FilterbankFeatures(nn.Module):
24
+ """Filterbank features extraction module.
25
+
26
+ Follows NeMo's FilterbankFeatures implementation.
27
+ """
28
+
29
+ window: torch.Tensor
30
+ fb: torch.Tensor
31
+
32
+ def __init__(
33
+ self,
34
+ sample_rate=16000,
35
+ n_window_size=320,
36
+ n_window_stride=160,
37
+ window="hann",
38
+ normalize="per_feature",
39
+ n_fft=None,
40
+ preemph=0.97,
41
+ nfilt=64,
42
+ lowfreq=0,
43
+ highfreq=None,
44
+ log=True,
45
+ log_zero_guard_type="add",
46
+ log_zero_guard_value=2**-24,
47
+ dither=DITHER_CONSTANT,
48
+ pad_to=16,
49
+ max_duration=30,
50
+ frame_splicing=1,
51
+ exact_pad=False,
52
+ pad_value=0,
53
+ mag_power=2.0,
54
+ use_grads=False,
55
+ rng=None,
56
+ nb_augmentation_prob=0.0,
57
+ nb_max_freq=4000,
58
+ mel_norm="slaney",
59
+ stft_exact_pad=False,
60
+ stft_conv=False,
61
+ device="cpu",
62
+ ):
63
+ super().__init__()
64
+ if stft_conv or stft_exact_pad:
65
+ logger.warning(
66
+ "torch_stft compatibility flags are deprecated; " "forcing behavior to default torch.stft path."
67
+ )
68
+ if exact_pad and n_window_stride % 2 == 1:
69
+ raise NotImplementedError(f"{self} received exact_pad=True with odd hop length ({n_window_stride}).")
70
+
71
+ if (
72
+ n_window_size is None
73
+ or n_window_stride is None
74
+ or not isinstance(n_window_size, int)
75
+ or not isinstance(n_window_stride, int)
76
+ or n_window_size <= 0
77
+ or n_window_stride <= 0
78
+ ):
79
+ raise ValueError("n_window_size and n_window_stride must be positive ints.")
80
+
81
+ self.log_zero_guard_value = log_zero_guard_value
82
+ self.sample_rate = sample_rate
83
+ self.win_length = n_window_size
84
+ self.hop_length = n_window_stride
85
+ self.n_fft = n_fft or 2 ** math.ceil(math.log2(self.win_length))
86
+ self.stft_pad_amount = (self.n_fft - self.hop_length) // 2 if exact_pad else None
87
+ self.exact_pad = exact_pad
88
+ self.max_duration = max_duration
89
+
90
+ torch_windows = {
91
+ "hann": torch.hann_window,
92
+ "hamming": torch.hamming_window,
93
+ "blackman": torch.blackman_window,
94
+ "bartlett": torch.bartlett_window,
95
+ "none": None,
96
+ }
97
+ window_fn = torch_windows.get(window)
98
+ window_tensor = window_fn(self.win_length, periodic=False) if window_fn else None
99
+ self.register_buffer("window", window_tensor)
100
+
101
+ self.normalize = normalize
102
+ self.log = log
103
+ self.dither = dither
104
+ self.frame_splicing = frame_splicing
105
+ self.nfilt = nfilt
106
+ self.preemph = preemph
107
+ self.pad_to = pad_to
108
+ highfreq = highfreq or sample_rate / 2
109
+ self.pad_min_duration = 0.0
110
+ self.pad_direction = "both"
111
+ self.pad_value = pad_value
112
+ self.mag_power = mag_power
113
+ self.nb_augmentation_prob = nb_augmentation_prob
114
+
115
+ filterbanks = torch.tensor(
116
+ librosa.filters.mel(
117
+ sr=sample_rate, n_fft=self.n_fft, n_mels=nfilt, fmin=lowfreq, fmax=highfreq, norm=mel_norm
118
+ ),
119
+ dtype=torch.float,
120
+ ).unsqueeze(0)
121
+ self.register_buffer("fb", filterbanks)
122
+
123
+ max_length = self.get_seq_len(torch.tensor(max_duration * sample_rate, dtype=torch.float))
124
+ max_pad = pad_to - (max_length % pad_to) if pad_to > 0 else 0
125
+ self.max_length = max_length + max_pad
126
+
127
+ if log_zero_guard_type not in ["add", "clamp"]:
128
+ raise ValueError("log_zero_guard_type must be 'add' or 'clamp'.")
129
+ self.log_zero_guard_type = log_zero_guard_type
130
+
131
+ self.use_grads = use_grads
132
+ if not use_grads:
133
+ self.forward = torch.no_grad()(self.forward)
134
+ self._rng = random.Random() if rng is None else rng
135
+
136
+ if self.nb_augmentation_prob > 0.0:
137
+ if nb_max_freq >= sample_rate / 2:
138
+ self.nb_augmentation_prob = 0.0
139
+ else:
140
+ self._nb_max_fft_bin = int((nb_max_freq / sample_rate) * self.n_fft)
141
+
142
+ if self.window is None:
143
+ raise RuntimeError("Expected a window tensor for STFT feature extraction.")
144
+ if self.fb is None:
145
+ raise RuntimeError("Expected mel filterbank weights for feature extraction.")
146
+ self.window = self.window.to(dtype=torch.bfloat16)
147
+ self.fb = self.fb.to(dtype=torch.bfloat16)
148
+ self.generator = torch.Generator(device=device)
149
+ self.generator.manual_seed(0)
150
+
151
+ @_dynamo_disable
152
+ def _apply_dither(self, x, seq_len_time):
153
+ """Apply deterministic per-sample dither outside torch.compile.
154
+
155
+ Each sample is seeded by its valid waveform length so that dither noise
156
+ is batch-composition invariant (a sample's features depend only on its
157
+ own content, not on what else is in the batch).
158
+ """
159
+ if self.dither <= 0:
160
+ return x
161
+ for i in range(x.shape[0]):
162
+ valid_samples = min(int(seq_len_time[i].item()), x.shape[1])
163
+ if valid_samples <= 0:
164
+ continue
165
+ self.generator.manual_seed(valid_samples)
166
+ noise = torch.randn(
167
+ (valid_samples,),
168
+ dtype=x.dtype,
169
+ device=x.device,
170
+ generator=self.generator,
171
+ )
172
+ x[i, :valid_samples] += self.dither * noise
173
+ return x
174
+
175
+ @_dynamo_disable
176
+ def stft(self, x):
177
+ with torch.amp.autocast(x.device.type, enabled=False):
178
+ return torch.view_as_real(
179
+ torch.stft(
180
+ x,
181
+ n_fft=self.n_fft,
182
+ hop_length=self.hop_length,
183
+ win_length=self.win_length,
184
+ center=not self.exact_pad,
185
+ window=self.window.to(dtype=torch.float, device=x.device),
186
+ return_complex=True,
187
+ pad_mode="constant",
188
+ )
189
+ )
190
+
191
+ def log_zero_guard_value_fn(self, x):
192
+ if isinstance(self.log_zero_guard_value, str):
193
+ if self.log_zero_guard_value == "tiny":
194
+ return torch.finfo(x.dtype).tiny
195
+ if self.log_zero_guard_value == "eps":
196
+ return torch.finfo(x.dtype).eps
197
+ raise ValueError("log_zero_guard_value must be number, 'tiny', or 'eps' when str.")
198
+ return self.log_zero_guard_value
199
+
200
+ def get_seq_len(self, seq_len):
201
+ pad_amount = self.stft_pad_amount * 2 if self.stft_pad_amount is not None else self.n_fft // 2 * 2
202
+ seq_len = torch.floor_divide((seq_len + pad_amount - self.n_fft), self.hop_length)
203
+ return seq_len.to(dtype=torch.long)
204
+
205
+ def splice_frames(self, x, frame_splicing):
206
+ seq = [x]
207
+ for n in range(1, frame_splicing):
208
+ seq.append(torch.cat([x[:, :, :n], x[:, :, n:]], dim=2))
209
+ return torch.cat(seq, dim=1)
210
+
211
+ def normalize_batch(self, x, seq_len, normalize_type):
212
+ if normalize_type != "per_feature":
213
+ raise ValueError("Only per_feature normalization is supported.")
214
+ batch_size = x.shape[0]
215
+ max_time = x.shape[2]
216
+ time_steps = torch.arange(max_time, device=x.device).unsqueeze(0).expand(batch_size, max_time)
217
+ valid_mask = time_steps < seq_len.unsqueeze(1)
218
+ x_mean_num = torch.where(valid_mask.unsqueeze(1), x, 0.0).sum(axis=2)
219
+ x_mean_den = valid_mask.sum(axis=1)
220
+ x_mean = x_mean_num / x_mean_den.unsqueeze(1)
221
+ x_std = torch.sqrt(
222
+ torch.sum(
223
+ torch.where(valid_mask.unsqueeze(1), x - x_mean.unsqueeze(2), 0.0) ** 2,
224
+ axis=2,
225
+ )
226
+ / (x_mean_den.unsqueeze(1) - 1.0)
227
+ )
228
+ x_std = x_std.masked_fill(x_std.isnan(), 0.0)
229
+ x_std += DITHER_CONSTANT
230
+ return (x - x_mean.unsqueeze(2)) / x_std.unsqueeze(2), x_mean, x_std
231
+
232
+ def forward(self, x, seq_len, linear_spec=False):
233
+ if x.shape[1] < self.sample_rate * self.pad_min_duration:
234
+ pad_amount = int(self.sample_rate * self.pad_min_duration) - x.shape[1]
235
+ if self.pad_direction == "right":
236
+ x = F.pad(x, (0, pad_amount), value=self.pad_value)
237
+ elif self.pad_direction == "left":
238
+ x = F.pad(x, (pad_amount, 0), value=self.pad_value)
239
+ elif self.pad_direction == "both":
240
+ left_pad = pad_amount // 2
241
+ right_pad = pad_amount - left_pad
242
+ x = F.pad(x, (left_pad, right_pad), value=self.pad_value)
243
+ else:
244
+ raise ValueError(f"Invalid pad_direction: {self.pad_direction}")
245
+ seq_len = torch.tensor([x.shape[1]], dtype=torch.float, device=x.device)
246
+
247
+ seq_len_time = seq_len
248
+ seq_len_unfixed = self.get_seq_len(seq_len)
249
+ seq_len = torch.where(seq_len == 0, torch.zeros_like(seq_len_unfixed), seq_len_unfixed)
250
+
251
+ if self.stft_pad_amount is not None:
252
+ x = torch.nn.functional.pad(
253
+ x.unsqueeze(1), (self.stft_pad_amount, self.stft_pad_amount), "constant"
254
+ ).squeeze(1)
255
+
256
+ x = self._apply_dither(x, seq_len_time)
257
+
258
+ if self.preemph is not None:
259
+ timemask = torch.arange(x.shape[1], device=x.device).unsqueeze(0) < seq_len_time.unsqueeze(1)
260
+ x = torch.cat((x[:, 0].unsqueeze(1), x[:, 1:] - self.preemph * x[:, :-1]), dim=1)
261
+ x = x.masked_fill(~timemask, 0.0)
262
+
263
+ x = self.stft(x)
264
+ guard = 0 if not self.use_grads else DITHER_CONSTANT
265
+ x = torch.sqrt(x.pow(2).sum(-1) + guard)
266
+
267
+ if self.mag_power != 1.0:
268
+ x = x.pow(self.mag_power)
269
+ if linear_spec:
270
+ return x, seq_len
271
+
272
+ with torch.amp.autocast(x.device.type, enabled=False):
273
+ x = torch.matmul(self.fb.to(x.dtype), x)
274
+
275
+ if self.log:
276
+ if self.log_zero_guard_type == "add":
277
+ x = torch.log(x + self.log_zero_guard_value_fn(x))
278
+ elif self.log_zero_guard_type == "clamp":
279
+ x = torch.log(torch.clamp(x, min=self.log_zero_guard_value_fn(x)))
280
+ else:
281
+ raise ValueError("log_zero_guard_type was not understood")
282
+
283
+ if self.frame_splicing > 1:
284
+ x = self.splice_frames(x, self.frame_splicing)
285
+ if self.normalize:
286
+ x, _, _ = self.normalize_batch(x, seq_len, normalize_type=self.normalize)
287
+
288
+ max_len = x.size(-1)
289
+ mask = torch.arange(max_len, device=x.device)
290
+ mask = mask.repeat(x.size(0), 1) >= seq_len.unsqueeze(1)
291
+ x = x.masked_fill(mask.unsqueeze(1).to(device=x.device), self.pad_value)
292
+ del mask
293
+
294
+ if self.pad_to == "max":
295
+ x = nn.functional.pad(x, (0, self.max_length - x.size(-1)), value=self.pad_value)
296
+ elif self.pad_to > 0:
297
+ pad_amt = x.size(-1) % self.pad_to
298
+ if pad_amt != 0:
299
+ x = nn.functional.pad(x, (0, self.pad_to - pad_amt), value=self.pad_value)
300
+ return x, seq_len
301
+
302
+
303
+ class CohereAsrFeatureExtractor(SequenceFeatureExtractor):
304
+ """HF-compatible feature extractor wrapping FilterbankFeatures."""
305
+
306
+ model_input_names = ["input_features"]
307
+
308
+ def __init__(
309
+ self,
310
+ feature_size=64,
311
+ sampling_rate=16000,
312
+ padding_value=0.0,
313
+ max_duration=30,
314
+ n_window_size=320,
315
+ n_window_stride=160,
316
+ window="hann",
317
+ normalize="per_feature",
318
+ n_fft=None,
319
+ preemph=0.97,
320
+ lowfreq=0,
321
+ highfreq=None,
322
+ log=True,
323
+ log_zero_guard_type="add",
324
+ log_zero_guard_value=2**-24,
325
+ dither=DITHER_CONSTANT,
326
+ pad_to=16,
327
+ frame_splicing=1,
328
+ exact_pad=False,
329
+ mag_power=2.0,
330
+ nb_augmentation_prob=0.0,
331
+ nb_max_freq=4000,
332
+ mel_norm="slaney",
333
+ stft_exact_pad=False,
334
+ stft_conv=False,
335
+ device="cpu",
336
+ **kwargs,
337
+ ):
338
+ super().__init__(
339
+ feature_size=feature_size,
340
+ sampling_rate=sampling_rate,
341
+ padding_value=padding_value,
342
+ **kwargs,
343
+ )
344
+ self.max_duration = max_duration
345
+ self.hop_length = n_window_stride
346
+ self._device = str(device)
347
+ self._fb_config = dict(
348
+ sample_rate=sampling_rate,
349
+ n_window_size=n_window_size,
350
+ n_window_stride=n_window_stride,
351
+ window=window,
352
+ normalize=normalize,
353
+ n_fft=n_fft,
354
+ preemph=preemph,
355
+ nfilt=feature_size,
356
+ lowfreq=lowfreq,
357
+ highfreq=highfreq,
358
+ log=log,
359
+ log_zero_guard_type=log_zero_guard_type,
360
+ log_zero_guard_value=log_zero_guard_value,
361
+ dither=dither,
362
+ pad_to=pad_to,
363
+ max_duration=max_duration,
364
+ frame_splicing=frame_splicing,
365
+ exact_pad=exact_pad,
366
+ pad_value=padding_value,
367
+ mag_power=mag_power,
368
+ nb_augmentation_prob=nb_augmentation_prob,
369
+ nb_max_freq=nb_max_freq,
370
+ mel_norm=mel_norm,
371
+ stft_exact_pad=stft_exact_pad,
372
+ stft_conv=stft_conv,
373
+ device=device,
374
+ )
375
+ self._filterbank = None
376
+
377
+ @classmethod
378
+ def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
379
+ fe = super().from_pretrained(pretrained_model_name_or_path, **kwargs)
380
+ model_dir = Path(pretrained_model_name_or_path)
381
+ if model_dir.is_dir():
382
+ _maybe_load_preprocessor_buffers_from_checkpoint(feature_extractor=fe, model_dir=model_dir)
383
+ return fe
384
+
385
+ @property
386
+ def filterbank(self):
387
+ if self._filterbank is None:
388
+ fb = FilterbankFeatures(**self._fb_config)
389
+ fb.eval()
390
+ self._filterbank = fb.to(self._device)
391
+ return self._filterbank
392
+
393
+ def get_seq_len(self, seq_len):
394
+ return self.filterbank.get_seq_len(seq_len)
395
+
396
+ def __call__(
397
+ self,
398
+ raw_speech,
399
+ sampling_rate=None,
400
+ return_tensors=None,
401
+ **kwargs,
402
+ ):
403
+ """Extract mel features from raw waveform input."""
404
+ if sampling_rate is not None and int(sampling_rate) != int(self.sampling_rate):
405
+ raise ValueError(f"Expected sampling_rate={self.sampling_rate}, got {sampling_rate}")
406
+
407
+ if isinstance(raw_speech, np.ndarray):
408
+ if raw_speech.ndim == 1:
409
+ raw_speech = [raw_speech]
410
+ else:
411
+ raw_speech = [s for s in raw_speech]
412
+ elif isinstance(raw_speech, torch.Tensor):
413
+ if raw_speech.ndim == 1:
414
+ raw_speech = [raw_speech.detach().cpu().numpy()]
415
+ else:
416
+ raw_speech = [s.detach().cpu().numpy() for s in raw_speech]
417
+ elif not isinstance(raw_speech, (list, tuple)):
418
+ raise TypeError("raw_speech must be an array/tensor or list of arrays.")
419
+
420
+ normalized = []
421
+ for sample in raw_speech:
422
+ arr = np.asarray(sample, dtype=np.float32)
423
+ if arr.ndim != 1:
424
+ raise ValueError("Each audio sample must be 1D waveform.")
425
+ normalized.append(arr)
426
+
427
+ seq_len = torch.tensor([s.shape[0] for s in normalized], dtype=torch.long)
428
+ max_len = max(s.shape[0] for s in normalized)
429
+ padded = np.zeros((len(normalized), max_len), dtype=np.float32)
430
+ for i, s in enumerate(normalized):
431
+ padded[i, : s.shape[0]] = s
432
+
433
+ audio_tensor = torch.from_numpy(padded).to(self._device)
434
+ seq_len = seq_len.to(self._device)
435
+ with torch.no_grad():
436
+ input_features, length = self.filterbank(audio_tensor, seq_len)
437
+
438
+ result = BatchFeature({"input_features": input_features.cpu(), "length": length.cpu()})
439
+ if return_tensors is not None:
440
+ result = result.convert_to_tensors(return_tensors)
441
+ return result
442
+
443
+
444
+ class CohereAsrProcessor(ProcessorMixin):
445
+ """HF-compatible processor for Cohere ASR.
446
+
447
+ ``ProcessorMixin._get_arguments_from_pretrained`` resolves sub-component
448
+ class names by looking them up inside the ``transformers`` package, which
449
+ fails for custom remote-code classes. We override ``from_pretrained`` to
450
+ use ``AutoFeatureExtractor`` / ``AutoTokenizer`` instead -- those honour
451
+ ``auto_map`` and ``trust_remote_code``.
452
+ """
453
+
454
+ attributes = ["feature_extractor", "tokenizer"]
455
+ feature_extractor_class = "CohereAsrFeatureExtractor"
456
+ tokenizer_class = "CohereAsrTokenizer"
457
+
458
+ def __init__(self, feature_extractor=None, tokenizer=None, **kwargs):
459
+ if feature_extractor is None:
460
+ raise ValueError(
461
+ "CohereAsrProcessor requires a CohereAsrFeatureExtractor instance. " "Got feature_extractor=None."
462
+ )
463
+ if tokenizer is None:
464
+ raise ValueError("CohereAsrProcessor requires a CohereAsrTokenizer instance. " "Got tokenizer=None.")
465
+ # Bypass super().__init__ which calls get_possibly_dynamic_module to
466
+ # validate sub-component types. That lookup searches the transformers
467
+ # package namespace and fails for remote-code classes. We set the
468
+ # attributes directly instead -- the type checks above are sufficient.
469
+ self.feature_extractor = feature_extractor
470
+ self.tokenizer = tokenizer
471
+ self.chat_template = kwargs.get("chat_template", None)
472
+
473
+ @classmethod
474
+ def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
475
+ trust_remote_code = kwargs.pop("trust_remote_code", True)
476
+ feature_extractor = AutoFeatureExtractor.from_pretrained(
477
+ pretrained_model_name_or_path,
478
+ trust_remote_code=trust_remote_code,
479
+ **kwargs,
480
+ )
481
+ tokenizer = AutoTokenizer.from_pretrained(
482
+ pretrained_model_name_or_path,
483
+ trust_remote_code=trust_remote_code,
484
+ **kwargs,
485
+ )
486
+ return cls(feature_extractor=feature_extractor, tokenizer=tokenizer)
487
+
488
+ def __call__(
489
+ self,
490
+ audio=None,
491
+ text=None,
492
+ sampling_rate=None,
493
+ return_tensors=None,
494
+ **kwargs,
495
+ ):
496
+ """Run audio feature extraction and optional text tokenization."""
497
+ if audio is None:
498
+ raise ValueError("audio is required for CohereAsrProcessor.")
499
+
500
+ result = self.feature_extractor(audio, sampling_rate=sampling_rate, return_tensors=return_tensors)
501
+
502
+ if text is not None:
503
+ add_special_tokens = kwargs.pop("add_special_tokens", False)
504
+ text_inputs = self.tokenizer(
505
+ text,
506
+ return_tensors=return_tensors,
507
+ add_special_tokens=add_special_tokens,
508
+ **kwargs,
509
+ )
510
+ result["input_ids"] = text_inputs["input_ids"]
511
+ if "attention_mask" in text_inputs:
512
+ result["attention_mask"] = text_inputs["attention_mask"]
513
+ return result
514
+
515
+ def batch_decode(self, *args, **kwargs):
516
+ return self.tokenizer.batch_decode(*args, **kwargs)
517
+
518
+ def decode(self, *args, **kwargs):
519
+ return self.tokenizer.decode(*args, **kwargs)
520
+
521
+
522
+ def _maybe_load_preprocessor_buffers_from_checkpoint(
523
+ feature_extractor: CohereAsrFeatureExtractor, model_dir: Path
524
+ ) -> None:
525
+ """
526
+ Load exported frontend buffers if they exist in checkpoint weights.
527
+ """
528
+ safetensor_path = model_dir / "model.safetensors"
529
+ if not safetensor_path.exists():
530
+ return
531
+ try:
532
+ state = safetensors_load_file(safetensor_path.as_posix())
533
+ except Exception:
534
+ return
535
+
536
+ fb = state.get("preprocessor.featurizer.fb")
537
+ window = state.get("preprocessor.featurizer.window")
538
+ if fb is None or window is None:
539
+ return
540
+
541
+ fb_module = feature_extractor.filterbank
542
+ target_device = fb_module.fb.device
543
+ target_dtype = fb_module.fb.dtype
544
+ fb_module.fb = fb.to(device=target_device, dtype=target_dtype)
545
+ fb_module.window = window.to(device=target_device, dtype=target_dtype)
processor_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "auto_map": {
3
+ "AutoProcessor": "processing_cohere_asr.CohereAsrProcessor"
4
+ },
5
+ "processor_class": "CohereAsrProcessor"
6
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|nospeech|>",
4
+ "<|pnc|>",
5
+ "<|nopnc|>",
6
+ "<|startofcontext|>",
7
+ "<|itn|>",
8
+ "<|noitn|>",
9
+ "<|timestamp|>",
10
+ "<|notimestamp|>",
11
+ "<|diarize|>",
12
+ "<|nodiarize|>",
13
+ "<|spkchange|>",
14
+ "<|audioseparator|>",
15
+ "<|emo:undefined|>",
16
+ "<|emo:neutral|>",
17
+ "<|emo:happy|>",
18
+ "<|emo:sad|>",
19
+ "<|emo:angry|>",
20
+ "<|unklang|>",
21
+ "<|aa|>",
22
+ "<|ab|>",
23
+ "<|af|>",
24
+ "<|ak|>",
25
+ "<|sq|>",
26
+ "<|am|>",
27
+ "<|ar|>",
28
+ "<|an|>",
29
+ "<|hy|>",
30
+ "<|as|>",
31
+ "<|av|>",
32
+ "<|ae|>",
33
+ "<|ay|>",
34
+ "<|az|>",
35
+ "<|bm|>",
36
+ "<|ba|>",
37
+ "<|eu|>",
38
+ "<|be|>",
39
+ "<|bn|>",
40
+ "<|bi|>",
41
+ "<|bs|>",
42
+ "<|br|>",
43
+ "<|bg|>",
44
+ "<|my|>",
45
+ "<|ca|>",
46
+ "<|ch|>",
47
+ "<|ce|>",
48
+ "<|ny|>",
49
+ "<|zh|>",
50
+ "<|cu|>",
51
+ "<|cv|>",
52
+ "<|kw|>",
53
+ "<|co|>",
54
+ "<|cr|>",
55
+ "<|hr|>",
56
+ "<|cs|>",
57
+ "<|da|>",
58
+ "<|dv|>",
59
+ "<|nl|>",
60
+ "<|dz|>",
61
+ "<|en|>",
62
+ "<|eo|>",
63
+ "<|et|>",
64
+ "<|ee|>",
65
+ "<|fo|>",
66
+ "<|fj|>",
67
+ "<|fi|>",
68
+ "<|fr|>",
69
+ "<|fy|>",
70
+ "<|ff|>",
71
+ "<|gd|>",
72
+ "<|gl|>",
73
+ "<|lg|>",
74
+ "<|ka|>",
75
+ "<|de|>",
76
+ "<|el|>",
77
+ "<|kl|>",
78
+ "<|gn|>",
79
+ "<|gu|>",
80
+ "<|ht|>",
81
+ "<|ha|>",
82
+ "<|he|>",
83
+ "<|hz|>",
84
+ "<|hi|>",
85
+ "<|ho|>",
86
+ "<|hu|>",
87
+ "<|is|>",
88
+ "<|io|>",
89
+ "<|ig|>",
90
+ "<|id|>",
91
+ "<|ia|>",
92
+ "<|ie|>",
93
+ "<|iu|>",
94
+ "<|ik|>",
95
+ "<|ga|>",
96
+ "<|it|>",
97
+ "<|ja|>",
98
+ "<|jv|>",
99
+ "<|kn|>",
100
+ "<|kr|>",
101
+ "<|ks|>",
102
+ "<|kk|>",
103
+ "<|km|>",
104
+ "<|ki|>",
105
+ "<|rw|>",
106
+ "<|ky|>",
107
+ "<|kv|>",
108
+ "<|kg|>",
109
+ "<|ko|>",
110
+ "<|kj|>",
111
+ "<|ku|>",
112
+ "<|lo|>",
113
+ "<|la|>",
114
+ "<|lv|>",
115
+ "<|li|>",
116
+ "<|ln|>",
117
+ "<|lt|>",
118
+ "<|lu|>",
119
+ "<|lb|>",
120
+ "<|mk|>",
121
+ "<|mg|>",
122
+ "<|ms|>",
123
+ "<|ml|>",
124
+ "<|mt|>",
125
+ "<|gv|>",
126
+ "<|mi|>",
127
+ "<|mr|>",
128
+ "<|mh|>",
129
+ "<|mn|>",
130
+ "<|na|>",
131
+ "<|nv|>",
132
+ "<|nd|>",
133
+ "<|nr|>",
134
+ "<|ng|>",
135
+ "<|ne|>",
136
+ "<|no|>",
137
+ "<|nb|>",
138
+ "<|nn|>",
139
+ "<|oc|>",
140
+ "<|oj|>",
141
+ "<|or|>",
142
+ "<|om|>",
143
+ "<|os|>",
144
+ "<|pi|>",
145
+ "<|ps|>",
146
+ "<|fa|>",
147
+ "<|pl|>",
148
+ "<|pt|>",
149
+ "<|pa|>",
150
+ "<|qu|>",
151
+ "<|ro|>",
152
+ "<|rm|>",
153
+ "<|rn|>",
154
+ "<|ru|>",
155
+ "<|se|>",
156
+ "<|sm|>",
157
+ "<|sg|>",
158
+ "<|sa|>",
159
+ "<|sc|>",
160
+ "<|sr|>",
161
+ "<|sn|>",
162
+ "<|sd|>",
163
+ "<|si|>",
164
+ "<|sk|>",
165
+ "<|sl|>",
166
+ "<|so|>",
167
+ "<|st|>",
168
+ "<|es|>",
169
+ "<|su|>",
170
+ "<|sw|>",
171
+ "<|ss|>",
172
+ "<|sv|>",
173
+ "<|tl|>",
174
+ "<|ty|>",
175
+ "<|tg|>",
176
+ "<|ta|>",
177
+ "<|tt|>",
178
+ "<|te|>",
179
+ "<|th|>",
180
+ "<|bo|>",
181
+ "<|ti|>",
182
+ "<|to|>",
183
+ "<|ts|>",
184
+ "<|tn|>",
185
+ "<|tr|>",
186
+ "<|tk|>",
187
+ "<|tw|>",
188
+ "<|ug|>",
189
+ "<|uk|>",
190
+ "<|ur|>",
191
+ "<|uz|>",
192
+ "<|ve|>",
193
+ "<|vi|>",
194
+ "<|vo|>",
195
+ "<|wa|>",
196
+ "<|cy|>",
197
+ "<|wo|>",
198
+ "<|xh|>",
199
+ "<|ii|>",
200
+ "<|yi|>",
201
+ "<|yo|>",
202
+ "<|za|>",
203
+ "<|zu|>",
204
+ "<|spk0|>",
205
+ "<|spk1|>",
206
+ "<|spk2|>",
207
+ "<|spk3|>",
208
+ "<|spk4|>",
209
+ "<|spk5|>",
210
+ "<|spk6|>",
211
+ "<|spk7|>",
212
+ "<|spk8|>",
213
+ "<|spk9|>",
214
+ "<|spk10|>",
215
+ "<|spk11|>",
216
+ "<|spk12|>",
217
+ "<|spk13|>",
218
+ "<|spk14|>",
219
+ "<|spk15|>",
220
+ "<|spltoken0|>",
221
+ "<|spltoken1|>",
222
+ "<|spltoken2|>",
223
+ "<|spltoken3|>",
224
+ "<|spltoken4|>",
225
+ "<|spltoken5|>",
226
+ "<|spltoken6|>",
227
+ "<|spltoken7|>",
228
+ "<|spltoken8|>",
229
+ "<|spltoken9|>",
230
+ "<|spltoken10|>",
231
+ "<|spltoken11|>",
232
+ "<|spltoken12|>",
233
+ "<|spltoken13|>",
234
+ "<|spltoken14|>",
235
+ "<|spltoken15|>",
236
+ "<|spltoken16|>",
237
+ "<|spltoken17|>",
238
+ "<|spltoken18|>",
239
+ "<|spltoken19|>",
240
+ "<|spltoken20|>",
241
+ "<|spltoken21|>",
242
+ "<|spltoken22|>",
243
+ "<|spltoken23|>",
244
+ "<|spltoken24|>",
245
+ "<|spltoken25|>",
246
+ "<|spltoken26|>",
247
+ "<|spltoken27|>",
248
+ "<|spltoken28|>",
249
+ "<|spltoken29|>",
250
+ "<|spltoken30|>",
251
+ "<|spltoken31|>",
252
+ "<|spltoken32|>",
253
+ "<|spltoken33|>"
254
+ ],
255
+ "bos_token": "<|startoftranscript|>",
256
+ "eos_token": "<|endoftext|>",
257
+ "pad_token": "<pad>",
258
+ "unk_token": "<unk>"
259
+ }
tokenization_cohere_asr.py ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from typing import Optional
3
+
4
+ import sentencepiece as spm
5
+ from transformers import SPIECE_UNDERLINE, PreTrainedTokenizer
6
+ from transformers.utils import cached_file
7
+
8
+ try:
9
+ from transformers.utils import is_offline_mode
10
+ except ImportError:
11
+ from transformers.utils.hub import is_offline_mode
12
+ from transformers.utils.import_utils import requires
13
+
14
+ CMD_ASR_BOS = "<|startoftranscript|>"
15
+ CMD_ASR_EOS = "<|endoftext|>"
16
+ CMD_ASR_PAD = "<pad>"
17
+ CMD_ASR_UNK = "<unk>"
18
+ VOCAB_FILES_NAMES = {"vocab_file": "tokenizer.model"}
19
+
20
+
21
+ @requires(backends=("sentencepiece",))
22
+ class CohereAsrTokenizer(PreTrainedTokenizer):
23
+ """
24
+ Cohere ASR tokenizer.
25
+ """
26
+
27
+ vocab_files_names = VOCAB_FILES_NAMES
28
+ model_input_names = ["input_ids"]
29
+
30
+ def __init__(
31
+ self,
32
+ spm_model_file: Optional[str] = None,
33
+ bos_token=CMD_ASR_BOS,
34
+ eos_token=CMD_ASR_EOS,
35
+ unk_token=CMD_ASR_UNK,
36
+ pad_token=CMD_ASR_PAD,
37
+ additional_special_tokens=None,
38
+ split_special_tokens=False,
39
+ add_prefix_space=False,
40
+ sp_model_kwargs=None,
41
+ **kwargs,
42
+ ):
43
+ self.spm_model_file = spm_model_file
44
+ self.sp_model_kwargs = sp_model_kwargs or {}
45
+ self.add_prefix_space = add_prefix_space
46
+ self.sp_model = self.get_spm_processor()
47
+
48
+ super().__init__(
49
+ unk_token=unk_token,
50
+ pad_token=pad_token,
51
+ bos_token=bos_token,
52
+ eos_token=eos_token,
53
+ additional_special_tokens=additional_special_tokens or [],
54
+ split_special_tokens=split_special_tokens,
55
+ add_prefix_space=add_prefix_space,
56
+ **kwargs,
57
+ )
58
+ self.init_kwargs["sp_model_kwargs"] = dict(self.sp_model_kwargs)
59
+
60
+ @classmethod
61
+ def from_pretrained(cls, pretrained_model_name_or_path, *init_inputs, **kwargs):
62
+ local_spm = os.path.join(pretrained_model_name_or_path, "tokenizer.model")
63
+ if os.path.exists(local_spm):
64
+ spm_path = local_spm
65
+ else:
66
+ try:
67
+ spm_path = cached_file(
68
+ pretrained_model_name_or_path,
69
+ "tokenizer.model",
70
+ _raise_exceptions_for_missing_entries=True,
71
+ )
72
+ except EnvironmentError as exc:
73
+ if is_offline_mode():
74
+ raise ValueError(
75
+ f"Offline mode: tokenizer.model not found for {pretrained_model_name_or_path}."
76
+ ) from exc
77
+ raise ValueError(
78
+ f"tokenizer.model not found in {pretrained_model_name_or_path} (local or remote)."
79
+ ) from exc
80
+
81
+ return super().from_pretrained(
82
+ pretrained_model_name_or_path,
83
+ spm_model_file=spm_path,
84
+ *init_inputs,
85
+ **kwargs,
86
+ )
87
+
88
+ @property
89
+ def vocab_size(self):
90
+ return self.sp_model.get_piece_size()
91
+
92
+ def get_vocab(self):
93
+ vocab = {self.sp_model.id_to_piece(i): i for i in range(self.vocab_size)}
94
+ for token_id, added_token in self.added_tokens_decoder.items():
95
+ if added_token.content not in vocab:
96
+ vocab[added_token.content] = token_id
97
+ return vocab
98
+
99
+ def _tokenize(self, text, **kwargs):
100
+ pieces = self.sp_model.encode(text, out_type=str)
101
+ if text and text[0] == " " and (not pieces or pieces[0] != SPIECE_UNDERLINE):
102
+ pieces = [SPIECE_UNDERLINE] + pieces
103
+ return pieces
104
+
105
+ def _convert_token_to_id(self, token):
106
+ return self.sp_model.piece_to_id(token)
107
+
108
+ def _convert_id_to_token(self, index):
109
+ return self.sp_model.id_to_piece(index)
110
+
111
+ def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
112
+ if token_ids_1 is None:
113
+ return [self.bos_token_id] + token_ids_0 + [self.eos_token_id]
114
+ return [self.bos_token_id] + token_ids_0 + [self.eos_token_id] + token_ids_1 + [self.eos_token_id]
115
+
116
+ def get_special_tokens_mask(self, token_ids_0, token_ids_1=None, already_has_special_tokens=False):
117
+ if already_has_special_tokens:
118
+ special_ids = {self.bos_token_id, self.eos_token_id, self.pad_token_id, self.unk_token_id}
119
+ for tok in self.additional_special_tokens or []:
120
+ special_ids.add(self.convert_tokens_to_ids(tok))
121
+ return [1 if tid in special_ids else 0 for tid in token_ids_0]
122
+ if token_ids_1 is None:
123
+ return [1] + [0] * len(token_ids_0) + [1]
124
+ return [1] + [0] * len(token_ids_0) + [1] + [0] * len(token_ids_1) + [1]
125
+
126
+ def num_special_tokens_to_add(self, pair=False):
127
+ if pair:
128
+ raise AssertionError(f"Pair sequences not supported for {self.__class__.__name__}.")
129
+ return 2
130
+
131
+ def convert_tokens_to_string(self, tokens):
132
+ if not tokens:
133
+ return ""
134
+ if self.add_prefix_space and tokens[0].startswith(SPIECE_UNDERLINE):
135
+ tokens = [tokens[0][1:]] + tokens[1:]
136
+ out = []
137
+ buf = []
138
+ prev_was_special = False
139
+
140
+ def flush():
141
+ nonlocal buf, prev_was_special
142
+ if not buf:
143
+ return
144
+ if prev_was_special and buf[0].startswith(SPIECE_UNDERLINE):
145
+ out.append(" ")
146
+ out.append(self.sp_model.decode(buf))
147
+ buf = []
148
+ prev_was_special = False
149
+
150
+ for tok in tokens:
151
+ if tok in self.all_special_tokens:
152
+ flush()
153
+ out.append(tok)
154
+ prev_was_special = True
155
+ else:
156
+ buf.append(tok)
157
+ flush()
158
+ return "".join(out)
159
+
160
+ def save_vocabulary(self, save_directory, filename_prefix=None):
161
+ os.makedirs(save_directory, exist_ok=True)
162
+ out_name = (filename_prefix + "-" if filename_prefix else "") + "tokenizer.model"
163
+ out_path = os.path.join(save_directory, out_name)
164
+ if not os.path.exists(out_path):
165
+ with open(out_path, "wb") as f:
166
+ f.write(self.sp_model.serialized_model_proto())
167
+ return (out_path,)
168
+
169
+ def get_spm_processor(self):
170
+ if not self.spm_model_file:
171
+ raise ValueError("CohereAsrTokenizer requires `spm_model_file` (tokenizer.model).")
172
+ tokenizer = spm.SentencePieceProcessor(**self.sp_model_kwargs)
173
+ tokenizer.Load(self.spm_model_file)
174
+ return tokenizer
175
+
176
+ def __getstate__(self):
177
+ state = self.__dict__.copy()
178
+ state["sp_model"] = None
179
+ return state
180
+
181
+ def __setstate__(self, state):
182
+ self.__dict__ = state
183
+ self.sp_model = self.get_spm_processor()
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d21e6a83b2d0d3e1241a7817e4bef8eb63bcb7cfe4a2675af9a35ff3bbf0e14
3
+ size 492827
tokenizer_config.json ADDED
@@ -0,0 +1,2314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "bos_token": "<|startoftranscript|>",
4
+ "eos_token": "<|endoftext|>",
5
+ "model_max_length": 2048,
6
+ "pad_token": "<pad>",
7
+ "split_special_tokens": true,
8
+ "tokenizer_class": "CohereAsrTokenizer",
9
+ "unk_token": "<unk>",
10
+ "add_prefix_space": false,
11
+ "added_tokens_decoder": {
12
+ "0": {
13
+ "content": "<unk>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "1": {
21
+ "content": "<|nospeech|>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "10": {
29
+ "content": "<|timestamp|>",
30
+ "lstrip": false,
31
+ "normalized": false,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "100": {
37
+ "content": "<|kn|>",
38
+ "lstrip": false,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ },
44
+ "101": {
45
+ "content": "<|kr|>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": true
51
+ },
52
+ "102": {
53
+ "content": "<|ks|>",
54
+ "lstrip": false,
55
+ "normalized": false,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": true
59
+ },
60
+ "103": {
61
+ "content": "<|kk|>",
62
+ "lstrip": false,
63
+ "normalized": false,
64
+ "rstrip": false,
65
+ "single_word": false,
66
+ "special": true
67
+ },
68
+ "104": {
69
+ "content": "<|km|>",
70
+ "lstrip": false,
71
+ "normalized": false,
72
+ "rstrip": false,
73
+ "single_word": false,
74
+ "special": true
75
+ },
76
+ "105": {
77
+ "content": "<|ki|>",
78
+ "lstrip": false,
79
+ "normalized": false,
80
+ "rstrip": false,
81
+ "single_word": false,
82
+ "special": true
83
+ },
84
+ "106": {
85
+ "content": "<|rw|>",
86
+ "lstrip": false,
87
+ "normalized": false,
88
+ "rstrip": false,
89
+ "single_word": false,
90
+ "special": true
91
+ },
92
+ "107": {
93
+ "content": "<|ky|>",
94
+ "lstrip": false,
95
+ "normalized": false,
96
+ "rstrip": false,
97
+ "single_word": false,
98
+ "special": true
99
+ },
100
+ "108": {
101
+ "content": "<|kv|>",
102
+ "lstrip": false,
103
+ "normalized": false,
104
+ "rstrip": false,
105
+ "single_word": false,
106
+ "special": true
107
+ },
108
+ "109": {
109
+ "content": "<|kg|>",
110
+ "lstrip": false,
111
+ "normalized": false,
112
+ "rstrip": false,
113
+ "single_word": false,
114
+ "special": true
115
+ },
116
+ "11": {
117
+ "content": "<|notimestamp|>",
118
+ "lstrip": false,
119
+ "normalized": false,
120
+ "rstrip": false,
121
+ "single_word": false,
122
+ "special": true
123
+ },
124
+ "110": {
125
+ "content": "<|ko|>",
126
+ "lstrip": false,
127
+ "normalized": false,
128
+ "rstrip": false,
129
+ "single_word": false,
130
+ "special": true
131
+ },
132
+ "111": {
133
+ "content": "<|kj|>",
134
+ "lstrip": false,
135
+ "normalized": false,
136
+ "rstrip": false,
137
+ "single_word": false,
138
+ "special": true
139
+ },
140
+ "112": {
141
+ "content": "<|ku|>",
142
+ "lstrip": false,
143
+ "normalized": false,
144
+ "rstrip": false,
145
+ "single_word": false,
146
+ "special": true
147
+ },
148
+ "113": {
149
+ "content": "<|lo|>",
150
+ "lstrip": false,
151
+ "normalized": false,
152
+ "rstrip": false,
153
+ "single_word": false,
154
+ "special": true
155
+ },
156
+ "114": {
157
+ "content": "<|la|>",
158
+ "lstrip": false,
159
+ "normalized": false,
160
+ "rstrip": false,
161
+ "single_word": false,
162
+ "special": true
163
+ },
164
+ "115": {
165
+ "content": "<|lv|>",
166
+ "lstrip": false,
167
+ "normalized": false,
168
+ "rstrip": false,
169
+ "single_word": false,
170
+ "special": true
171
+ },
172
+ "116": {
173
+ "content": "<|li|>",
174
+ "lstrip": false,
175
+ "normalized": false,
176
+ "rstrip": false,
177
+ "single_word": false,
178
+ "special": true
179
+ },
180
+ "117": {
181
+ "content": "<|ln|>",
182
+ "lstrip": false,
183
+ "normalized": false,
184
+ "rstrip": false,
185
+ "single_word": false,
186
+ "special": true
187
+ },
188
+ "118": {
189
+ "content": "<|lt|>",
190
+ "lstrip": false,
191
+ "normalized": false,
192
+ "rstrip": false,
193
+ "single_word": false,
194
+ "special": true
195
+ },
196
+ "119": {
197
+ "content": "<|lu|>",
198
+ "lstrip": false,
199
+ "normalized": false,
200
+ "rstrip": false,
201
+ "single_word": false,
202
+ "special": true
203
+ },
204
+ "12": {
205
+ "content": "<|diarize|>",
206
+ "lstrip": false,
207
+ "normalized": false,
208
+ "rstrip": false,
209
+ "single_word": false,
210
+ "special": true
211
+ },
212
+ "120": {
213
+ "content": "<|lb|>",
214
+ "lstrip": false,
215
+ "normalized": false,
216
+ "rstrip": false,
217
+ "single_word": false,
218
+ "special": true
219
+ },
220
+ "121": {
221
+ "content": "<|mk|>",
222
+ "lstrip": false,
223
+ "normalized": false,
224
+ "rstrip": false,
225
+ "single_word": false,
226
+ "special": true
227
+ },
228
+ "122": {
229
+ "content": "<|mg|>",
230
+ "lstrip": false,
231
+ "normalized": false,
232
+ "rstrip": false,
233
+ "single_word": false,
234
+ "special": true
235
+ },
236
+ "123": {
237
+ "content": "<|ms|>",
238
+ "lstrip": false,
239
+ "normalized": false,
240
+ "rstrip": false,
241
+ "single_word": false,
242
+ "special": true
243
+ },
244
+ "124": {
245
+ "content": "<|ml|>",
246
+ "lstrip": false,
247
+ "normalized": false,
248
+ "rstrip": false,
249
+ "single_word": false,
250
+ "special": true
251
+ },
252
+ "125": {
253
+ "content": "<|mt|>",
254
+ "lstrip": false,
255
+ "normalized": false,
256
+ "rstrip": false,
257
+ "single_word": false,
258
+ "special": true
259
+ },
260
+ "126": {
261
+ "content": "<|gv|>",
262
+ "lstrip": false,
263
+ "normalized": false,
264
+ "rstrip": false,
265
+ "single_word": false,
266
+ "special": true
267
+ },
268
+ "127": {
269
+ "content": "<|mi|>",
270
+ "lstrip": false,
271
+ "normalized": false,
272
+ "rstrip": false,
273
+ "single_word": false,
274
+ "special": true
275
+ },
276
+ "128": {
277
+ "content": "<|mr|>",
278
+ "lstrip": false,
279
+ "normalized": false,
280
+ "rstrip": false,
281
+ "single_word": false,
282
+ "special": true
283
+ },
284
+ "129": {
285
+ "content": "<|mh|>",
286
+ "lstrip": false,
287
+ "normalized": false,
288
+ "rstrip": false,
289
+ "single_word": false,
290
+ "special": true
291
+ },
292
+ "13": {
293
+ "content": "<|nodiarize|>",
294
+ "lstrip": false,
295
+ "normalized": false,
296
+ "rstrip": false,
297
+ "single_word": false,
298
+ "special": true
299
+ },
300
+ "130": {
301
+ "content": "<|mn|>",
302
+ "lstrip": false,
303
+ "normalized": false,
304
+ "rstrip": false,
305
+ "single_word": false,
306
+ "special": true
307
+ },
308
+ "131": {
309
+ "content": "<|na|>",
310
+ "lstrip": false,
311
+ "normalized": false,
312
+ "rstrip": false,
313
+ "single_word": false,
314
+ "special": true
315
+ },
316
+ "132": {
317
+ "content": "<|nv|>",
318
+ "lstrip": false,
319
+ "normalized": false,
320
+ "rstrip": false,
321
+ "single_word": false,
322
+ "special": true
323
+ },
324
+ "133": {
325
+ "content": "<|nd|>",
326
+ "lstrip": false,
327
+ "normalized": false,
328
+ "rstrip": false,
329
+ "single_word": false,
330
+ "special": true
331
+ },
332
+ "134": {
333
+ "content": "<|nr|>",
334
+ "lstrip": false,
335
+ "normalized": false,
336
+ "rstrip": false,
337
+ "single_word": false,
338
+ "special": true
339
+ },
340
+ "135": {
341
+ "content": "<|ng|>",
342
+ "lstrip": false,
343
+ "normalized": false,
344
+ "rstrip": false,
345
+ "single_word": false,
346
+ "special": true
347
+ },
348
+ "136": {
349
+ "content": "<|ne|>",
350
+ "lstrip": false,
351
+ "normalized": false,
352
+ "rstrip": false,
353
+ "single_word": false,
354
+ "special": true
355
+ },
356
+ "137": {
357
+ "content": "<|no|>",
358
+ "lstrip": false,
359
+ "normalized": false,
360
+ "rstrip": false,
361
+ "single_word": false,
362
+ "special": true
363
+ },
364
+ "138": {
365
+ "content": "<|nb|>",
366
+ "lstrip": false,
367
+ "normalized": false,
368
+ "rstrip": false,
369
+ "single_word": false,
370
+ "special": true
371
+ },
372
+ "139": {
373
+ "content": "<|nn|>",
374
+ "lstrip": false,
375
+ "normalized": false,
376
+ "rstrip": false,
377
+ "single_word": false,
378
+ "special": true
379
+ },
380
+ "14": {
381
+ "content": "<|spkchange|>",
382
+ "lstrip": false,
383
+ "normalized": false,
384
+ "rstrip": false,
385
+ "single_word": false,
386
+ "special": true
387
+ },
388
+ "140": {
389
+ "content": "<|oc|>",
390
+ "lstrip": false,
391
+ "normalized": false,
392
+ "rstrip": false,
393
+ "single_word": false,
394
+ "special": true
395
+ },
396
+ "141": {
397
+ "content": "<|oj|>",
398
+ "lstrip": false,
399
+ "normalized": false,
400
+ "rstrip": false,
401
+ "single_word": false,
402
+ "special": true
403
+ },
404
+ "142": {
405
+ "content": "<|or|>",
406
+ "lstrip": false,
407
+ "normalized": false,
408
+ "rstrip": false,
409
+ "single_word": false,
410
+ "special": true
411
+ },
412
+ "143": {
413
+ "content": "<|om|>",
414
+ "lstrip": false,
415
+ "normalized": false,
416
+ "rstrip": false,
417
+ "single_word": false,
418
+ "special": true
419
+ },
420
+ "144": {
421
+ "content": "<|os|>",
422
+ "lstrip": false,
423
+ "normalized": false,
424
+ "rstrip": false,
425
+ "single_word": false,
426
+ "special": true
427
+ },
428
+ "145": {
429
+ "content": "<|pi|>",
430
+ "lstrip": false,
431
+ "normalized": false,
432
+ "rstrip": false,
433
+ "single_word": false,
434
+ "special": true
435
+ },
436
+ "146": {
437
+ "content": "<|ps|>",
438
+ "lstrip": false,
439
+ "normalized": false,
440
+ "rstrip": false,
441
+ "single_word": false,
442
+ "special": true
443
+ },
444
+ "147": {
445
+ "content": "<|fa|>",
446
+ "lstrip": false,
447
+ "normalized": false,
448
+ "rstrip": false,
449
+ "single_word": false,
450
+ "special": true
451
+ },
452
+ "148": {
453
+ "content": "<|pl|>",
454
+ "lstrip": false,
455
+ "normalized": false,
456
+ "rstrip": false,
457
+ "single_word": false,
458
+ "special": true
459
+ },
460
+ "149": {
461
+ "content": "<|pt|>",
462
+ "lstrip": false,
463
+ "normalized": false,
464
+ "rstrip": false,
465
+ "single_word": false,
466
+ "special": true
467
+ },
468
+ "15": {
469
+ "content": "<|audioseparator|>",
470
+ "lstrip": false,
471
+ "normalized": false,
472
+ "rstrip": false,
473
+ "single_word": false,
474
+ "special": true
475
+ },
476
+ "150": {
477
+ "content": "<|pa|>",
478
+ "lstrip": false,
479
+ "normalized": false,
480
+ "rstrip": false,
481
+ "single_word": false,
482
+ "special": true
483
+ },
484
+ "151": {
485
+ "content": "<|qu|>",
486
+ "lstrip": false,
487
+ "normalized": false,
488
+ "rstrip": false,
489
+ "single_word": false,
490
+ "special": true
491
+ },
492
+ "152": {
493
+ "content": "<|ro|>",
494
+ "lstrip": false,
495
+ "normalized": false,
496
+ "rstrip": false,
497
+ "single_word": false,
498
+ "special": true
499
+ },
500
+ "153": {
501
+ "content": "<|rm|>",
502
+ "lstrip": false,
503
+ "normalized": false,
504
+ "rstrip": false,
505
+ "single_word": false,
506
+ "special": true
507
+ },
508
+ "154": {
509
+ "content": "<|rn|>",
510
+ "lstrip": false,
511
+ "normalized": false,
512
+ "rstrip": false,
513
+ "single_word": false,
514
+ "special": true
515
+ },
516
+ "155": {
517
+ "content": "<|ru|>",
518
+ "lstrip": false,
519
+ "normalized": false,
520
+ "rstrip": false,
521
+ "single_word": false,
522
+ "special": true
523
+ },
524
+ "156": {
525
+ "content": "<|se|>",
526
+ "lstrip": false,
527
+ "normalized": false,
528
+ "rstrip": false,
529
+ "single_word": false,
530
+ "special": true
531
+ },
532
+ "157": {
533
+ "content": "<|sm|>",
534
+ "lstrip": false,
535
+ "normalized": false,
536
+ "rstrip": false,
537
+ "single_word": false,
538
+ "special": true
539
+ },
540
+ "158": {
541
+ "content": "<|sg|>",
542
+ "lstrip": false,
543
+ "normalized": false,
544
+ "rstrip": false,
545
+ "single_word": false,
546
+ "special": true
547
+ },
548
+ "159": {
549
+ "content": "<|sa|>",
550
+ "lstrip": false,
551
+ "normalized": false,
552
+ "rstrip": false,
553
+ "single_word": false,
554
+ "special": true
555
+ },
556
+ "16": {
557
+ "content": "<|emo:undefined|>",
558
+ "lstrip": false,
559
+ "normalized": false,
560
+ "rstrip": false,
561
+ "single_word": false,
562
+ "special": true
563
+ },
564
+ "160": {
565
+ "content": "<|sc|>",
566
+ "lstrip": false,
567
+ "normalized": false,
568
+ "rstrip": false,
569
+ "single_word": false,
570
+ "special": true
571
+ },
572
+ "161": {
573
+ "content": "<|sr|>",
574
+ "lstrip": false,
575
+ "normalized": false,
576
+ "rstrip": false,
577
+ "single_word": false,
578
+ "special": true
579
+ },
580
+ "162": {
581
+ "content": "<|sn|>",
582
+ "lstrip": false,
583
+ "normalized": false,
584
+ "rstrip": false,
585
+ "single_word": false,
586
+ "special": true
587
+ },
588
+ "163": {
589
+ "content": "<|sd|>",
590
+ "lstrip": false,
591
+ "normalized": false,
592
+ "rstrip": false,
593
+ "single_word": false,
594
+ "special": true
595
+ },
596
+ "164": {
597
+ "content": "<|si|>",
598
+ "lstrip": false,
599
+ "normalized": false,
600
+ "rstrip": false,
601
+ "single_word": false,
602
+ "special": true
603
+ },
604
+ "165": {
605
+ "content": "<|sk|>",
606
+ "lstrip": false,
607
+ "normalized": false,
608
+ "rstrip": false,
609
+ "single_word": false,
610
+ "special": true
611
+ },
612
+ "166": {
613
+ "content": "<|sl|>",
614
+ "lstrip": false,
615
+ "normalized": false,
616
+ "rstrip": false,
617
+ "single_word": false,
618
+ "special": true
619
+ },
620
+ "167": {
621
+ "content": "<|so|>",
622
+ "lstrip": false,
623
+ "normalized": false,
624
+ "rstrip": false,
625
+ "single_word": false,
626
+ "special": true
627
+ },
628
+ "168": {
629
+ "content": "<|st|>",
630
+ "lstrip": false,
631
+ "normalized": false,
632
+ "rstrip": false,
633
+ "single_word": false,
634
+ "special": true
635
+ },
636
+ "169": {
637
+ "content": "<|es|>",
638
+ "lstrip": false,
639
+ "normalized": false,
640
+ "rstrip": false,
641
+ "single_word": false,
642
+ "special": true
643
+ },
644
+ "17": {
645
+ "content": "<|emo:neutral|>",
646
+ "lstrip": false,
647
+ "normalized": false,
648
+ "rstrip": false,
649
+ "single_word": false,
650
+ "special": true
651
+ },
652
+ "170": {
653
+ "content": "<|su|>",
654
+ "lstrip": false,
655
+ "normalized": false,
656
+ "rstrip": false,
657
+ "single_word": false,
658
+ "special": true
659
+ },
660
+ "171": {
661
+ "content": "<|sw|>",
662
+ "lstrip": false,
663
+ "normalized": false,
664
+ "rstrip": false,
665
+ "single_word": false,
666
+ "special": true
667
+ },
668
+ "172": {
669
+ "content": "<|ss|>",
670
+ "lstrip": false,
671
+ "normalized": false,
672
+ "rstrip": false,
673
+ "single_word": false,
674
+ "special": true
675
+ },
676
+ "173": {
677
+ "content": "<|sv|>",
678
+ "lstrip": false,
679
+ "normalized": false,
680
+ "rstrip": false,
681
+ "single_word": false,
682
+ "special": true
683
+ },
684
+ "174": {
685
+ "content": "<|tl|>",
686
+ "lstrip": false,
687
+ "normalized": false,
688
+ "rstrip": false,
689
+ "single_word": false,
690
+ "special": true
691
+ },
692
+ "175": {
693
+ "content": "<|ty|>",
694
+ "lstrip": false,
695
+ "normalized": false,
696
+ "rstrip": false,
697
+ "single_word": false,
698
+ "special": true
699
+ },
700
+ "176": {
701
+ "content": "<|tg|>",
702
+ "lstrip": false,
703
+ "normalized": false,
704
+ "rstrip": false,
705
+ "single_word": false,
706
+ "special": true
707
+ },
708
+ "177": {
709
+ "content": "<|ta|>",
710
+ "lstrip": false,
711
+ "normalized": false,
712
+ "rstrip": false,
713
+ "single_word": false,
714
+ "special": true
715
+ },
716
+ "178": {
717
+ "content": "<|tt|>",
718
+ "lstrip": false,
719
+ "normalized": false,
720
+ "rstrip": false,
721
+ "single_word": false,
722
+ "special": true
723
+ },
724
+ "179": {
725
+ "content": "<|te|>",
726
+ "lstrip": false,
727
+ "normalized": false,
728
+ "rstrip": false,
729
+ "single_word": false,
730
+ "special": true
731
+ },
732
+ "18": {
733
+ "content": "<|emo:happy|>",
734
+ "lstrip": false,
735
+ "normalized": false,
736
+ "rstrip": false,
737
+ "single_word": false,
738
+ "special": true
739
+ },
740
+ "180": {
741
+ "content": "<|th|>",
742
+ "lstrip": false,
743
+ "normalized": false,
744
+ "rstrip": false,
745
+ "single_word": false,
746
+ "special": true
747
+ },
748
+ "181": {
749
+ "content": "<|bo|>",
750
+ "lstrip": false,
751
+ "normalized": false,
752
+ "rstrip": false,
753
+ "single_word": false,
754
+ "special": true
755
+ },
756
+ "182": {
757
+ "content": "<|ti|>",
758
+ "lstrip": false,
759
+ "normalized": false,
760
+ "rstrip": false,
761
+ "single_word": false,
762
+ "special": true
763
+ },
764
+ "183": {
765
+ "content": "<|to|>",
766
+ "lstrip": false,
767
+ "normalized": false,
768
+ "rstrip": false,
769
+ "single_word": false,
770
+ "special": true
771
+ },
772
+ "184": {
773
+ "content": "<|ts|>",
774
+ "lstrip": false,
775
+ "normalized": false,
776
+ "rstrip": false,
777
+ "single_word": false,
778
+ "special": true
779
+ },
780
+ "185": {
781
+ "content": "<|tn|>",
782
+ "lstrip": false,
783
+ "normalized": false,
784
+ "rstrip": false,
785
+ "single_word": false,
786
+ "special": true
787
+ },
788
+ "186": {
789
+ "content": "<|tr|>",
790
+ "lstrip": false,
791
+ "normalized": false,
792
+ "rstrip": false,
793
+ "single_word": false,
794
+ "special": true
795
+ },
796
+ "187": {
797
+ "content": "<|tk|>",
798
+ "lstrip": false,
799
+ "normalized": false,
800
+ "rstrip": false,
801
+ "single_word": false,
802
+ "special": true
803
+ },
804
+ "188": {
805
+ "content": "<|tw|>",
806
+ "lstrip": false,
807
+ "normalized": false,
808
+ "rstrip": false,
809
+ "single_word": false,
810
+ "special": true
811
+ },
812
+ "189": {
813
+ "content": "<|ug|>",
814
+ "lstrip": false,
815
+ "normalized": false,
816
+ "rstrip": false,
817
+ "single_word": false,
818
+ "special": true
819
+ },
820
+ "19": {
821
+ "content": "<|emo:sad|>",
822
+ "lstrip": false,
823
+ "normalized": false,
824
+ "rstrip": false,
825
+ "single_word": false,
826
+ "special": true
827
+ },
828
+ "190": {
829
+ "content": "<|uk|>",
830
+ "lstrip": false,
831
+ "normalized": false,
832
+ "rstrip": false,
833
+ "single_word": false,
834
+ "special": true
835
+ },
836
+ "191": {
837
+ "content": "<|ur|>",
838
+ "lstrip": false,
839
+ "normalized": false,
840
+ "rstrip": false,
841
+ "single_word": false,
842
+ "special": true
843
+ },
844
+ "192": {
845
+ "content": "<|uz|>",
846
+ "lstrip": false,
847
+ "normalized": false,
848
+ "rstrip": false,
849
+ "single_word": false,
850
+ "special": true
851
+ },
852
+ "193": {
853
+ "content": "<|ve|>",
854
+ "lstrip": false,
855
+ "normalized": false,
856
+ "rstrip": false,
857
+ "single_word": false,
858
+ "special": true
859
+ },
860
+ "194": {
861
+ "content": "<|vi|>",
862
+ "lstrip": false,
863
+ "normalized": false,
864
+ "rstrip": false,
865
+ "single_word": false,
866
+ "special": true
867
+ },
868
+ "195": {
869
+ "content": "<|vo|>",
870
+ "lstrip": false,
871
+ "normalized": false,
872
+ "rstrip": false,
873
+ "single_word": false,
874
+ "special": true
875
+ },
876
+ "196": {
877
+ "content": "<|wa|>",
878
+ "lstrip": false,
879
+ "normalized": false,
880
+ "rstrip": false,
881
+ "single_word": false,
882
+ "special": true
883
+ },
884
+ "197": {
885
+ "content": "<|cy|>",
886
+ "lstrip": false,
887
+ "normalized": false,
888
+ "rstrip": false,
889
+ "single_word": false,
890
+ "special": true
891
+ },
892
+ "198": {
893
+ "content": "<|wo|>",
894
+ "lstrip": false,
895
+ "normalized": false,
896
+ "rstrip": false,
897
+ "single_word": false,
898
+ "special": true
899
+ },
900
+ "199": {
901
+ "content": "<|xh|>",
902
+ "lstrip": false,
903
+ "normalized": false,
904
+ "rstrip": false,
905
+ "single_word": false,
906
+ "special": true
907
+ },
908
+ "2": {
909
+ "content": "<pad>",
910
+ "lstrip": false,
911
+ "normalized": false,
912
+ "rstrip": false,
913
+ "single_word": false,
914
+ "special": true
915
+ },
916
+ "20": {
917
+ "content": "<|emo:angry|>",
918
+ "lstrip": false,
919
+ "normalized": false,
920
+ "rstrip": false,
921
+ "single_word": false,
922
+ "special": true
923
+ },
924
+ "200": {
925
+ "content": "<|ii|>",
926
+ "lstrip": false,
927
+ "normalized": false,
928
+ "rstrip": false,
929
+ "single_word": false,
930
+ "special": true
931
+ },
932
+ "201": {
933
+ "content": "<|yi|>",
934
+ "lstrip": false,
935
+ "normalized": false,
936
+ "rstrip": false,
937
+ "single_word": false,
938
+ "special": true
939
+ },
940
+ "202": {
941
+ "content": "<|yo|>",
942
+ "lstrip": false,
943
+ "normalized": false,
944
+ "rstrip": false,
945
+ "single_word": false,
946
+ "special": true
947
+ },
948
+ "203": {
949
+ "content": "<|za|>",
950
+ "lstrip": false,
951
+ "normalized": false,
952
+ "rstrip": false,
953
+ "single_word": false,
954
+ "special": true
955
+ },
956
+ "204": {
957
+ "content": "<|zu|>",
958
+ "lstrip": false,
959
+ "normalized": false,
960
+ "rstrip": false,
961
+ "single_word": false,
962
+ "special": true
963
+ },
964
+ "205": {
965
+ "content": "<|spk0|>",
966
+ "lstrip": false,
967
+ "normalized": false,
968
+ "rstrip": false,
969
+ "single_word": false,
970
+ "special": true
971
+ },
972
+ "206": {
973
+ "content": "<|spk1|>",
974
+ "lstrip": false,
975
+ "normalized": false,
976
+ "rstrip": false,
977
+ "single_word": false,
978
+ "special": true
979
+ },
980
+ "207": {
981
+ "content": "<|spk2|>",
982
+ "lstrip": false,
983
+ "normalized": false,
984
+ "rstrip": false,
985
+ "single_word": false,
986
+ "special": true
987
+ },
988
+ "208": {
989
+ "content": "<|spk3|>",
990
+ "lstrip": false,
991
+ "normalized": false,
992
+ "rstrip": false,
993
+ "single_word": false,
994
+ "special": true
995
+ },
996
+ "209": {
997
+ "content": "<|spk4|>",
998
+ "lstrip": false,
999
+ "normalized": false,
1000
+ "rstrip": false,
1001
+ "single_word": false,
1002
+ "special": true
1003
+ },
1004
+ "21": {
1005
+ "content": "<|unklang|>",
1006
+ "lstrip": false,
1007
+ "normalized": false,
1008
+ "rstrip": false,
1009
+ "single_word": false,
1010
+ "special": true
1011
+ },
1012
+ "210": {
1013
+ "content": "<|spk5|>",
1014
+ "lstrip": false,
1015
+ "normalized": false,
1016
+ "rstrip": false,
1017
+ "single_word": false,
1018
+ "special": true
1019
+ },
1020
+ "211": {
1021
+ "content": "<|spk6|>",
1022
+ "lstrip": false,
1023
+ "normalized": false,
1024
+ "rstrip": false,
1025
+ "single_word": false,
1026
+ "special": true
1027
+ },
1028
+ "212": {
1029
+ "content": "<|spk7|>",
1030
+ "lstrip": false,
1031
+ "normalized": false,
1032
+ "rstrip": false,
1033
+ "single_word": false,
1034
+ "special": true
1035
+ },
1036
+ "213": {
1037
+ "content": "<|spk8|>",
1038
+ "lstrip": false,
1039
+ "normalized": false,
1040
+ "rstrip": false,
1041
+ "single_word": false,
1042
+ "special": true
1043
+ },
1044
+ "214": {
1045
+ "content": "<|spk9|>",
1046
+ "lstrip": false,
1047
+ "normalized": false,
1048
+ "rstrip": false,
1049
+ "single_word": false,
1050
+ "special": true
1051
+ },
1052
+ "215": {
1053
+ "content": "<|spk10|>",
1054
+ "lstrip": false,
1055
+ "normalized": false,
1056
+ "rstrip": false,
1057
+ "single_word": false,
1058
+ "special": true
1059
+ },
1060
+ "216": {
1061
+ "content": "<|spk11|>",
1062
+ "lstrip": false,
1063
+ "normalized": false,
1064
+ "rstrip": false,
1065
+ "single_word": false,
1066
+ "special": true
1067
+ },
1068
+ "217": {
1069
+ "content": "<|spk12|>",
1070
+ "lstrip": false,
1071
+ "normalized": false,
1072
+ "rstrip": false,
1073
+ "single_word": false,
1074
+ "special": true
1075
+ },
1076
+ "218": {
1077
+ "content": "<|spk13|>",
1078
+ "lstrip": false,
1079
+ "normalized": false,
1080
+ "rstrip": false,
1081
+ "single_word": false,
1082
+ "special": true
1083
+ },
1084
+ "219": {
1085
+ "content": "<|spk14|>",
1086
+ "lstrip": false,
1087
+ "normalized": false,
1088
+ "rstrip": false,
1089
+ "single_word": false,
1090
+ "special": true
1091
+ },
1092
+ "22": {
1093
+ "content": "<|aa|>",
1094
+ "lstrip": false,
1095
+ "normalized": false,
1096
+ "rstrip": false,
1097
+ "single_word": false,
1098
+ "special": true
1099
+ },
1100
+ "220": {
1101
+ "content": "<|spk15|>",
1102
+ "lstrip": false,
1103
+ "normalized": false,
1104
+ "rstrip": false,
1105
+ "single_word": false,
1106
+ "special": true
1107
+ },
1108
+ "221": {
1109
+ "content": "<|spltoken0|>",
1110
+ "lstrip": false,
1111
+ "normalized": false,
1112
+ "rstrip": false,
1113
+ "single_word": false,
1114
+ "special": true
1115
+ },
1116
+ "222": {
1117
+ "content": "<|spltoken1|>",
1118
+ "lstrip": false,
1119
+ "normalized": false,
1120
+ "rstrip": false,
1121
+ "single_word": false,
1122
+ "special": true
1123
+ },
1124
+ "223": {
1125
+ "content": "<|spltoken2|>",
1126
+ "lstrip": false,
1127
+ "normalized": false,
1128
+ "rstrip": false,
1129
+ "single_word": false,
1130
+ "special": true
1131
+ },
1132
+ "224": {
1133
+ "content": "<|spltoken3|>",
1134
+ "lstrip": false,
1135
+ "normalized": false,
1136
+ "rstrip": false,
1137
+ "single_word": false,
1138
+ "special": true
1139
+ },
1140
+ "225": {
1141
+ "content": "<|spltoken4|>",
1142
+ "lstrip": false,
1143
+ "normalized": false,
1144
+ "rstrip": false,
1145
+ "single_word": false,
1146
+ "special": true
1147
+ },
1148
+ "226": {
1149
+ "content": "<|spltoken5|>",
1150
+ "lstrip": false,
1151
+ "normalized": false,
1152
+ "rstrip": false,
1153
+ "single_word": false,
1154
+ "special": true
1155
+ },
1156
+ "227": {
1157
+ "content": "<|spltoken6|>",
1158
+ "lstrip": false,
1159
+ "normalized": false,
1160
+ "rstrip": false,
1161
+ "single_word": false,
1162
+ "special": true
1163
+ },
1164
+ "228": {
1165
+ "content": "<|spltoken7|>",
1166
+ "lstrip": false,
1167
+ "normalized": false,
1168
+ "rstrip": false,
1169
+ "single_word": false,
1170
+ "special": true
1171
+ },
1172
+ "229": {
1173
+ "content": "<|spltoken8|>",
1174
+ "lstrip": false,
1175
+ "normalized": false,
1176
+ "rstrip": false,
1177
+ "single_word": false,
1178
+ "special": true
1179
+ },
1180
+ "23": {
1181
+ "content": "<|ab|>",
1182
+ "lstrip": false,
1183
+ "normalized": false,
1184
+ "rstrip": false,
1185
+ "single_word": false,
1186
+ "special": true
1187
+ },
1188
+ "230": {
1189
+ "content": "<|spltoken9|>",
1190
+ "lstrip": false,
1191
+ "normalized": false,
1192
+ "rstrip": false,
1193
+ "single_word": false,
1194
+ "special": true
1195
+ },
1196
+ "231": {
1197
+ "content": "<|spltoken10|>",
1198
+ "lstrip": false,
1199
+ "normalized": false,
1200
+ "rstrip": false,
1201
+ "single_word": false,
1202
+ "special": true
1203
+ },
1204
+ "232": {
1205
+ "content": "<|spltoken11|>",
1206
+ "lstrip": false,
1207
+ "normalized": false,
1208
+ "rstrip": false,
1209
+ "single_word": false,
1210
+ "special": true
1211
+ },
1212
+ "233": {
1213
+ "content": "<|spltoken12|>",
1214
+ "lstrip": false,
1215
+ "normalized": false,
1216
+ "rstrip": false,
1217
+ "single_word": false,
1218
+ "special": true
1219
+ },
1220
+ "234": {
1221
+ "content": "<|spltoken13|>",
1222
+ "lstrip": false,
1223
+ "normalized": false,
1224
+ "rstrip": false,
1225
+ "single_word": false,
1226
+ "special": true
1227
+ },
1228
+ "235": {
1229
+ "content": "<|spltoken14|>",
1230
+ "lstrip": false,
1231
+ "normalized": false,
1232
+ "rstrip": false,
1233
+ "single_word": false,
1234
+ "special": true
1235
+ },
1236
+ "236": {
1237
+ "content": "<|spltoken15|>",
1238
+ "lstrip": false,
1239
+ "normalized": false,
1240
+ "rstrip": false,
1241
+ "single_word": false,
1242
+ "special": true
1243
+ },
1244
+ "237": {
1245
+ "content": "<|spltoken16|>",
1246
+ "lstrip": false,
1247
+ "normalized": false,
1248
+ "rstrip": false,
1249
+ "single_word": false,
1250
+ "special": true
1251
+ },
1252
+ "238": {
1253
+ "content": "<|spltoken17|>",
1254
+ "lstrip": false,
1255
+ "normalized": false,
1256
+ "rstrip": false,
1257
+ "single_word": false,
1258
+ "special": true
1259
+ },
1260
+ "239": {
1261
+ "content": "<|spltoken18|>",
1262
+ "lstrip": false,
1263
+ "normalized": false,
1264
+ "rstrip": false,
1265
+ "single_word": false,
1266
+ "special": true
1267
+ },
1268
+ "24": {
1269
+ "content": "<|af|>",
1270
+ "lstrip": false,
1271
+ "normalized": false,
1272
+ "rstrip": false,
1273
+ "single_word": false,
1274
+ "special": true
1275
+ },
1276
+ "240": {
1277
+ "content": "<|spltoken19|>",
1278
+ "lstrip": false,
1279
+ "normalized": false,
1280
+ "rstrip": false,
1281
+ "single_word": false,
1282
+ "special": true
1283
+ },
1284
+ "241": {
1285
+ "content": "<|spltoken20|>",
1286
+ "lstrip": false,
1287
+ "normalized": false,
1288
+ "rstrip": false,
1289
+ "single_word": false,
1290
+ "special": true
1291
+ },
1292
+ "242": {
1293
+ "content": "<|spltoken21|>",
1294
+ "lstrip": false,
1295
+ "normalized": false,
1296
+ "rstrip": false,
1297
+ "single_word": false,
1298
+ "special": true
1299
+ },
1300
+ "243": {
1301
+ "content": "<|spltoken22|>",
1302
+ "lstrip": false,
1303
+ "normalized": false,
1304
+ "rstrip": false,
1305
+ "single_word": false,
1306
+ "special": true
1307
+ },
1308
+ "244": {
1309
+ "content": "<|spltoken23|>",
1310
+ "lstrip": false,
1311
+ "normalized": false,
1312
+ "rstrip": false,
1313
+ "single_word": false,
1314
+ "special": true
1315
+ },
1316
+ "245": {
1317
+ "content": "<|spltoken24|>",
1318
+ "lstrip": false,
1319
+ "normalized": false,
1320
+ "rstrip": false,
1321
+ "single_word": false,
1322
+ "special": true
1323
+ },
1324
+ "246": {
1325
+ "content": "<|spltoken25|>",
1326
+ "lstrip": false,
1327
+ "normalized": false,
1328
+ "rstrip": false,
1329
+ "single_word": false,
1330
+ "special": true
1331
+ },
1332
+ "247": {
1333
+ "content": "<|spltoken26|>",
1334
+ "lstrip": false,
1335
+ "normalized": false,
1336
+ "rstrip": false,
1337
+ "single_word": false,
1338
+ "special": true
1339
+ },
1340
+ "248": {
1341
+ "content": "<|spltoken27|>",
1342
+ "lstrip": false,
1343
+ "normalized": false,
1344
+ "rstrip": false,
1345
+ "single_word": false,
1346
+ "special": true
1347
+ },
1348
+ "249": {
1349
+ "content": "<|spltoken28|>",
1350
+ "lstrip": false,
1351
+ "normalized": false,
1352
+ "rstrip": false,
1353
+ "single_word": false,
1354
+ "special": true
1355
+ },
1356
+ "25": {
1357
+ "content": "<|ak|>",
1358
+ "lstrip": false,
1359
+ "normalized": false,
1360
+ "rstrip": false,
1361
+ "single_word": false,
1362
+ "special": true
1363
+ },
1364
+ "250": {
1365
+ "content": "<|spltoken29|>",
1366
+ "lstrip": false,
1367
+ "normalized": false,
1368
+ "rstrip": false,
1369
+ "single_word": false,
1370
+ "special": true
1371
+ },
1372
+ "251": {
1373
+ "content": "<|spltoken30|>",
1374
+ "lstrip": false,
1375
+ "normalized": false,
1376
+ "rstrip": false,
1377
+ "single_word": false,
1378
+ "special": true
1379
+ },
1380
+ "252": {
1381
+ "content": "<|spltoken31|>",
1382
+ "lstrip": false,
1383
+ "normalized": false,
1384
+ "rstrip": false,
1385
+ "single_word": false,
1386
+ "special": true
1387
+ },
1388
+ "253": {
1389
+ "content": "<|spltoken32|>",
1390
+ "lstrip": false,
1391
+ "normalized": false,
1392
+ "rstrip": false,
1393
+ "single_word": false,
1394
+ "special": true
1395
+ },
1396
+ "254": {
1397
+ "content": "<|spltoken33|>",
1398
+ "lstrip": false,
1399
+ "normalized": false,
1400
+ "rstrip": false,
1401
+ "single_word": false,
1402
+ "special": true
1403
+ },
1404
+ "26": {
1405
+ "content": "<|sq|>",
1406
+ "lstrip": false,
1407
+ "normalized": false,
1408
+ "rstrip": false,
1409
+ "single_word": false,
1410
+ "special": true
1411
+ },
1412
+ "27": {
1413
+ "content": "<|am|>",
1414
+ "lstrip": false,
1415
+ "normalized": false,
1416
+ "rstrip": false,
1417
+ "single_word": false,
1418
+ "special": true
1419
+ },
1420
+ "28": {
1421
+ "content": "<|ar|>",
1422
+ "lstrip": false,
1423
+ "normalized": false,
1424
+ "rstrip": false,
1425
+ "single_word": false,
1426
+ "special": true
1427
+ },
1428
+ "29": {
1429
+ "content": "<|an|>",
1430
+ "lstrip": false,
1431
+ "normalized": false,
1432
+ "rstrip": false,
1433
+ "single_word": false,
1434
+ "special": true
1435
+ },
1436
+ "3": {
1437
+ "content": "<|endoftext|>",
1438
+ "lstrip": false,
1439
+ "normalized": false,
1440
+ "rstrip": false,
1441
+ "single_word": false,
1442
+ "special": true
1443
+ },
1444
+ "30": {
1445
+ "content": "<|hy|>",
1446
+ "lstrip": false,
1447
+ "normalized": false,
1448
+ "rstrip": false,
1449
+ "single_word": false,
1450
+ "special": true
1451
+ },
1452
+ "31": {
1453
+ "content": "<|as|>",
1454
+ "lstrip": false,
1455
+ "normalized": false,
1456
+ "rstrip": false,
1457
+ "single_word": false,
1458
+ "special": true
1459
+ },
1460
+ "32": {
1461
+ "content": "<|av|>",
1462
+ "lstrip": false,
1463
+ "normalized": false,
1464
+ "rstrip": false,
1465
+ "single_word": false,
1466
+ "special": true
1467
+ },
1468
+ "33": {
1469
+ "content": "<|ae|>",
1470
+ "lstrip": false,
1471
+ "normalized": false,
1472
+ "rstrip": false,
1473
+ "single_word": false,
1474
+ "special": true
1475
+ },
1476
+ "34": {
1477
+ "content": "<|ay|>",
1478
+ "lstrip": false,
1479
+ "normalized": false,
1480
+ "rstrip": false,
1481
+ "single_word": false,
1482
+ "special": true
1483
+ },
1484
+ "35": {
1485
+ "content": "<|az|>",
1486
+ "lstrip": false,
1487
+ "normalized": false,
1488
+ "rstrip": false,
1489
+ "single_word": false,
1490
+ "special": true
1491
+ },
1492
+ "36": {
1493
+ "content": "<|bm|>",
1494
+ "lstrip": false,
1495
+ "normalized": false,
1496
+ "rstrip": false,
1497
+ "single_word": false,
1498
+ "special": true
1499
+ },
1500
+ "37": {
1501
+ "content": "<|ba|>",
1502
+ "lstrip": false,
1503
+ "normalized": false,
1504
+ "rstrip": false,
1505
+ "single_word": false,
1506
+ "special": true
1507
+ },
1508
+ "38": {
1509
+ "content": "<|eu|>",
1510
+ "lstrip": false,
1511
+ "normalized": false,
1512
+ "rstrip": false,
1513
+ "single_word": false,
1514
+ "special": true
1515
+ },
1516
+ "39": {
1517
+ "content": "<|be|>",
1518
+ "lstrip": false,
1519
+ "normalized": false,
1520
+ "rstrip": false,
1521
+ "single_word": false,
1522
+ "special": true
1523
+ },
1524
+ "4": {
1525
+ "content": "<|startoftranscript|>",
1526
+ "lstrip": false,
1527
+ "normalized": false,
1528
+ "rstrip": false,
1529
+ "single_word": false,
1530
+ "special": true
1531
+ },
1532
+ "40": {
1533
+ "content": "<|bn|>",
1534
+ "lstrip": false,
1535
+ "normalized": false,
1536
+ "rstrip": false,
1537
+ "single_word": false,
1538
+ "special": true
1539
+ },
1540
+ "41": {
1541
+ "content": "<|bi|>",
1542
+ "lstrip": false,
1543
+ "normalized": false,
1544
+ "rstrip": false,
1545
+ "single_word": false,
1546
+ "special": true
1547
+ },
1548
+ "42": {
1549
+ "content": "<|bs|>",
1550
+ "lstrip": false,
1551
+ "normalized": false,
1552
+ "rstrip": false,
1553
+ "single_word": false,
1554
+ "special": true
1555
+ },
1556
+ "43": {
1557
+ "content": "<|br|>",
1558
+ "lstrip": false,
1559
+ "normalized": false,
1560
+ "rstrip": false,
1561
+ "single_word": false,
1562
+ "special": true
1563
+ },
1564
+ "44": {
1565
+ "content": "<|bg|>",
1566
+ "lstrip": false,
1567
+ "normalized": false,
1568
+ "rstrip": false,
1569
+ "single_word": false,
1570
+ "special": true
1571
+ },
1572
+ "45": {
1573
+ "content": "<|my|>",
1574
+ "lstrip": false,
1575
+ "normalized": false,
1576
+ "rstrip": false,
1577
+ "single_word": false,
1578
+ "special": true
1579
+ },
1580
+ "46": {
1581
+ "content": "<|ca|>",
1582
+ "lstrip": false,
1583
+ "normalized": false,
1584
+ "rstrip": false,
1585
+ "single_word": false,
1586
+ "special": true
1587
+ },
1588
+ "47": {
1589
+ "content": "<|ch|>",
1590
+ "lstrip": false,
1591
+ "normalized": false,
1592
+ "rstrip": false,
1593
+ "single_word": false,
1594
+ "special": true
1595
+ },
1596
+ "48": {
1597
+ "content": "<|ce|>",
1598
+ "lstrip": false,
1599
+ "normalized": false,
1600
+ "rstrip": false,
1601
+ "single_word": false,
1602
+ "special": true
1603
+ },
1604
+ "49": {
1605
+ "content": "<|ny|>",
1606
+ "lstrip": false,
1607
+ "normalized": false,
1608
+ "rstrip": false,
1609
+ "single_word": false,
1610
+ "special": true
1611
+ },
1612
+ "5": {
1613
+ "content": "<|pnc|>",
1614
+ "lstrip": false,
1615
+ "normalized": false,
1616
+ "rstrip": false,
1617
+ "single_word": false,
1618
+ "special": true
1619
+ },
1620
+ "50": {
1621
+ "content": "<|zh|>",
1622
+ "lstrip": false,
1623
+ "normalized": false,
1624
+ "rstrip": false,
1625
+ "single_word": false,
1626
+ "special": true
1627
+ },
1628
+ "51": {
1629
+ "content": "<|cu|>",
1630
+ "lstrip": false,
1631
+ "normalized": false,
1632
+ "rstrip": false,
1633
+ "single_word": false,
1634
+ "special": true
1635
+ },
1636
+ "52": {
1637
+ "content": "<|cv|>",
1638
+ "lstrip": false,
1639
+ "normalized": false,
1640
+ "rstrip": false,
1641
+ "single_word": false,
1642
+ "special": true
1643
+ },
1644
+ "53": {
1645
+ "content": "<|kw|>",
1646
+ "lstrip": false,
1647
+ "normalized": false,
1648
+ "rstrip": false,
1649
+ "single_word": false,
1650
+ "special": true
1651
+ },
1652
+ "54": {
1653
+ "content": "<|co|>",
1654
+ "lstrip": false,
1655
+ "normalized": false,
1656
+ "rstrip": false,
1657
+ "single_word": false,
1658
+ "special": true
1659
+ },
1660
+ "55": {
1661
+ "content": "<|cr|>",
1662
+ "lstrip": false,
1663
+ "normalized": false,
1664
+ "rstrip": false,
1665
+ "single_word": false,
1666
+ "special": true
1667
+ },
1668
+ "56": {
1669
+ "content": "<|hr|>",
1670
+ "lstrip": false,
1671
+ "normalized": false,
1672
+ "rstrip": false,
1673
+ "single_word": false,
1674
+ "special": true
1675
+ },
1676
+ "57": {
1677
+ "content": "<|cs|>",
1678
+ "lstrip": false,
1679
+ "normalized": false,
1680
+ "rstrip": false,
1681
+ "single_word": false,
1682
+ "special": true
1683
+ },
1684
+ "58": {
1685
+ "content": "<|da|>",
1686
+ "lstrip": false,
1687
+ "normalized": false,
1688
+ "rstrip": false,
1689
+ "single_word": false,
1690
+ "special": true
1691
+ },
1692
+ "59": {
1693
+ "content": "<|dv|>",
1694
+ "lstrip": false,
1695
+ "normalized": false,
1696
+ "rstrip": false,
1697
+ "single_word": false,
1698
+ "special": true
1699
+ },
1700
+ "6": {
1701
+ "content": "<|nopnc|>",
1702
+ "lstrip": false,
1703
+ "normalized": false,
1704
+ "rstrip": false,
1705
+ "single_word": false,
1706
+ "special": true
1707
+ },
1708
+ "60": {
1709
+ "content": "<|nl|>",
1710
+ "lstrip": false,
1711
+ "normalized": false,
1712
+ "rstrip": false,
1713
+ "single_word": false,
1714
+ "special": true
1715
+ },
1716
+ "61": {
1717
+ "content": "<|dz|>",
1718
+ "lstrip": false,
1719
+ "normalized": false,
1720
+ "rstrip": false,
1721
+ "single_word": false,
1722
+ "special": true
1723
+ },
1724
+ "62": {
1725
+ "content": "<|en|>",
1726
+ "lstrip": false,
1727
+ "normalized": false,
1728
+ "rstrip": false,
1729
+ "single_word": false,
1730
+ "special": true
1731
+ },
1732
+ "63": {
1733
+ "content": "<|eo|>",
1734
+ "lstrip": false,
1735
+ "normalized": false,
1736
+ "rstrip": false,
1737
+ "single_word": false,
1738
+ "special": true
1739
+ },
1740
+ "64": {
1741
+ "content": "<|et|>",
1742
+ "lstrip": false,
1743
+ "normalized": false,
1744
+ "rstrip": false,
1745
+ "single_word": false,
1746
+ "special": true
1747
+ },
1748
+ "65": {
1749
+ "content": "<|ee|>",
1750
+ "lstrip": false,
1751
+ "normalized": false,
1752
+ "rstrip": false,
1753
+ "single_word": false,
1754
+ "special": true
1755
+ },
1756
+ "66": {
1757
+ "content": "<|fo|>",
1758
+ "lstrip": false,
1759
+ "normalized": false,
1760
+ "rstrip": false,
1761
+ "single_word": false,
1762
+ "special": true
1763
+ },
1764
+ "67": {
1765
+ "content": "<|fj|>",
1766
+ "lstrip": false,
1767
+ "normalized": false,
1768
+ "rstrip": false,
1769
+ "single_word": false,
1770
+ "special": true
1771
+ },
1772
+ "68": {
1773
+ "content": "<|fi|>",
1774
+ "lstrip": false,
1775
+ "normalized": false,
1776
+ "rstrip": false,
1777
+ "single_word": false,
1778
+ "special": true
1779
+ },
1780
+ "69": {
1781
+ "content": "<|fr|>",
1782
+ "lstrip": false,
1783
+ "normalized": false,
1784
+ "rstrip": false,
1785
+ "single_word": false,
1786
+ "special": true
1787
+ },
1788
+ "7": {
1789
+ "content": "<|startofcontext|>",
1790
+ "lstrip": false,
1791
+ "normalized": false,
1792
+ "rstrip": false,
1793
+ "single_word": false,
1794
+ "special": true
1795
+ },
1796
+ "70": {
1797
+ "content": "<|fy|>",
1798
+ "lstrip": false,
1799
+ "normalized": false,
1800
+ "rstrip": false,
1801
+ "single_word": false,
1802
+ "special": true
1803
+ },
1804
+ "71": {
1805
+ "content": "<|ff|>",
1806
+ "lstrip": false,
1807
+ "normalized": false,
1808
+ "rstrip": false,
1809
+ "single_word": false,
1810
+ "special": true
1811
+ },
1812
+ "72": {
1813
+ "content": "<|gd|>",
1814
+ "lstrip": false,
1815
+ "normalized": false,
1816
+ "rstrip": false,
1817
+ "single_word": false,
1818
+ "special": true
1819
+ },
1820
+ "73": {
1821
+ "content": "<|gl|>",
1822
+ "lstrip": false,
1823
+ "normalized": false,
1824
+ "rstrip": false,
1825
+ "single_word": false,
1826
+ "special": true
1827
+ },
1828
+ "74": {
1829
+ "content": "<|lg|>",
1830
+ "lstrip": false,
1831
+ "normalized": false,
1832
+ "rstrip": false,
1833
+ "single_word": false,
1834
+ "special": true
1835
+ },
1836
+ "75": {
1837
+ "content": "<|ka|>",
1838
+ "lstrip": false,
1839
+ "normalized": false,
1840
+ "rstrip": false,
1841
+ "single_word": false,
1842
+ "special": true
1843
+ },
1844
+ "76": {
1845
+ "content": "<|de|>",
1846
+ "lstrip": false,
1847
+ "normalized": false,
1848
+ "rstrip": false,
1849
+ "single_word": false,
1850
+ "special": true
1851
+ },
1852
+ "77": {
1853
+ "content": "<|el|>",
1854
+ "lstrip": false,
1855
+ "normalized": false,
1856
+ "rstrip": false,
1857
+ "single_word": false,
1858
+ "special": true
1859
+ },
1860
+ "78": {
1861
+ "content": "<|kl|>",
1862
+ "lstrip": false,
1863
+ "normalized": false,
1864
+ "rstrip": false,
1865
+ "single_word": false,
1866
+ "special": true
1867
+ },
1868
+ "79": {
1869
+ "content": "<|gn|>",
1870
+ "lstrip": false,
1871
+ "normalized": false,
1872
+ "rstrip": false,
1873
+ "single_word": false,
1874
+ "special": true
1875
+ },
1876
+ "8": {
1877
+ "content": "<|itn|>",
1878
+ "lstrip": false,
1879
+ "normalized": false,
1880
+ "rstrip": false,
1881
+ "single_word": false,
1882
+ "special": true
1883
+ },
1884
+ "80": {
1885
+ "content": "<|gu|>",
1886
+ "lstrip": false,
1887
+ "normalized": false,
1888
+ "rstrip": false,
1889
+ "single_word": false,
1890
+ "special": true
1891
+ },
1892
+ "81": {
1893
+ "content": "<|ht|>",
1894
+ "lstrip": false,
1895
+ "normalized": false,
1896
+ "rstrip": false,
1897
+ "single_word": false,
1898
+ "special": true
1899
+ },
1900
+ "82": {
1901
+ "content": "<|ha|>",
1902
+ "lstrip": false,
1903
+ "normalized": false,
1904
+ "rstrip": false,
1905
+ "single_word": false,
1906
+ "special": true
1907
+ },
1908
+ "83": {
1909
+ "content": "<|he|>",
1910
+ "lstrip": false,
1911
+ "normalized": false,
1912
+ "rstrip": false,
1913
+ "single_word": false,
1914
+ "special": true
1915
+ },
1916
+ "84": {
1917
+ "content": "<|hz|>",
1918
+ "lstrip": false,
1919
+ "normalized": false,
1920
+ "rstrip": false,
1921
+ "single_word": false,
1922
+ "special": true
1923
+ },
1924
+ "85": {
1925
+ "content": "<|hi|>",
1926
+ "lstrip": false,
1927
+ "normalized": false,
1928
+ "rstrip": false,
1929
+ "single_word": false,
1930
+ "special": true
1931
+ },
1932
+ "86": {
1933
+ "content": "<|ho|>",
1934
+ "lstrip": false,
1935
+ "normalized": false,
1936
+ "rstrip": false,
1937
+ "single_word": false,
1938
+ "special": true
1939
+ },
1940
+ "87": {
1941
+ "content": "<|hu|>",
1942
+ "lstrip": false,
1943
+ "normalized": false,
1944
+ "rstrip": false,
1945
+ "single_word": false,
1946
+ "special": true
1947
+ },
1948
+ "88": {
1949
+ "content": "<|is|>",
1950
+ "lstrip": false,
1951
+ "normalized": false,
1952
+ "rstrip": false,
1953
+ "single_word": false,
1954
+ "special": true
1955
+ },
1956
+ "89": {
1957
+ "content": "<|io|>",
1958
+ "lstrip": false,
1959
+ "normalized": false,
1960
+ "rstrip": false,
1961
+ "single_word": false,
1962
+ "special": true
1963
+ },
1964
+ "9": {
1965
+ "content": "<|noitn|>",
1966
+ "lstrip": false,
1967
+ "normalized": false,
1968
+ "rstrip": false,
1969
+ "single_word": false,
1970
+ "special": true
1971
+ },
1972
+ "90": {
1973
+ "content": "<|ig|>",
1974
+ "lstrip": false,
1975
+ "normalized": false,
1976
+ "rstrip": false,
1977
+ "single_word": false,
1978
+ "special": true
1979
+ },
1980
+ "91": {
1981
+ "content": "<|id|>",
1982
+ "lstrip": false,
1983
+ "normalized": false,
1984
+ "rstrip": false,
1985
+ "single_word": false,
1986
+ "special": true
1987
+ },
1988
+ "92": {
1989
+ "content": "<|ia|>",
1990
+ "lstrip": false,
1991
+ "normalized": false,
1992
+ "rstrip": false,
1993
+ "single_word": false,
1994
+ "special": true
1995
+ },
1996
+ "93": {
1997
+ "content": "<|ie|>",
1998
+ "lstrip": false,
1999
+ "normalized": false,
2000
+ "rstrip": false,
2001
+ "single_word": false,
2002
+ "special": true
2003
+ },
2004
+ "94": {
2005
+ "content": "<|iu|>",
2006
+ "lstrip": false,
2007
+ "normalized": false,
2008
+ "rstrip": false,
2009
+ "single_word": false,
2010
+ "special": true
2011
+ },
2012
+ "95": {
2013
+ "content": "<|ik|>",
2014
+ "lstrip": false,
2015
+ "normalized": false,
2016
+ "rstrip": false,
2017
+ "single_word": false,
2018
+ "special": true
2019
+ },
2020
+ "96": {
2021
+ "content": "<|ga|>",
2022
+ "lstrip": false,
2023
+ "normalized": false,
2024
+ "rstrip": false,
2025
+ "single_word": false,
2026
+ "special": true
2027
+ },
2028
+ "97": {
2029
+ "content": "<|it|>",
2030
+ "lstrip": false,
2031
+ "normalized": false,
2032
+ "rstrip": false,
2033
+ "single_word": false,
2034
+ "special": true
2035
+ },
2036
+ "98": {
2037
+ "content": "<|ja|>",
2038
+ "lstrip": false,
2039
+ "normalized": false,
2040
+ "rstrip": false,
2041
+ "single_word": false,
2042
+ "special": true
2043
+ },
2044
+ "99": {
2045
+ "content": "<|jv|>",
2046
+ "lstrip": false,
2047
+ "normalized": false,
2048
+ "rstrip": false,
2049
+ "single_word": false,
2050
+ "special": true
2051
+ }
2052
+ },
2053
+ "additional_special_tokens": [
2054
+ "<|nospeech|>",
2055
+ "<|pnc|>",
2056
+ "<|nopnc|>",
2057
+ "<|startofcontext|>",
2058
+ "<|itn|>",
2059
+ "<|noitn|>",
2060
+ "<|timestamp|>",
2061
+ "<|notimestamp|>",
2062
+ "<|diarize|>",
2063
+ "<|nodiarize|>",
2064
+ "<|spkchange|>",
2065
+ "<|audioseparator|>",
2066
+ "<|emo:undefined|>",
2067
+ "<|emo:neutral|>",
2068
+ "<|emo:happy|>",
2069
+ "<|emo:sad|>",
2070
+ "<|emo:angry|>",
2071
+ "<|unklang|>",
2072
+ "<|aa|>",
2073
+ "<|ab|>",
2074
+ "<|af|>",
2075
+ "<|ak|>",
2076
+ "<|sq|>",
2077
+ "<|am|>",
2078
+ "<|ar|>",
2079
+ "<|an|>",
2080
+ "<|hy|>",
2081
+ "<|as|>",
2082
+ "<|av|>",
2083
+ "<|ae|>",
2084
+ "<|ay|>",
2085
+ "<|az|>",
2086
+ "<|bm|>",
2087
+ "<|ba|>",
2088
+ "<|eu|>",
2089
+ "<|be|>",
2090
+ "<|bn|>",
2091
+ "<|bi|>",
2092
+ "<|bs|>",
2093
+ "<|br|>",
2094
+ "<|bg|>",
2095
+ "<|my|>",
2096
+ "<|ca|>",
2097
+ "<|ch|>",
2098
+ "<|ce|>",
2099
+ "<|ny|>",
2100
+ "<|zh|>",
2101
+ "<|cu|>",
2102
+ "<|cv|>",
2103
+ "<|kw|>",
2104
+ "<|co|>",
2105
+ "<|cr|>",
2106
+ "<|hr|>",
2107
+ "<|cs|>",
2108
+ "<|da|>",
2109
+ "<|dv|>",
2110
+ "<|nl|>",
2111
+ "<|dz|>",
2112
+ "<|en|>",
2113
+ "<|eo|>",
2114
+ "<|et|>",
2115
+ "<|ee|>",
2116
+ "<|fo|>",
2117
+ "<|fj|>",
2118
+ "<|fi|>",
2119
+ "<|fr|>",
2120
+ "<|fy|>",
2121
+ "<|ff|>",
2122
+ "<|gd|>",
2123
+ "<|gl|>",
2124
+ "<|lg|>",
2125
+ "<|ka|>",
2126
+ "<|de|>",
2127
+ "<|el|>",
2128
+ "<|kl|>",
2129
+ "<|gn|>",
2130
+ "<|gu|>",
2131
+ "<|ht|>",
2132
+ "<|ha|>",
2133
+ "<|he|>",
2134
+ "<|hz|>",
2135
+ "<|hi|>",
2136
+ "<|ho|>",
2137
+ "<|hu|>",
2138
+ "<|is|>",
2139
+ "<|io|>",
2140
+ "<|ig|>",
2141
+ "<|id|>",
2142
+ "<|ia|>",
2143
+ "<|ie|>",
2144
+ "<|iu|>",
2145
+ "<|ik|>",
2146
+ "<|ga|>",
2147
+ "<|it|>",
2148
+ "<|ja|>",
2149
+ "<|jv|>",
2150
+ "<|kn|>",
2151
+ "<|kr|>",
2152
+ "<|ks|>",
2153
+ "<|kk|>",
2154
+ "<|km|>",
2155
+ "<|ki|>",
2156
+ "<|rw|>",
2157
+ "<|ky|>",
2158
+ "<|kv|>",
2159
+ "<|kg|>",
2160
+ "<|ko|>",
2161
+ "<|kj|>",
2162
+ "<|ku|>",
2163
+ "<|lo|>",
2164
+ "<|la|>",
2165
+ "<|lv|>",
2166
+ "<|li|>",
2167
+ "<|ln|>",
2168
+ "<|lt|>",
2169
+ "<|lu|>",
2170
+ "<|lb|>",
2171
+ "<|mk|>",
2172
+ "<|mg|>",
2173
+ "<|ms|>",
2174
+ "<|ml|>",
2175
+ "<|mt|>",
2176
+ "<|gv|>",
2177
+ "<|mi|>",
2178
+ "<|mr|>",
2179
+ "<|mh|>",
2180
+ "<|mn|>",
2181
+ "<|na|>",
2182
+ "<|nv|>",
2183
+ "<|nd|>",
2184
+ "<|nr|>",
2185
+ "<|ng|>",
2186
+ "<|ne|>",
2187
+ "<|no|>",
2188
+ "<|nb|>",
2189
+ "<|nn|>",
2190
+ "<|oc|>",
2191
+ "<|oj|>",
2192
+ "<|or|>",
2193
+ "<|om|>",
2194
+ "<|os|>",
2195
+ "<|pi|>",
2196
+ "<|ps|>",
2197
+ "<|fa|>",
2198
+ "<|pl|>",
2199
+ "<|pt|>",
2200
+ "<|pa|>",
2201
+ "<|qu|>",
2202
+ "<|ro|>",
2203
+ "<|rm|>",
2204
+ "<|rn|>",
2205
+ "<|ru|>",
2206
+ "<|se|>",
2207
+ "<|sm|>",
2208
+ "<|sg|>",
2209
+ "<|sa|>",
2210
+ "<|sc|>",
2211
+ "<|sr|>",
2212
+ "<|sn|>",
2213
+ "<|sd|>",
2214
+ "<|si|>",
2215
+ "<|sk|>",
2216
+ "<|sl|>",
2217
+ "<|so|>",
2218
+ "<|st|>",
2219
+ "<|es|>",
2220
+ "<|su|>",
2221
+ "<|sw|>",
2222
+ "<|ss|>",
2223
+ "<|sv|>",
2224
+ "<|tl|>",
2225
+ "<|ty|>",
2226
+ "<|tg|>",
2227
+ "<|ta|>",
2228
+ "<|tt|>",
2229
+ "<|te|>",
2230
+ "<|th|>",
2231
+ "<|bo|>",
2232
+ "<|ti|>",
2233
+ "<|to|>",
2234
+ "<|ts|>",
2235
+ "<|tn|>",
2236
+ "<|tr|>",
2237
+ "<|tk|>",
2238
+ "<|tw|>",
2239
+ "<|ug|>",
2240
+ "<|uk|>",
2241
+ "<|ur|>",
2242
+ "<|uz|>",
2243
+ "<|ve|>",
2244
+ "<|vi|>",
2245
+ "<|vo|>",
2246
+ "<|wa|>",
2247
+ "<|cy|>",
2248
+ "<|wo|>",
2249
+ "<|xh|>",
2250
+ "<|ii|>",
2251
+ "<|yi|>",
2252
+ "<|yo|>",
2253
+ "<|za|>",
2254
+ "<|zu|>",
2255
+ "<|spk0|>",
2256
+ "<|spk1|>",
2257
+ "<|spk2|>",
2258
+ "<|spk3|>",
2259
+ "<|spk4|>",
2260
+ "<|spk5|>",
2261
+ "<|spk6|>",
2262
+ "<|spk7|>",
2263
+ "<|spk8|>",
2264
+ "<|spk9|>",
2265
+ "<|spk10|>",
2266
+ "<|spk11|>",
2267
+ "<|spk12|>",
2268
+ "<|spk13|>",
2269
+ "<|spk14|>",
2270
+ "<|spk15|>",
2271
+ "<|spltoken0|>",
2272
+ "<|spltoken1|>",
2273
+ "<|spltoken2|>",
2274
+ "<|spltoken3|>",
2275
+ "<|spltoken4|>",
2276
+ "<|spltoken5|>",
2277
+ "<|spltoken6|>",
2278
+ "<|spltoken7|>",
2279
+ "<|spltoken8|>",
2280
+ "<|spltoken9|>",
2281
+ "<|spltoken10|>",
2282
+ "<|spltoken11|>",
2283
+ "<|spltoken12|>",
2284
+ "<|spltoken13|>",
2285
+ "<|spltoken14|>",
2286
+ "<|spltoken15|>",
2287
+ "<|spltoken16|>",
2288
+ "<|spltoken17|>",
2289
+ "<|spltoken18|>",
2290
+ "<|spltoken19|>",
2291
+ "<|spltoken20|>",
2292
+ "<|spltoken21|>",
2293
+ "<|spltoken22|>",
2294
+ "<|spltoken23|>",
2295
+ "<|spltoken24|>",
2296
+ "<|spltoken25|>",
2297
+ "<|spltoken26|>",
2298
+ "<|spltoken27|>",
2299
+ "<|spltoken28|>",
2300
+ "<|spltoken29|>",
2301
+ "<|spltoken30|>",
2302
+ "<|spltoken31|>",
2303
+ "<|spltoken32|>",
2304
+ "<|spltoken33|>"
2305
+ ],
2306
+ "auto_map": {
2307
+ "AutoTokenizer": [
2308
+ "tokenization_cohere_asr.CohereAsrTokenizer",
2309
+ null
2310
+ ]
2311
+ },
2312
+ "clean_up_tokenization_spaces": false,
2313
+ "sp_model_kwargs": {}
2314
+ }