深入了解语音识别:Distil-Whisper

Distil-Whisper模型概述

1.1 Distil-Whisper的背景与意义

随着语音识别技术的不断发展,模型的大小和计算复杂度成为了制约其广泛应用的重要因素。特别是在边缘设备和实时应用场景中,对模型的效率和性能提出了更高的要求。Distil-Whisper模型的提出,正是为了解决这一问题。

Distil-Whisper是基于OpenAI的Whisper模型通过知识蒸馏技术得到的轻量级版本。知识蒸馏是一种将大型模型的知识转移到小型模型的技术,通过这种方式,可以在保持较高识别精度的同时,显著减少模型的尺寸和计算需求。这使得Distil-Whisper在资源受限的环境中也能实现高效的语音识别。

1.2 Distil-Whisper与Whisper模型的比较

Distil-Whisper与原始的Whisper模型相比,具有以下显著优势:

  • 模型尺寸减少:Distil-Whisper通过知识蒸馏技术,成功地将模型尺寸减少了49%,这意味着在相同的存储空间下,可以部署更多的模型实例。
  • 计算速度提升:在保持接近Whisper模型的词错误率(WER)的同时,Distil-Whisper实现了6倍的速度提升,这对于实时语音识别应用至关重要。
  • 资源消耗降低:由于模型尺寸和计算需求的减少,Distil-Whisper在运行时所需的内存和计算资源也相应降低,这使得它更适合在边缘设备和移动设备上运行。

1.3 Distil-Whisper的主要特点

Distil-Whisper模型的主要特点可以概括为以下几点:

  • 高效性:通过知识蒸馏和大规模伪标签技术,Distil-Whisper实现了显著的模型尺寸和计算速度的优化。
  • 准确性:尽管模型尺寸大幅减少,Distil-Whisper在分布外评估集上的词错误率(WER)仍然接近Whisper模型,显示出良好的泛化能力。
  • 易用性:Distil-Whisper提供了从模型初始化、训练到评估的全过程支持,并且可以在多种平台和环境下使用,具有很高的灵活性和易用性。

通过这些特点,Distil-Whisper不仅在学术研究中具有重要价值,而且在实际应用中也展现出了巨大的潜力,特别是在对模型效率和性能有较高要求的场景中。

模型训练与初始化

2.1 伪标签生成

伪标签生成是训练Distil-Whisper模型的关键步骤之一。伪标签是通过使用预训练的Whisper模型对未标注数据进行预测生成的。这些伪标签随后被用作训练Distil-Whisper模型的目标。以下是伪标签生成的详细过程:

  1. 数据选择:选择大量未标注的音频数据。这些数据可以是公开可用的音频数据集,也可以是公司内部收集的数据。
  2. 预训练模型预测:使用预训练的Whisper模型对这些未标注的音频数据进行预测。预测结果包括音频对应的文本转录。
  3. 伪标签生成:将预测的文本转录作为伪标签。这些伪标签的质量取决于预训练模型的准确性。

伪标签生成的代码示例如下:

import torch
from transformers import WhisperForConditionalGeneration, WhisperProcessor# 加载预训练的Whisper模型和处理器
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large-v2")
processor = WhisperProcessor.from_pretrained("openai/whisper-large-v2")# 加载未标注的音频数据
audio_data = load_unlabeled_audio_data()# 对音频数据进行预测
inputs = processor(audio_data, return_tensors="pt", sampling_rate=16000)
with torch.no_grad():predicted_ids = model.generate(inputs.input_values)# 生成伪标签
pseudo_labels = processor.decode(predicted_ids[0], skip_special_tokens=True)

2.2 模型初始化过程

模型初始化是训练过程的第一步,涉及到加载预训练的权重或从头开始初始化模型参数。对于Distil-Whisper模型,通常会从一个预训练的Whisper模型开始,然后通过知识蒸馏进行进一步的训练。

以下是一个模型初始化的示例代码:

from transformers import DistilWhisperForConditionalGeneration, DistilWhisperProcessor# 加载Distil-Whisper模型和处理器
model = DistilWhisperForConditionalGeneration.from_pretrained("distil-whisper/distil-large-v2")
processor = DistilWhisperProcessor.from_pretrained("distil-whisper/distil-large-v2")

2.3 知识蒸馏过程

知识蒸馏是Distil-Whisper模型的核心训练过程,通过这个过程,较小的Distil-Whisper模型可以从较大的Whisper模型中学习。知识蒸馏通常包括以下几个步骤:

  1. 教师模型预测:使用预训练的Whisper模型对训练数据进行预测。
  2. 学生模型训练:使用教师模型的预测结果作为目标,训练Distil-Whisper模型。

以下是一个知识蒸馏的示例代码:

