Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.
Python asraudiochineseemotion-recognitionfunasrmcp-servermultilingual-asropenai-compatible-apiparaformerpunctuationpytorchreal-time-asrspeaker-diarizationspeech-recognitionspeech-to-textstreaming-asrtranscriptionvllmvoice-activity-detectionwhisper-alternative
finetune entire bicif_paraformer
shixian.shie3c094ed9df6
diff --git a/funasr/models/e2e_asr_paraformer.py b/funasr/models/e2e_asr_paraformer.pyindex b57c8e228..f1bb2bfc1 100644--- a/funasr/models/e2e_asr_paraformer.py+++ b/funasr/models/e2e_asr_paraformer.py@@ -1025,16 +1025,76 @@ class BiCifParaformer(Paraformer):# 1. Encoderencoder_out, encoder_out_lens = self.encode(speech, speech_lengths)+ intermediate_outs = None+ if isinstance(encoder_out, tuple):+ intermediate_outs = encoder_out[1]+ encoder_out = encoder_out[0]+ loss_att, acc_att, cer_att, wer_att = None, None, None, None+ loss_ctc, cer_ctc = None, None+ loss_pre = Nonestats = dict()+ # 1. CTC branch+ if self.ctc_weight != 0.0:+ loss_ctc, cer_ctc = self._calc_ctc_loss(+ encoder_out, encoder_out_lens, text, text_lengths+ )++ # Collect CTC branch stats+ stats["loss_ctc"] = loss_ctc.detach() if loss_ctc is not None else None+ stats["cer_ctc"] = cer_ctc++ # Intermediate CTC (optional)+ loss_interctc = 0.0+ if self.interctc_weight != 0.0 and intermediate_outs is not None:+ for layer_idx, intermediate_out in intermediate_outs:+ # we assume intermediate_out has the same length & padding+ # as those of encoder_out+ loss_ic, cer_ic = self._calc_ctc_loss(+ intermediate_out, encoder_out_lens, text, text_lengths+ )+ loss_interctc = loss_interctc + loss_ic++ # Collect Intermedaite CTC stats+ stats["loss_interctc_layer{}".format(layer_idx)] = (+ loss_ic.detach() if loss_ic is not None else None+ )+ stats["cer_interctc_layer{}".format(layer_idx)] = cer_ic++ loss_interctc = loss_interctc / len(intermediate_outs)++ # calculate whole encoder loss+ loss_ctc = (+ 1 - self.interctc_weight+ ) * loss_ctc + self.interctc_weight * loss_interctc++ # 2b. Attention decoder branch+ if self.ctc_weight != 1.0:+ loss_att, acc_att, cer_att, wer_att, loss_pre = self._calc_att_loss(+ encoder_out, encoder_out_lens, text, text_lengths+ )+loss_pre2 = self._calc_pre2_loss(encoder_out, encoder_out_lens, text, text_lengths)- loss = loss_pre2+ # 3. CTC-Att loss definition+ if self.ctc_weight == 0.0:+ loss = loss_att + loss_pre * self.predictor_weight + loss_pre2 * self.predictor_weight * 0.5+ elif self.ctc_weight == 1.0:+ loss = loss_ctc+ else:+ loss = self.ctc_weight * loss_ctc + (1 - self.ctc_weight) * loss_att + loss_pre * self.predictor_weight + loss_pre2 * self.predictor_weight * 0.5+ # Collect Attn branch stats+ stats["loss_att"] = loss_att.detach() if loss_att is not None else None+ stats["acc"] = acc_att+ stats["cer"] = cer_att+ stats["wer"] = wer_att+ stats["loss_pre"] = loss_pre.detach().cpu() if loss_pre is not None else Nonestats["loss_pre2"] = loss_pre2.detach().cpu()+stats["loss"] = torch.clone(loss.detach())# force_gatherable: to-device and to-tensor if scalar for DataParallel