Upload folder using huggingface_hub
Browse files- MyEncoderASR.py +156 -1
- __pycache__/MyEncoderASR.cpython-310.pyc +0 -0
- inference.yaml +2 -2
- inference_verbose.yaml +202 -0
MyEncoderASR.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
from speechbrain.inference.ASR import EncoderASR
|
|
|
|
|
|
|
| 2 |
import torch
|
| 3 |
import speechbrain
|
| 4 |
import functools
|
|
|
|
| 5 |
|
| 6 |
class MyEncoderASR(EncoderASR):
|
| 7 |
def transcribe_batch(self, wavs, wav_lens):
|
|
@@ -33,6 +36,7 @@ class MyEncoderASR(EncoderASR):
|
|
| 33 |
with torch.no_grad():
|
| 34 |
wav_lens = wav_lens.to(self.device)
|
| 35 |
encoder_out = self.encode_batch(wavs, wav_lens)
|
|
|
|
| 36 |
predictions = self.decoding_function(encoder_out, wav_lens)
|
| 37 |
is_ctc_text_encoder_tokenizer = isinstance(
|
| 38 |
self.tokenizer, speechbrain.dataio.encoder.CTCTextEncoder
|
|
@@ -50,5 +54,156 @@ class MyEncoderASR(EncoderASR):
|
|
| 50 |
]
|
| 51 |
else:
|
| 52 |
predicted_words = [hyp[0].text for hyp in predictions]
|
| 53 |
-
|
| 54 |
return predicted_words, predictions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from speechbrain.inference.ASR import EncoderASR
|
| 2 |
+
from speechbrain.decoders.ctc import TorchAudioCTCPrefixBeamSearcher
|
| 3 |
+
from speechbrain.decoders.ctc import CTCHypothesis
|
| 4 |
import torch
|
| 5 |
import speechbrain
|
| 6 |
import functools
|
| 7 |
+
import matplotlib.pyplot as plt
|
| 8 |
|
| 9 |
class MyEncoderASR(EncoderASR):
|
| 10 |
def transcribe_batch(self, wavs, wav_lens):
|
|
|
|
| 36 |
with torch.no_grad():
|
| 37 |
wav_lens = wav_lens.to(self.device)
|
| 38 |
encoder_out = self.encode_batch(wavs, wav_lens)
|
| 39 |
+
# frame level logits.
|
| 40 |
predictions = self.decoding_function(encoder_out, wav_lens)
|
| 41 |
is_ctc_text_encoder_tokenizer = isinstance(
|
| 42 |
self.tokenizer, speechbrain.dataio.encoder.CTCTextEncoder
|
|
|
|
| 54 |
]
|
| 55 |
else:
|
| 56 |
predicted_words = [hyp[0].text for hyp in predictions]
|
|
|
|
| 57 |
return predicted_words, predictions
|
| 58 |
+
|
| 59 |
+
class MyCTCPrefixBeamSearcher(TorchAudioCTCPrefixBeamSearcher):
|
| 60 |
+
def decode_beams(self, log_probs, wav_len):
|
| 61 |
+
"""Decode log_probs using TorchAudio CTC decoder.
|
| 62 |
+
|
| 63 |
+
If `using_cpu_decoder=True` then log_probs and wav_len are moved to CPU before decoding.
|
| 64 |
+
When using CUDA CTC decoder, the timestep information is not available. Therefore, the timesteps
|
| 65 |
+
in the returned hypotheses are set to None.
|
| 66 |
+
|
| 67 |
+
Make sure that the input are in the log domain. The decoder will fail to decode
|
| 68 |
+
logits or probabilities. The input should be the log probabilities of the CTC output.
|
| 69 |
+
|
| 70 |
+
Arguments
|
| 71 |
+
---------
|
| 72 |
+
log_probs : torch.Tensor
|
| 73 |
+
The log probabilities of the input audio.
|
| 74 |
+
Shape: (batch_size, seq_length, vocab_size)
|
| 75 |
+
wav_len : torch.Tensor, default: None
|
| 76 |
+
The speechbrain-style relative length. Shape: (batch_size,)
|
| 77 |
+
If None, then the length of each audio is assumed to be seq_length.
|
| 78 |
+
|
| 79 |
+
Returns
|
| 80 |
+
-------
|
| 81 |
+
list of list of CTCHypothesis
|
| 82 |
+
The decoded hypotheses. The outer list is over the batch dimension, and the inner list is over the topk dimension.
|
| 83 |
+
"""
|
| 84 |
+
if wav_len is not None:
|
| 85 |
+
wav_len = log_probs.size(1) * wav_len
|
| 86 |
+
else:
|
| 87 |
+
wav_len = torch.tensor(
|
| 88 |
+
[log_probs.size(1)] * log_probs.size(0),
|
| 89 |
+
device=log_probs.device,
|
| 90 |
+
dtype=torch.int32,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
if wav_len.dtype != torch.int32:
|
| 94 |
+
wav_len = wav_len.to(torch.int32)
|
| 95 |
+
|
| 96 |
+
if log_probs.dtype != torch.float32:
|
| 97 |
+
raise ValueError("log_probs must be float32.")
|
| 98 |
+
|
| 99 |
+
# When using CPU decoder, we need to move the log_probs and wav_len to CPU
|
| 100 |
+
if self.using_cpu_decoder and log_probs.is_cuda:
|
| 101 |
+
log_probs = log_probs.cpu()
|
| 102 |
+
|
| 103 |
+
if self.using_cpu_decoder and wav_len.is_cuda:
|
| 104 |
+
wav_len = wav_len.cpu()
|
| 105 |
+
|
| 106 |
+
if not log_probs.is_contiguous():
|
| 107 |
+
raise RuntimeError("log_probs must be contiguous.")
|
| 108 |
+
|
| 109 |
+
results = self._ctc_decoder(log_probs, wav_len)
|
| 110 |
+
|
| 111 |
+
tokens_preds = []
|
| 112 |
+
words_preds = []
|
| 113 |
+
scores_preds = []
|
| 114 |
+
timesteps_preds = []
|
| 115 |
+
|
| 116 |
+
# over batch dim
|
| 117 |
+
for i in range(len(results)):
|
| 118 |
+
if self.using_cpu_decoder:
|
| 119 |
+
preds = [
|
| 120 |
+
results[i][j].tokens.tolist()
|
| 121 |
+
for j in range(len(results[i]))
|
| 122 |
+
]
|
| 123 |
+
preds = [
|
| 124 |
+
[self.tokens[token] for token in tokens] for tokens in preds
|
| 125 |
+
]
|
| 126 |
+
tokens_preds.append(preds)
|
| 127 |
+
|
| 128 |
+
timesteps = [
|
| 129 |
+
results[i][j].timesteps.tolist()
|
| 130 |
+
for j in range(len(results[i]))
|
| 131 |
+
]
|
| 132 |
+
timesteps_preds.append(timesteps)
|
| 133 |
+
|
| 134 |
+
else:
|
| 135 |
+
# no timesteps is available for CUDA CTC decoder
|
| 136 |
+
timesteps = [None for _ in range(len(results[i]))]
|
| 137 |
+
timesteps_preds.append(timesteps)
|
| 138 |
+
|
| 139 |
+
preds = [results[i][j].tokens for j in range(len(results[i]))]
|
| 140 |
+
preds = [
|
| 141 |
+
[self.tokens[token] for token in tokens] for tokens in preds
|
| 142 |
+
]
|
| 143 |
+
tokens_preds.append(preds)
|
| 144 |
+
|
| 145 |
+
words = [results[i][j].words for j in range(len(results[i]))]
|
| 146 |
+
words_preds.append(words)
|
| 147 |
+
|
| 148 |
+
scores = [results[i][j].score for j in range(len(results[i]))]
|
| 149 |
+
scores_preds.append(scores)
|
| 150 |
+
|
| 151 |
+
hyps = []
|
| 152 |
+
for (
|
| 153 |
+
batch_index,
|
| 154 |
+
(batch_text, batch_score, batch_timesteps),
|
| 155 |
+
) in enumerate(zip(tokens_preds, scores_preds, timesteps_preds)):
|
| 156 |
+
hyps.append([])
|
| 157 |
+
for text, score, timestep in zip(
|
| 158 |
+
batch_text, batch_score, batch_timesteps
|
| 159 |
+
):
|
| 160 |
+
hyps[batch_index].append(
|
| 161 |
+
CTCHypothesis(
|
| 162 |
+
text=text,
|
| 163 |
+
last_lm_state=None,
|
| 164 |
+
score=score,
|
| 165 |
+
lm_score=score,
|
| 166 |
+
text_frames=timestep,
|
| 167 |
+
)
|
| 168 |
+
)
|
| 169 |
+
return hyps
|
| 170 |
+
|
| 171 |
+
def plot_alignments(waveform, emission, tokens, timesteps, sample_rate):
|
| 172 |
+
t = torch.arange(waveform.size(0)) / sample_rate
|
| 173 |
+
ratio = waveform.size(0) / emission.size(1) / sample_rate
|
| 174 |
+
|
| 175 |
+
chars = []
|
| 176 |
+
words = []
|
| 177 |
+
word_start = None
|
| 178 |
+
for token, timestep in zip(tokens, timesteps * ratio):
|
| 179 |
+
if token == "|":
|
| 180 |
+
if word_start is not None:
|
| 181 |
+
words.append((word_start, timestep))
|
| 182 |
+
word_start = None
|
| 183 |
+
else:
|
| 184 |
+
chars.append((token, timestep))
|
| 185 |
+
if word_start is None:
|
| 186 |
+
word_start = timestep
|
| 187 |
+
|
| 188 |
+
num_axes = len(waveform) // sample_rate + 1
|
| 189 |
+
plt.figure(figsize=[num_axes*10, 5])
|
| 190 |
+
fig, axes = plt.subplots(num_axes, 1)
|
| 191 |
+
|
| 192 |
+
def _plot(ax, xlim):
|
| 193 |
+
ax.plot(t, waveform)
|
| 194 |
+
for token, timestep in chars:
|
| 195 |
+
ax.annotate(token.upper(), (timestep, 0.5))
|
| 196 |
+
for word_start, word_end in words:
|
| 197 |
+
ax.axvspan(word_start, word_end, alpha=0.1, color="red")
|
| 198 |
+
ax.set_ylim(-0.6, 0.7)
|
| 199 |
+
ax.set_yticks([0])
|
| 200 |
+
ax.grid(True, axis="y")
|
| 201 |
+
ax.set_xlim(xlim)
|
| 202 |
+
|
| 203 |
+
for i in range(0, num_axes):
|
| 204 |
+
_plot(axes[i], (i, i+1))
|
| 205 |
+
|
| 206 |
+
axes[num_axes-1].set_xlabel("time (sec)")
|
| 207 |
+
fig.tight_layout()
|
| 208 |
+
|
| 209 |
+
return fig
|
__pycache__/MyEncoderASR.cpython-310.pyc
ADDED
|
Binary file (7.35 kB). View file
|
|
|
inference.yaml
CHANGED
|
@@ -67,8 +67,8 @@ training_target: "target" # "target": deduplicated canonical phoneme sequence; "
|
|
| 67 |
# "canonical"
|
| 68 |
# "perceived": deduplicated perceived phoneme sequence
|
| 69 |
|
| 70 |
-
perceived_ssl: !
|
| 71 |
-
|
| 72 |
freeze: !ref <freeze_perceived_ssl>
|
| 73 |
freeze_feature_extractor: !ref <freeze_perceived_feature_extractor>
|
| 74 |
save_path: !ref <pretrained_models_path>
|
|
|
|
| 67 |
# "canonical"
|
| 68 |
# "perceived": deduplicated perceived phoneme sequence
|
| 69 |
|
| 70 |
+
perceived_ssl: !new:speechbrain.lobes.models.huggingface_transformers.wavlm.WavLM
|
| 71 |
+
source: "microsoft/wavlm-large"
|
| 72 |
freeze: !ref <freeze_perceived_ssl>
|
| 73 |
freeze_feature_extractor: !ref <freeze_perceived_feature_extractor>
|
| 74 |
save_path: !ref <pretrained_models_path>
|
inference_verbose.yaml
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Hyperparameters toggles
|
| 2 |
+
prefix: ""
|
| 3 |
+
|
| 4 |
+
## SSL features Selection
|
| 5 |
+
pretrained_models_path: pretrained_models/
|
| 6 |
+
# pretrained_models:
|
| 7 |
+
# {
|
| 8 |
+
# "wav2vec2_base": "facebook/wav2vec2-base", # 768
|
| 9 |
+
# "hubert_base": "facebook/hubert-base-ls960", # 768
|
| 10 |
+
# "wavlm_base": "microsoft/wavlm-base", # 768
|
| 11 |
+
# "wavlm_base_plus": "microsoft/wavlm-base-plus", # 768
|
| 12 |
+
# "hubert_multilingual": "utter-project/mHuBERT-147", # 768
|
| 13 |
+
# "clap" : "laion/clap-htsat-fused", # 768
|
| 14 |
+
# "data2vec_base": "facebook/data2vec-audio-base", # 768
|
| 15 |
+
|
| 16 |
+
# "wav2vec2_large": "facebook/wav2vec2-large", # 1024
|
| 17 |
+
# "hubert_large": "facebook/hubert-large-ls960", # 1024
|
| 18 |
+
# "wavlm_large": "microsoft/wavlm-large-plus", # 1024
|
| 19 |
+
# "data2vec_large": "facebook/data2vec-audio-large", #1024
|
| 20 |
+
# "whisper_medium": "openai/whisper-medium", # 1024
|
| 21 |
+
|
| 22 |
+
# "whisper_large_v3_turbo": "openai/whisper-large-v3-turbo", # 1280
|
| 23 |
+
# }
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# select pretrained SSL models
|
| 27 |
+
perceived_ssl_model: "wavlm_large" # in pretrained_models
|
| 28 |
+
canonical_ssl_model: Null
|
| 29 |
+
|
| 30 |
+
# # models hidden size, varies by model
|
| 31 |
+
ENCODER_DIM: 1024
|
| 32 |
+
|
| 33 |
+
# # How to fuse the features
|
| 34 |
+
feature_fusion: "mono" # Options: "mono" for single ssl, "dual_ssl_enc" for dual ssl encoder, "dual_loss" for single SSL dual ssl loss
|
| 35 |
+
blend_alpha: 0.5 # If using "blend" fusion
|
| 36 |
+
|
| 37 |
+
# Input files
|
| 38 |
+
# Data files
|
| 39 |
+
data_folder_save: "./data"
|
| 40 |
+
train_annotation: !ref <data_folder_save>/train-train.json
|
| 41 |
+
valid_annotation: !ref <data_folder_save>/train-dev.json
|
| 42 |
+
test_annotation: !ref <data_folder_save>/test.json
|
| 43 |
+
# Extra data
|
| 44 |
+
train_annotation_extra: !ref <data_folder_save>/train-train_with_extra.json
|
| 45 |
+
use_extra_train_data: False
|
| 46 |
+
|
| 47 |
+
evaluate_key: "PER" # use "mpd_f1_seq" for Transformer decoder path best mpd f1
|
| 48 |
+
# "PER_seq" for Transformer decoder's best error rate
|
| 49 |
+
# "PER" for ctc path best error rate
|
| 50 |
+
# "mpd_f1" for ctc path best mpd f1
|
| 51 |
+
max_save_models: 3 # Maximum number of saved models for each metrics
|
| 52 |
+
# generate training id for output folder
|
| 53 |
+
# generate_training_id: !apply:trainer.generate_training_id.generate_training_id [!ref <perceived_ssl_model_id>, !ref <canonical_ssl_model_id>, !ref <feature_fusion>, !ref <prefix>]
|
| 54 |
+
|
| 55 |
+
# output files
|
| 56 |
+
output_folder: !ref exp_l2arctic/<perceived_ssl_model>_<canonical_ssl_model>_<feature_fusion>_<prefix>
|
| 57 |
+
per_file: !ref <output_folder>/per.txt
|
| 58 |
+
mpd_file: !ref <output_folder>/mpd.txt
|
| 59 |
+
save_folder: !ref <output_folder>/save
|
| 60 |
+
train_log: !ref <output_folder>/train_log.txt
|
| 61 |
+
|
| 62 |
+
on_training_test_wer_folder: !ref <output_folder>/on_training_test_wer
|
| 63 |
+
on_training_test_mpd_folder: !ref <output_folder>/on_training_test_mpd
|
| 64 |
+
|
| 65 |
+
# Training Target
|
| 66 |
+
training_target: "target" # "target": deduplicated canonical phoneme sequence; "target_with_repeats": with repeats
|
| 67 |
+
# "canonical"
|
| 68 |
+
# "perceived": deduplicated perceived phoneme sequence
|
| 69 |
+
|
| 70 |
+
# perceived_ssl: !apply:trainer.AutoSSLoader.AutoSSLLoader
|
| 71 |
+
perceived_ssl: !new:speechbrain.lobes.models.huggingface_transformers.wavlm.WavLM
|
| 72 |
+
source: "microsoft/wavlm-large"
|
| 73 |
+
freeze: !ref <freeze_perceived_ssl>
|
| 74 |
+
freeze_feature_extractor: !ref <freeze_perceived_feature_extractor>
|
| 75 |
+
save_path: !ref <pretrained_models_path>
|
| 76 |
+
output_all_hiddens: False
|
| 77 |
+
preceived_ssl_emb_layer: -1
|
| 78 |
+
|
| 79 |
+
enc: !new:torch.nn.Sequential
|
| 80 |
+
- !new:speechbrain.lobes.models.VanillaNN.VanillaNN
|
| 81 |
+
input_shape: [null, null, !ref <ENCODER_DIM>]
|
| 82 |
+
activation: !ref <activation>
|
| 83 |
+
dnn_blocks: !ref <dnn_layers>
|
| 84 |
+
dnn_neurons: !ref <dnn_neurons>
|
| 85 |
+
- !new:torch.nn.LayerNorm
|
| 86 |
+
normalized_shape: !ref <dnn_neurons>
|
| 87 |
+
|
| 88 |
+
ctc_lin: !new:speechbrain.nnet.linear.Linear
|
| 89 |
+
input_size: !ref <dnn_neurons>
|
| 90 |
+
n_neurons: !ref <output_neurons> # 40 phonemes + 1 blank + 1 err
|
| 91 |
+
|
| 92 |
+
# Model parameters
|
| 93 |
+
activation: !name:torch.nn.LeakyReLU
|
| 94 |
+
dnn_layers: 2
|
| 95 |
+
dnn_neurons: 384
|
| 96 |
+
freeze_perceived_ssl: False
|
| 97 |
+
freeze_canonical_ssl: False
|
| 98 |
+
freeze_perceived_feature_extractor: True # freeze the CNN extractor in wav2vec
|
| 99 |
+
freeze_canonical_feature_extractor: True # Freeze Whisper encoder?
|
| 100 |
+
|
| 101 |
+
log_softmax: !new:speechbrain.nnet.activations.Softmax
|
| 102 |
+
apply_log: True
|
| 103 |
+
|
| 104 |
+
ctc_cost: !name:speechbrain.nnet.losses.ctc_loss
|
| 105 |
+
blank_index: !ref <blank_index>
|
| 106 |
+
|
| 107 |
+
ctc_cost_mispro: !name:speechbrain.nnet.losses.ctc_loss
|
| 108 |
+
blank_index: !ref <blank_index>
|
| 109 |
+
|
| 110 |
+
# Outputs
|
| 111 |
+
output_neurons: 44 # l2arctic: 40phns(sil)+err+blank + eos + bos =44
|
| 112 |
+
blank_index: 0
|
| 113 |
+
|
| 114 |
+
model: !new:torch.nn.ModuleList
|
| 115 |
+
- [!ref <enc>, !ref <ctc_lin>]
|
| 116 |
+
|
| 117 |
+
adam_opt_class: !name:torch.optim.Adam
|
| 118 |
+
lr: !ref <lr>
|
| 119 |
+
|
| 120 |
+
pretrained_opt_class: !name:torch.optim.Adam
|
| 121 |
+
lr: !ref <lr_pretrained>
|
| 122 |
+
|
| 123 |
+
checkpointer: !new:speechbrain.utils.checkpoints.Checkpointer
|
| 124 |
+
checkpoints_dir: !ref <save_folder>
|
| 125 |
+
recoverables:
|
| 126 |
+
model: !ref <model>
|
| 127 |
+
perceived_ssl: !ref <perceived_ssl>
|
| 128 |
+
counter: !ref <epoch_counter>
|
| 129 |
+
allow_partial_load: True
|
| 130 |
+
# canonical_ssl: !ref <canonical_ssl>
|
| 131 |
+
|
| 132 |
+
augmentation: !new:speechbrain.augment.time_domain.SpeedPerturb
|
| 133 |
+
orig_freq: !ref <sample_rate>
|
| 134 |
+
speeds: [95, 100, 105]
|
| 135 |
+
|
| 136 |
+
epoch_counter: !new:speechbrain.utils.epoch_loop.EpochCounter
|
| 137 |
+
limit: !ref <number_of_epochs>
|
| 138 |
+
|
| 139 |
+
train_logger: !new:speechbrain.utils.train_logger.FileTrainLogger
|
| 140 |
+
save_file: !ref <train_log>
|
| 141 |
+
|
| 142 |
+
ctc_stats: !name:speechbrain.utils.metric_stats.MetricStats
|
| 143 |
+
metric: !name:speechbrain.nnet.losses.ctc_loss
|
| 144 |
+
blank_index: !ref <blank_index>
|
| 145 |
+
reduction: batch
|
| 146 |
+
|
| 147 |
+
per_stats: !name:speechbrain.utils.metric_stats.ErrorRateStats
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
# # TIMIT
|
| 151 |
+
# timit_local_data_folder: "/common/db/TIMIT" # Path to TIMIT datase
|
| 152 |
+
|
| 153 |
+
seed: 3047
|
| 154 |
+
__set_seed: !apply:torch.manual_seed [!ref <seed>]
|
| 155 |
+
|
| 156 |
+
# training parameters
|
| 157 |
+
number_of_epochs: 100
|
| 158 |
+
batch_size: 16
|
| 159 |
+
lr: 0.0003
|
| 160 |
+
sorting: ascending
|
| 161 |
+
sample_rate: 16000
|
| 162 |
+
gradient_accumulation: 2
|
| 163 |
+
lr_pretrained: 0.00001
|
| 164 |
+
|
| 165 |
+
# Mix-Precision Training
|
| 166 |
+
auto_mix_prec: true
|
| 167 |
+
# or
|
| 168 |
+
precision: fp16 # 支持 "fp32"、"fp16" 或 "bf16"
|
| 169 |
+
eval_precision: fp32 # 推理同样切换到 FP16
|
| 170 |
+
|
| 171 |
+
# Dataloader options
|
| 172 |
+
train_dataloader_opts:
|
| 173 |
+
batch_size: !ref <batch_size>
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
valid_dataloader_opts:
|
| 177 |
+
batch_size: !ref <batch_size>
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
test_dataloader_opts:
|
| 181 |
+
batch_size: 1
|
| 182 |
+
|
| 183 |
+
pretrainer: !new:speechbrain.utils.parameter_transfer.Pretrainer
|
| 184 |
+
collect_in: !ref <save_folder>/
|
| 185 |
+
loadables:
|
| 186 |
+
perceived_ssl: !ref <perceived_ssl>
|
| 187 |
+
model: !ref <model>
|
| 188 |
+
tokenizer: !ref <tokenizer>
|
| 189 |
+
|
| 190 |
+
encoder: !new:speechbrain.nnet.containers.LengthsCapableSequential
|
| 191 |
+
perceived_ssl: !ref <perceived_ssl>
|
| 192 |
+
enc: !ref <enc>
|
| 193 |
+
ctc_lin: !ref <ctc_lin>
|
| 194 |
+
log_softmax: !ref <log_softmax>
|
| 195 |
+
|
| 196 |
+
decoding_function: !name:speechbrain.decoders.ctc_greedy_decode
|
| 197 |
+
blank_id: !ref <blank_index>
|
| 198 |
+
|
| 199 |
+
tokenizer: !new:speechbrain.dataio.encoder.CTCTextEncoder
|
| 200 |
+
|
| 201 |
+
modules:
|
| 202 |
+
encoder: !ref <encoder>
|