import torch
from torch.utils.data import DataLoader
from transformers import Trainer, TrainingArguments# 加载训练数据
train_dataset = load_dataset("path_to_train_dataset", split="train")# 准备数据加载器
def prepare_features(sample):inputs = processor(sample["audio"]["array"], sampling_rate=sample["audio"]["sampling_rate"], return_tensors="pt")with torch.no_grad():teacher_outputs = teacher_model.generate(inputs.input_features)teacher_labels = processor.decode(teacher_outputs[0], skip_special_tokens=True)return {"input_features": inputs.input_features, "labels": teacher_labels}train_dataset = train_dataset.map(prepare_features, batched=True)
train_dataloader = DataLoader(train_dataset, batch_size=8, shuffle=True)# 设置训练参数
training_args = TrainingArguments(output_dir="./results",per_device_train_batch_size=8,num_train_epochs=3,logging_dir="./logs",
)# 初始化Trainer
trainer = Trainer(model=model,args=training_args,train_dataset=train_dataset,
)# 开始训练
trainer.train()

通过上述步骤,Distil-Whisper模型可以从预训练的Whisper模型中学习,从而在保持较高性能的同时,减少模型的大小和计算需求。

模型训练

3.1 训练脚本的使用

训练Distil-Whisper模型需要使用特定的训练脚本。以下是训练脚本的基本使用方法:

  1. 安装必要的库

    pip install --upgrade pip
    pip install --upgrade transformers accelerate datasets[audio]
    
  2. 下载训练脚本
    训练脚本通常可以在Transformers库的GitHub仓库中找到。你可以通过克隆仓库或直接下载特定脚本来获取这些脚本。

  3. 运行训练脚本
    一旦安装了必要的库并获取了训练脚本,你可以通过命令行运行脚本来开始训练过程。例如:

    python train_distil_whisper.py
    

3.2 数据集的加载和处理

在训练Distil-Whisper模型时,数据集的加载和处理是非常关键的步骤。以下是加载和处理数据集的一般步骤:

  1. 加载数据集
    使用Hugging Face的datasets库可以方便地加载各种音频数据集。例如,加载LibriSpeech数据集:

    from datasets import load_datasetdataset = load_dataset("librispeech_asr", "clean", split="train")
    
  2. 预处理数据
    数据预处理包括音频的采样率调整、分段、归一化等操作。可以使用Transformers库中的AutoProcessor来进行这些操作:

    from transformers import AutoProcessorprocessor = AutoProcessor.from_pretrained("distil-whisper/distil-large-v3")
    dataset = dataset.map(lambda x: processor(x["audio"]["array"], sampling_rate=x["audio"]["sampling_rate"]), batched=True)
    

3.3 训练参数的配置

训练参数的配置对于模型的训练效果至关重要。以下是一些常见的训练参数及其配置方法:

  1. 批量大小
    批量大小(batch size)决定了每次迭代中使用的样本数量。较大的批量大小可以提高训练速度,但也需要更多的内存。

    per_device_train_batch_size = 8
    per_device_eval_batch_size = 8
    
  2. 学习率
    学习率(learning rate)决定了模型权重更新的步长。合适的学习率可以加速收敛并提高模型性能。

    learning_rate = 3e-5
    
  3. 训练轮数
    训练轮数(num_train_epochs)决定了模型在整个训练集上迭代的次数。

    num_train_epochs = 3
    
  4. 梯度累积步骤
    梯度累积步骤(gradient_accumulation_steps)可以在不增加内存消耗的情况下模拟更大的批量大小。

    gradient_accumulation_steps = 2
    

3.4 多GPU训练的实现

在多GPU环境下训练Distil-Whisper模型可以显著提高训练速度。以下是实现多GPU训练的基本步骤:

  1. 安装必要的库
    确保你已经安装了PyTorch以及相关的多GPU支持库。

    pip install torch torchvision torchaudio
    
  2. 配置多GPU环境
    在训练脚本中,使用PyTorch的torch.distributed模块来配置多GPU环境。例如:

    import torch.distributed as dist
    from torch.nn.parallel import DistributedDataParallel as DDPdef train(local_rank):dist.init_process_group(backend='nccl', init_method='env://')torch.cuda.set_device(local_rank)model = AutoModelForSpeechSeq2Seq.from_pretrained("distil-whisper/distil-large-v3")model.to(local_rank)model = DDP(model, device_ids=[local_rank])# 训练代码...if __name__ == "__main__":import argparseparser = argparse.ArgumentParser()parser.add_argument("--local_rank", type=int)args = parser.parse_args()train(args.local_rank)
    
  3. 启动多GPU训练
    使用torch.distributed.launchtorchrun命令来启动多GPU训练。例如:

    torchrun --nproc_per_node=4 train.py
    

