精炼的Whisper模型可以作为OpenAI Whisper的替代品吗?
我有一个可以正常工作的录像转录流程,使用的是本地的OpenAI Whisper模型。我想用一个相应的精简模型(“distil-small.en”),这个模型更小,运行得更快。
transcribe(self):
file = "/path/to/video"
model = whisper.load_model("small.en") # WORKS
model = whisper.load_model("distil-small.en") # DOES NOT WORK
transcript = model.transcribe(word_timestamps=True, audio=file)
print(transcript["text"])
但是,我遇到了一个错误,提示找不到这个模型:
RuntimeError: Model distil-small.en not found; available models = ['tiny.en', 'tiny', 'base.en', 'base', 'small.en', 'small', 'medium.en', 'medium', 'large-v1', 'large-v2', 'large-v3', 'large']
我在Poetry中安装了我的依赖(其实它底层是用pip的),具体步骤如下:
[tool.poetry.dependencies]
python = "^3.11"
openai-whisper = "*"
transformers = "*" # distilled whisper models
accelerate = "*" # distilled whisper models
datasets = { version = "*", extras = ["audio"] } # distilled whisper models
在GitHub Distilled Whisper的文档中,似乎使用了不同的方法来安装和使用这些模型。
请问可以把精简模型直接替换成普通的Whisper模型吗?
1 个回答
1
使用带有字符串参数的 load_model
只适用于OpenAI已知的模型列表。如果你想使用自己的模型,首先需要从huggingface网站或其他地方下载它。
可以参考这个链接: https://huggingface.co/distil-whisper/distil-small.en#running-whisper-in-openai-whisper
import torch
from datasets import load_dataset
from huggingface_hub import hf_hub_download
from whisper import load_model, transcribe
distil_small_en = hf_hub_download(repo_id="distil-whisper/distil-small.en", filename="original-model.bin")
model = load_model(distil_small_en)
dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
sample = dataset[0]["audio"]["array"]
sample = torch.from_numpy(sample).float()
pred_out = transcribe(model, audio=sample)
print(pred_out["text"])
你还可以查看 OpenAI是如何检查load_model
的字符串参数,它只会检查已知的模型(这在你展示的错误中也有提到)。