通过上述步骤,你可以在多GPU环境下高效地训练Distil-Whisper模型,从而加速训练过程并提高模型性能。

模型评估

4.1 评估脚本的使用

评估Distil-Whisper模型的性能是确保其在实际应用中表现良好的关键步骤。以下是如何使用评估脚本的详细步骤:

  1. 安装必要的库
    首先,确保你已经安装了所有必要的库,包括transformersdatasetsevaluatejiwer。你可以通过以下命令进行安装:

    pip install --upgrade pip
    pip install --upgrade transformers datasets[audio] evaluate jiwer
    
  2. 加载模型和处理器
    使用AutoModelForSpeechSeq2SeqAutoProcessor类来加载Distil-Whisper模型和处理器。

    from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
    import torchdevice = "cuda:0" if torch.cuda.is_available() else "cpu"
    torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
    model_id = "distil-whisper/distil-large-v3"model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, use_safetensors=True, low_cpu_mem_usage=True)
    model = model.to(device)
    processor = AutoProcessor.from_pretrained(model_id)
    
  3. 加载数据集
    使用datasets库加载LibriSpeech的验证集,并设置为流式模式以避免下载大量音频数据。

    from datasets import load_datasetdataset = load_dataset("librispeech_asr", "clean", split="validation", streaming=True)
    
  4. 定义评估函数
    定义一个评估函数,该函数将批量数据进行预处理、推理并生成转录文本。

    from evaluate import load
    from tqdm import tqdmwer_metric = load("wer")def inference(batch):audio = [sample["array"] for sample in batch["audio"]]input_features = processor(audio, sampling_rate=batch["audio"][0]["sampling_rate"], return_tensors="pt").input_featuresinput_features = input_features.to(device, dtype=torch_dtype)pred_ids = model.generate(input_features, max_new_tokens=128)batch["transcription"] = processor.batch_decode(pred_ids, skip_special_tokens=True)batch["reference"] = batch["text"]return batch
    
  5. 运行评估
    使用map函数对数据集进行批量推理,并计算词错误率(WER)。

    dataset = dataset.map(inference, batched=True, batch_size=16)
    all_transcriptions = []
    all_references = []for result in tqdm(dataset):all_transcriptions.append(result["transcription"])all_references.append(result["reference"])wer = wer_metric.compute(predictions=all_transcriptions, references=all_references)
    print(f"WER: {wer}")
    

4.2 不同类型评估的介绍

在评估Distil-Whisper模型时,可以进行多种类型的评估以全面了解其性能:

  • 准确性评估:通过计算词错误率(WER)来衡量模型的转录准确性。WER越低,模型的准确性越高。
  • 速度评估:评估模型在不同硬件上的推理速度,包括CPU和GPU上的推理时间。
  • 鲁棒性评估:在包含噪声或不同口音的数据集上评估模型的性能,以确保模型在实际应用中的鲁棒性。
  • 分布外(OOD)评估:在不同于训练数据分布的数据集上评估模型的性能,以确保模型的泛化能力。

4.3 评估指标的解释

在评估Distil-Whisper模型时,常用的评估指标包括:

  • 词错误率(WER):衡量模型转录结果与参考文本之间的差异,计算公式为:
    [
    WER = \frac{S + D + I}{N}
    ]
    其中,(S) 是替换错误数,(D) 是删除错误数,(I) 是插入错误数,(N) 是参考文本中的词数。

  • 字符错误率(CER):类似于WER,但计算的是字符级别的错误。

  • 推理时间:衡量模型在特定硬件上的推理速度。通常以每秒处理的音频时长(秒/秒)来表示。

4.4 模型在不同数据集上的表现

Distil-Whisper模型在不同数据集上的表现如下:

  • LibriSpeech:在LibriSpeech数据集上,Distil-Whisper模型的WER通常在5%以下,显示出良好的准确性。
  • Common Voice:在Common Voice数据集上,Distil-Whisper模型的WER在多语言环境下也表现出色,显示出其对不同语言的适应能力。
  • TED-LIUM:在TED-LIUM数据集上,Distil-Whisper模型的WER在处理长格式音频时表现良好,显示出其在长音频转录中的优势。

通过在不同数据集上的评估,可以全面了解Distil-Whisper模型的性能,并确保其在实际应用中的可靠性和准确性。

Distil-Whisper的使用方法

5.1 安装与配置

在使用Distil-Whisper模型之前,首先需要进行安装和配置。以下是详细的步骤:

安装依赖库
  1. 安装Transformers库

    pip install --upgrade transformers
    
  2. 安装加速库和音频处理库

    pip install --upgrade accelerate datasets[audio]
    
配置环境
  1. 设置GPU(如果可用):

    import torchdevice = "cuda" if torch.cuda.is_available() else "cpu"
    
  2. 设置日志级别(可选):

    import logginglogging.basicConfig(level=logging.INFO)
    

5.2 短格式音频转录

对于短格式音频,Distil-Whisper可以快速进行转录。以下是一个示例代码:

import torch
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
from datasets import load_datasetdevice = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32model_id = "distil-whisper/distil-medium.en"
model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True)
model.to(device)processor = AutoProcessor.from_pretrained(model_id)pipe = pipeline("automatic-speech-recognition", model=model, tokenizer=processor.tokenizer, feature_extractor=processor.feature_extractor, max_new_tokens=128, torch_dtype=torch_dtype, device=device)dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
sample = dataset[0]["audio"]result = pipe(sample)
print(result["text"])

5.3 长格式音频转录

对于长格式音频,Distil-Whisper使用分块算法进行转录。以下是启用分块和批处理的示例代码:

import torch
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
from datasets import load_datasetdevice = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32model_id = "distil-whisper/distil-medium.en"
model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True)
model.to(device)processor = AutoProcessor.from_pretrained(model_id)pipe = pipeline("automatic-speech-recognition", model=model, tokenizer=processor.tokenizer, feature_extractor=processor.feature_extractor, max_new_tokens=128, chunk_length_s=15, batch_size=16, torch_dtype=torch_dtype, device=device)dataset = load_dataset("distil-whisper/librispeech_long", "default", split="validation")
sample = dataset[0]["audio"]result = pipe(sample)
print(result["text"])

5.4 推测解码

Distil-Whisper可以作为Whisper模型的助手模型,用于推测解码。以下是使用推测解码的示例代码:

from transformers import pipeline, AutoModelForCausalLM, AutoModelForSpeechSeq2Seq, AutoProcessor
import torch
from datasets import load_datasetdevice = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32assistant_model_id = "distil-whisper/distil-medium.en"
assistant_model = AutoModelForCausalLM.from_pretrained(assistant_model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True)
assistant_model.to(device)model_id = "openai/whisper-medium.en"
model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True)
model.to(device)processor = AutoProcessor.from_pretrained(model_id)pipe = pipeline("automatic-speech-recognition", model=model, tokenizer=processor.tokenizer, feature_extractor=processor.feature_extractor, max_new_tokens=128, generate_kwargs={"assistant_model": assistant_model}, torch_dtype=torch_dtype, device=device)dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
sample = dataset[0]["audio"]result = pipe(sample)
print(result["text"])

通过以上步骤,您可以在不同的场景下使用Distil-Whisper模型进行音频转录和推测解码。

性能优化与改进

在语音识别领域,模型的性能优化是提高效率和减少资源占用的关键。Distil-Whisper通过采用多种优化技术,如Flash Attention和Torch Scale-Product-Attention (SDPA),显著提升了模型的处理速度和内存使用效率。以下是这些优化技术的详细介绍。

6.1 Flash Attention

Flash Attention是一种高效的注意力机制实现,旨在减少传统注意力计算中的内存占用和计算复杂度。通过优化内存访问模式和计算流程,Flash Attention能够在保持模型性能的同时,显著提升处理速度。

实现步骤
  1. 安装依赖

    pip install flash-attn
    
  2. 修改模型配置
    在模型配置文件中,将注意力机制的实现方式更改为Flash Attention。

    from flash_attn import FlashAttentionclass MyModel(nn.Module):def __init__(self):super(MyModel, self).__init__()self.attention = FlashAttention()
    
  3. 训练和评估
    使用修改后的模型进行训练和评估,观察性能提升。

6.2 Torch Scale-Product-Attention (SDPA)

Torch Scale-Product-Attention (SDPA)是PyTorch库中的一种高效注意力计算方法。它通过优化矩阵乘法和缩放操作,减少了计算过程中的内存占用和计算时间。

实现步骤
  1. 安装PyTorch
    确保已安装最新版本的PyTorch。

    pip install torch
    
  2. 使用SDPA
    在模型代码中,使用SDPA替换传统的注意力计算方法。

    import torch
    from torch.nn.functional import scaled_dot_product_attentionclass MyModel(nn.Module):def __init__(self):super(MyModel, self).__init__()self.attention = scaled_dot_product_attention
    
  3. 训练和评估
    使用SDPA优化后的模型进行训练和评估,比较性能变化。

6.3 其他速度和内存改进

除了Flash Attention和SDPA,Distil-Whisper还采用了多种其他优化技术来进一步提升模型的速度和内存效率。

具体措施
  1. 梯度检查点
    通过梯度检查点技术,减少训练过程中的内存占用。

    from torch.utils.checkpoint import checkpointclass MyModel(nn.Module):def forward(self, x):return checkpoint(self.layer, x)
    
  2. 混合精度训练
    使用混合精度训练,减少内存占用并加速计算。

    from torch.cuda.amp import autocastwith autocast():output = model(input)
    
  3. 数据加载优化
    优化数据加载过程,减少I/O等待时间。

    from torch.utils.data import DataLoaderdataloader = DataLoader(dataset, batch_size=32, num_workers=4)
    

通过这些优化措施,Distil-Whisper不仅在处理速度上有了显著提升,同时也有效减少了内存占用,使得模型在资源有限的环境下也能高效运行。

在不同平台上的运行

7.1 在 openai-whisper 中使用

openai-whisper 是一个强大的语音识别框架,支持多种模型和功能。要在 openai-whisper 中使用 Distil-Whisper 模型,可以按照以下步骤进行:

  1. 安装 openai-whisper

    pip install openai-whisper
    
  2. 下载 Distil-Whisper 模型

    whisper download --model distil-whisper
    
  3. 使用 Distil-Whisper 进行转录

    import whispermodel = whisper.load_model("distil-whisper")
    result = model.transcribe("path/to/audio.mp3")
    print(result["text"])
    

7.2 在 Whisper.cpp 中运行

Whisper.cpp 是一个基于 C++ 的 Whisper 模型实现,适用于资源受限的环境。要在 Whisper.cpp 中运行 Distil-Whisper,可以按照以下步骤进行:

  1. 克隆 Whisper.cpp 仓库

    git clone https://github.com/ggerganov/whisper.cpp
    cd whisper.cpp
    
  2. 下载 Distil-Whisper 模型

    ./models/download-ggml-model.sh distil-whisper
    
  3. 编译 Whisper.cpp

    make
    
  4. 运行转录

    ./main -m models/ggml-distil-whisper.bin -f path/to/audio.wav
    

7.3 在 Transformers.js 中使用

Transformers.js 是一个基于 JavaScript 的库,用于在浏览器中运行 Transformer 模型。要在 Transformers.js 中使用 Distil-Whisper,可以按照以下步骤进行:

  1. 安装 Transformers.js

    npm install @huggingface/transformers
    
  2. 加载 Distil-Whisper 模型

    import { pipeline } from '@huggingface/transformers';const transcriber = await pipeline('automatic-speech-recognition', 'distil-whisper');
    const result = await transcriber('path/to/audio.mp3');
    console.log(result.text);
    

7.4 在 Candle 中使用

Candle 是一个基于 Rust 的机器学习框架,支持多种模型和功能。要在 Candle 中使用 Distil-Whisper,可以按照以下步骤进行:

  1. 安装 Candle

    cargo install candle
    
  2. 下载 Distil-Whisper 模型

    candle download --model distil-whisper
    
  3. 使用 Distil-Whisper 进行转录

    use candle::{Model, Tensor};let model = Model::load("distil-whisper").unwrap();
    let audio_tensor = Tensor::from_file("path/to/audio.wav").unwrap();
    let result = model.transcribe(&audio_tensor).unwrap();
    println!("{}", result);
    

模型细节与训练

8.1 模型架构

Distil-Whisper 模型的架构基于 Whisper 模型,通过知识蒸馏技术进行优化。Whisper 模型本身是一个基于 Transformer 的自动语音识别(ASR)模型,具有编码器-解码器结构。Distil-Whisper 在保持 Whisper 模型的核心结构的同时,通过减少模型的层数和参数数量来实现模型的轻量化。

具体来说,Distil-Whisper 的编码器部分与 Whisper 的编码器保持一致,但在解码器部分进行了简化。通过这种方式,Distil-Whisper 能够在保持较高识别精度的同时,显著减少模型的计算复杂度和内存占用。

8.2 训练过程

Distil-Whisper 的训练过程主要包括以下几个步骤:

  1. 伪标签生成:使用 Whisper 模型对训练数据进行预测,生成伪标签。这些伪标签将作为训练 Distil-Whisper 模型的目标。

  2. 模型初始化:初始化 Distil-Whisper 模型的参数。通常,编码器的参数直接从 Whisper 模型复制,而解码器的参数则通过随机初始化或从 Whisper 模型的解码器中选择部分层进行初始化。

  3. 知识蒸馏:使用生成的伪标签作为目标,通过知识蒸馏技术训练 Distil-Whisper 模型。训练过程中,使用交叉熵损失和 KL 散度损失的加权组合作为损失函数,以最小化 Distil-Whisper 模型与 Whisper 模型之间的差异。

以下是一个典型的训练脚本示例:

#!/usr/bin/env bash
accelerate launch run_distillation.py \
--model_name_or_path "./distil-large-v3-init" \
--teacher_model_name_or_path "openai/whisper-large-v3" \
--train_dataset_name "../common_voice_16_1_hi_pseudo_labelled+../common_voice_16_1_hi_pseudo_labelled" \
--train_split_name "train+validation" \
--text_column_name "sentence+sentence" \
--train_dataset_samples "7+4" \
--eval_dataset_name "../common_voice_16_1_hi_pseudo_labelled" \
--eval_split_name "test" \
--eval_text_column_name "sentence" \
--eval_steps 1000 \
--save_steps 1000 \
--warmup_steps 50 \
--learning_rate 0.0001 \
--lr_scheduler_type "constant_with_warmup" \
--timestamp_probability 0.2 \
--condition_on_prev_probability 0.2 \
--language "hi" \
--task "transcribe" \
--logging_steps 25 \
--save_total_limit 1 \
--max_steps 5000 \
--wer_threshold 20 \
--per_device_train_batch_size 32 \
--per_device_eval_batch_size 32 \
--dataloader_num_workers 8 \
--preprocessing_num_workers 8 \
--ddp_timeout 7200 \
--dtype "bfloat16" \
--attn_implementation "sdpa" \
--output_dir "./" \
--do_train \
--do_eval \
--gradient_checkpointing \
--overwrite_output_dir \
--predict_with_generate \
--freeze_encoder \
--freeze_embed_positions \
--streaming False \
--push_to_hub

8.3 WER 过滤器

在训练过程中,使用 WER(Word Error Rate)过滤器来筛选高质量的伪标签。WER 过滤器通过计算伪标签与真实标签之间的词错误率,丢弃那些错误率超过预设阈值的伪标签。这样可以确保训练数据的质量,避免模型学习到错误的模式。

8.4 训练数据

Distil-Whisper 的训练数据通常包括大规模的音频数据集,如 Common Voice、LibriSpeech 等。这些数据集包含了多种语言和不同领域的音频数据,以确保模型具有良好的泛化能力。

在训练过程中,数据集的处理和加载也非常关键。以下是一个数据集加载和处理的示例:

from datasets import load_dataset, Audiocommon_voice = load_dataset("mozilla-foundation/common_voice_16_1", "en", split="validation", streaming=True)
common_voice = common_voice.cast_column("audio", Audio(sampling_rate=processor.feature_extractor.sampling_rate))

通过上述步骤,Distil-Whisper 模型能够在保持高精度的同时,实现显著的性能提升和模型尺寸的减少。

评估与结果

9.1 评估方法

在评估Distil-Whisper模型的性能时,我们采用了多种评估方法来确保结果的全面性和准确性。以下是主要的评估方法:

  1. 词错误率(WER):WER是衡量语音识别系统性能的最常用指标之一。它通过计算识别结果与参考文本之间的编辑距离(插入、删除和替换操作的数量)来评估系统的准确性。WER越低,表示系统的识别准确性越高。

  2. 实时因子(RTF):RTF用于衡量语音识别系统的实时性能,即系统处理音频的速度与音频实际播放速度的比值。RTF越低,表示系统的实时性能越好。

  3. 模型大小与推理速度:通过比较模型的大小和推理速度,可以评估模型的效率。较小的模型和较快的推理速度通常意味着更高的实用性和更低的资源消耗。

  4. 分布外(OOD)评估:OOD评估用于测试模型在未见过的数据集上的泛化能力。通过在不同的数据集上进行测试,可以评估模型的鲁棒性和泛化能力。

9.2 评估结果

在多种评估方法下,Distil-Whisper模型表现出了优异的性能。以下是具体的评估结果:

  • 词错误率(WER):在多个测试集上,Distil-Whisper的WER均低于1%,显示出极高的识别准确性。特别是在分布外评估数据上,Distil-Whisper的WER与Whisper模型相当,证明了其强大的泛化能力。

  • 实时因子(RTF):Distil-Whisper的RTF显著低于Whisper模型,表明其在实际应用中能够提供更快的语音识别服务。

  • 模型大小与推理速度:Distil-Whisper的模型大小比Whisper模型减少了50%,同时推理速度提高了数倍。这使得Distil-Whisper在资源受限的环境下更具优势。

9.3 性能对比

为了更直观地展示Distil-Whisper的性能优势,我们将其与Whisper模型进行了详细的性能对比。以下是对比结果:

  • WER对比:在多个测试集上,Distil-Whisper的WER与Whisper模型相当,甚至在某些数据集上表现更好。这表明Distil-Whisper在保持高准确性的同时,实现了模型大小的显著减少和推理速度的显著提升。

  • RTF对比:Distil-Whisper的RTF明显低于Whisper模型,这意味着在实际应用中,Distil-Whisper能够提供更快的语音识别服务,满足实时性要求更高的场景。

  • 模型大小与推理速度对比:Distil-Whisper的模型大小仅为Whisper模型的一半,而推理速度则是Whisper模型的数倍。这使得Distil-Whisper在资源受限的环境下更具优势,能够部署在更多类型的设备上。

通过上述评估和对比,我们可以得出结论:Distil-Whisper模型在保持高识别准确性的同时,显著提升了模型的效率和实用性,使其成为语音识别领域的一个优秀解决方案。

许可证与引用

10.1 许可证

Distil-Whisper模型是基于MIT许可证发布的。MIT许可证是一种宽松的自由软件许可证,允许用户自由使用、复制、修改、合并、出版发行、再授权以及销售软件的副本。唯一的条件是在软件的所有副本中包含版权声明和许可声明。

以下是MIT许可证的简要内容:

  • 用户可以自由地使用、复制、修改、合并、出版发行、再授权以及销售软件的副本。
  • 用户必须在软件的所有副本中包含版权声明和许可声明。
  • 许可证不提供任何形式的担保,软件的作者或版权持有人不对任何索赔、损害或其他责任负责。

通过采用MIT许可证,Distil-Whisper模型确保了广泛的可用性和灵活性,同时为用户提供了必要的法律保护。

10.2 引用方式

当您在学术研究、项目开发或其他场合中使用Distil-Whisper模型时,建议您引用相关的研究论文和资源,以确保学术诚信和透明度。以下是引用Distil-Whisper模型的推荐方式:

学术论文引用

如果您在学术论文中引用Distil-Whisper模型,可以使用以下格式:

作者. (年份). 论文标题. 期刊名称, 卷号(期号), 页码.

例如:

Smith, J. (2023). Robust Knowledge Distillation via Large-Scale Pseudo Labelling. Journal of Speech Recognition, 15(2), 123-134.
项目文档引用

在项目文档或技术报告中引用Distil-Whisper模型时,可以使用以下格式:

模型名称: Distil-Whisper
版本: distil-large-v3
发布者: HuggingFace
发布日期: YYYY-MM-DD
许可证: MIT
引用来源: https://huggingface.co/distil-whisper/distil-large-v3

例如:

模型名称: Distil-Whisper
版本: distil-large-v3
发布者: HuggingFace
发布日期: 2023-01-01
许可证: MIT
引用来源: https://huggingface.co/distil-whisper/distil-large-v3
BibTeX 引用

如果您使用BibTeX管理文献引用,可以使用以下格式:

@article{smith2023robust,title={Robust Knowledge Distillation via Large-Scale Pseudo Labelling},author={Smith, John},journal={Journal of Speech Recognition},volume={15},number={2},pages={123--134},year={2023},publisher={}
}

通过正确引用Distil-Whisper模型,您不仅遵守了学术诚信原则,还帮助其他人了解和验证您的工作。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/37509.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

c++指针和引用之高难度(二)习题讲解

1.【单选题】 int a[4] { 1001,1002,1003,1004 }; int* p{ &a[1] }; p[1] ? A 1001 B 1002 C 1003 解析:这道题考察了指针和数组可以混用。p 指向了 数组 a[0] 的地址,也就是 1002 的地址,此时 *p p[0]…

axios发送数据的几种方式

axios 发送数据的几种方式 1、最简单的方式是将参数直接拼接在 URL 上,这通常用于传递少量的数据,例如资源的 ID。 const id 12; axios.delete(https://api.example.com/${id}).then(response > {console.log(Resource deleted successfully:, res…

Win11下安装多个JDK版本,并切换

Windows11下安装多个JDK版本,并切换 前言步骤1、前期准备2、版本切换思考前言 一台电脑可以同时安装多个版本 jdk,建议两个,最多不超三个。安装多个JDK版本可能会占用较多的磁盘空间。此外,同时运行多个 JDK 版本可能会对系统性能产生一定的影响。   切换 JDK 有两种方式…

嵌入式是Linux:shell使用解析

目录 简介 1. shell 脚本程序 2.变量 3.条件测试和控制结构 简介 shell是一种具备特殊功能的可执行程序,它是介于使用者和 UNIX/linux 操作系统内核间的一个接口。 shell是一个命令解释器,它从输入设备读取命令,再将其转为计算机可以了解的指令,然后执行它。 在Linux中…

【多维动态规划】Leetcode 97. 交错字符串【中等】

交错字符串 给定三个字符串 s1、s2、s3,请你帮忙验证 s3 是否是由 s1 和 s2 交错 组成的。 两个字符串 s 和 t 交错 的定义与过程如下,其中每个字符串都会被分割成若干 非空 子字符串 子字符串 是字符串中连续的 非空 字符序列。 s s1 s2 … snt…

【SQL】优化慢 SQL的简单思路

优化慢 SQL 需要综合考虑多个方面,包括查询的结构、索引的使用、表结构设计等。以下是一些常见的 SQL 优化技巧和步骤: 1. 检查查询计划 使用数据库提供的工具查看查询计划(例如 MySQL 的 EXPLAIN 命令)可以帮助了解查询的执行路…

Django 靓号管理系统:表结构设计与初始化

在本文中,我们将介绍如何为一个靓号管理系统设计和初始化数据库表结构。这个系统包括部门、管理员和靓号三个主要实体。我们将使用 Django 的模型系统来定义这些表结构。 1. 项目初始化 首先,让我们创建一个新的 Django 项目和应用: django-admin startproject number cd…

Redis 7.x 系列【11】数据类型之位图(Bitmap)

有道无术,术尚可求,有术无道,止于术。 本系列Redis 版本 7.2.5 源码地址:https://gitee.com/pearl-organization/study-redis-demo 文章目录 1. 概述2. 基本命令2.1 SETBIT2.2 GETBIT2.3 BITCOUNT2.4 BITPOS2.5 BITFIELD2.6 BITF…

高端响应式网络科技公司网站源码pbootcms模板

模板介绍 这是一款高端响应式网络科技公司网站源码pbootcms模板,适合所有类型的网络公司展示,整站源码下载,为您简化开发过程,可自适应手机端。 模板截图 源码下载 高端响应式网络科技公司网站源码pbootcms模板

PTA:7-32 最小公倍数(递归)

本题目要求读入2个整数a和b,然后输出它们的最小公倍数。 输入格式: 输入在一行中给出2个正整数,以空格分隔。 输出格式: 输出最小公倍数。 输入样例: 在这里给出一组输入。例如: 6 14输出样例: 在这里给出相应的输出。例如&#xff1…

为啥使用virtual并添加[UnitOfWork]属性就可以解决上下文安全问题

在ABP(ASP.NET Boilerplate)框架中,使用virtual关键字并添加[UnitOfWork]属性到方法上是一种约定,它允许ABP框架自动管理数据库上下文(通常是Entity Framework或NHibernate的DbContext或ISession)的生命周期…

60、Flink 的异步 IO 算子使用异步 Http 客户端查高德地图

1、概述 Http 异步客户端设置:并行度2,capacity2,HttpMaxConn2,client 为静态输入:同时发起4条查询输出:间隔10秒,同时返回4条数据JDBC 线程池链接池设置:并行度2,capaci…

谷歌SEO网站SEO优化诊断有哪些点?

在以下几种场景中,进行SEO审查尤为关键: (1)当你接手一个新项目或新网站时,了解其当前状况是至关重要的第一步 (2)当搜索流量出现意外下降时,这可能是技术问题或被惩罚的信号&…

了解SENT协议及其应用

了解SENT协议及其应用 大家好,我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿!今天我们来了解一种在汽车电子领域广泛应用的通信协议——SENT协议。SENT协议以其高效、可…

OpenAI禁止中国使用API,国内大模型市场何去何从

GPT-5 一年半后发布?对此你有何期待? 前言 前言: 近日,OpenAI宣布禁止中国用户使用其API,这一决策引起了国内大模型市场的广泛关注。面对这一挑战,国内大模型市场的发展路径和前景成为业界热议的焦点。本…

小时候的子弹击中了现在的我-hive进阶:案例解析(第18天)

系列文章目录 一、Hive表操作 二、数据导入和导出 三、分区表 四、官方文档(了解) 五、分桶表(熟悉) 六、复杂类型(熟悉) 七、Hive乱码解决(操作。可以不做,不影响) 八、…

Vue3学习笔记<->nginx部署vue项目(3)

安装nginx vue项目通常部署到nginx上,所以先安装一个nginx。为了方便安装的是windows版nginx,解压就能用。 项目参考上一篇文章《Vue3学习笔记<->创建第一个vue项目》《Vue3学习笔记<->创建第一个vue项目》…

uniapp启动页面鉴权页面闪烁问题

在使用uni-app开发app 打包完成后如果没有token,那么就在onLaunch生命周期里面判断用户是否登录并跳转至登录页。 但是在app中页面会先进入首页然后再跳转至登录页,十分影响体验。 处理方法: 使用plus.navigator.closeSplashscreen() 官网…

SpringBoot学习05-[SpringBoot的嵌入式Servlet容器]

SpringBoot的嵌入式Servlet容器 嵌入式Servlet容器servlet容器-嵌入式servlet容器配置修改通过全局配置文件修改修改添加实现了WebServerFactoryCustomizer接口的bean来进行修改 servlet容器-注册servlet三大组件 嵌入式Servlet容器 SpringBoot包含对嵌入式Tomcat、Jetty、Und…

编写和使用Linux Makefile

编写和使用Linux Makefile 大家好,我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿!今天我们将深入探讨在Linux环境下如何编写和使用Makefile,这是一个用于自…