Zum Inhalt springen
ModelAufgelistetExtern
Herunterladen

Whisper Base ONNX

> This is a Transformers.js-ready ONNX conversion of the original Hugging Face model openai/whisper-base. > The original model card content follows below.

ArtText modelVersionBBewertung

Modellquelle

Art
Text model
Dateigröße
217 MB
Version
vdecoder_model_merged
Aktualisiert
31. Okt. 2026
Downloads
12
Quelle
Hugging Face

Quellenbeschreibung

This is a Transformers.js-ready ONNX conversion of the original Hugging Face model openai/whisper-base. The original model card content follows below.

Optimized for Transformers.js WebGPU: The fp32 graph reduced returned encoder data for a 30-second input from 414.9 MiB to 2.9 MiB and reduced the hot cached-decoder branch from 1,295 to 164 nodes. On an Apple M3 Max with Transformers.js 4.2.0, median transcription time improved from 1275.6 ms to 612.1 ms (2.08x faster) with an identical transcript and identical segment timestamps. Segment timestamps remain supported, but return_token_timestamps is not supported because the unused decoder cross-attention outputs were removed. A later dispatch-optimization pass improved a local JFK benchmark from 497.5 ms to 406.6 ms (1.22x) with the same transcript.

Whisper

Whisper is a pre-trained model for automatic speech recognition (ASR) and speech translation. Trained on 680k hours of labelled data, Whisper models demonstrate a strong ability to generalise to many datasets and domains without the need for fine-tuning.

Whisper was proposed in the paper Robust Speech Recognition via Large-Scale Weak Supervision by Alec Radford et al from OpenAI. The original code repository can be found here.

Disclaimer: Content for this model card has partly been written by the Hugging Face team, and parts of it were copied and pasted from the original model card.

Model details

Whisper is a Transformer based encoder-decoder model, also referred to as a sequence-to-sequence model. It was trained on 680k hours of labelled speech data annotated using large-scale weak supervision.

The models were trained on either English-only data or multilingual data. The English-only models were trained on the task of speech recognition. The multilingual models were trained on both speech recognition and speech translation. For speech recognition, the model predicts transcriptions in the same language as the audio. For speech translation, the model predicts transcriptions to a different language to the audio.

Whisper checkpoints come in five configurations of varying model sizes. The smallest four are trained on either English-only or multilingual data. The largest checkpoints are multilingual only. All ten of the pre-trained checkpoints are available on the Hugging Face Hub. The checkpoints are summarised in the following table with links to the models on the Hub:

SizeParametersEnglish-onlyMultilingual
tiny39 M✓✓
base74 M✓✓
small244 M✓✓
medium769 M✓✓
large1550 Mx✓
large-v21550 Mx✓

Usage

To transcribe audio samples, the model has to be used alongside a WhisperProcessor.

The WhisperProcessor is used to:

  1. Pre-process the audio inputs (converting them to log-Mel spectrograms for the model)
  2. Post-process the model outputs (converting them from tokens to text)

The model is informed of which task to perform (transcription or translation) by passing the appropriate "context tokens". These context tokens are a sequence of tokens that are given to the decoder at the start of the decoding process, and take the following order:

  1. The transcription always starts with the <|startoftranscript|> token
  2. The second token is the language token (e.g. <|en|> for English)
  3. The third token is the "task token". It can take one of two values: <|transcribe|> for speech recognition or <|translate|> for speech translation
  4. In addition, a <|notimestamps|> token is added if the model should not include timestamp prediction

Thus, a typical sequence of context tokens might look as follows:

<|startoftranscript|> <|en|> <|transcribe|> <|notimestamps|>

Which tells the model to decode in English, under the task of speech recognition, and not to predict timestamps.

These tokens can either be forced or un-forced. If they are forced, the model is made to predict each token at each position. This allows one to control the output language and task for the Whisper model. If they are un-forced, the Whisper model will automatically predict the output langauge and task itself.

The context tokens can be set accordingly:

model.config.forced_decoder_ids = WhisperProcessor.get_decoder_prompt_ids(language="english", task="transcribe")

Which forces the model to predict in English under the task of speech recognition.

Transcription

English to English

In this example, the context tokens are 'unforced', meaning the model automatically predicts the output language (English) and task (transcribe).

>>> from transformers import WhisperProcessor, WhisperForConditionalGeneration
>>> from datasets import load_dataset

>>> # load model and processor
>>> processor = WhisperProcessor.from_pretrained("openai/whisper-base")
>>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-base")
>>> model.config.forced_decoder_ids = None

>>> # load dummy dataset and read audio files
>>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
>>> sample = ds[0]["audio"]
>>> input_features = processor(sample["array"], sampling_rate=sample["sampling_rate"], return_tensors="pt").input_features 

>>> # generate token ids
>>> predicted_ids = model.generate(input_features)
>>> # decode token ids to text
>>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=False)
['<|startoftranscript|><|en|><|transcribe|><|notimestamps|> Mr. Quilter is the apostle of the middle classes and we are glad to welcome his gospel.<|endoftext|>']

>>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
[' Mr. Quilter is the apostle of the middle classes and we are glad to welcome his gospel.']

The context tokens can be removed from the start of the transcription by setting skip_special_tokens=True.

French to French

The following example demonstrates French to French transcription by setting the decoder ids appropriately.

>>> from transformers import WhisperProcessor, WhisperForConditionalGeneration
>>> from datasets import Audio, load_dataset

>>> # load model and processor
>>> processor = WhisperProcessor.from_pretrained("openai/whisper-base")
>>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-base")
>>> forced_decoder_ids = processor.get_decoder_prompt_ids(language="french", task="transcribe")

>>> # load streaming dataset and read first audio sample
>>> ds = load_dataset("common_voice", "fr", split="test", streaming=True)
>>> ds = ds.cast_column("audio", Audio(sampling_rate=16_000))
>>> input_speech = next(iter(ds))["audio"]
>>> input_features = processor(input_speech["array"], sampling_rate=input_speech["sampling_rate"], return_tensors="pt").input_features

>>> # generate token ids
>>> predicted_ids = model.generate(input_features, forced_decoder_ids=forced_decoder_ids)
>>> # decode token ids to text
>>> transcription = processor.batch_decode(predicted_ids)
['<|startoftranscript|><|fr|><|transcribe|><|notimestamps|> Un vrai travail intéressant va enfin être mené sur ce sujet.<|endoftext|>']

>>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
[' Un vrai travail intéressant va enfin être mené sur ce sujet.']

Translation

Setting the task to "translate" forces the Whisper model to perform speech translation.

French to English

>>> from transformers import WhisperProcessor, WhisperForConditionalGeneration
>>> from datasets import Audio, load_dataset

>>> # load model and processor
>>> processor = WhisperProcessor.from_pretrained("openai/whisper-base")
>>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-base")
>>> forced_decoder_ids = processor.get_decoder_prompt_ids(language="french", task="translate")

>>> # load streaming dataset and read first audio sample
>>> ds = load_dataset("common_voice", "fr", split="test", streaming=True)
>>> ds = ds.cast_column("audio", Audio(sampling_rate=16_000))
>>> input_speech = next(iter(ds))["audio"]
>>> input_features = processor(input_speech["array"], sampling_rate=input_speech["sampling_rate"], return_tensors="pt").input_features

>>> # generate token ids
>>> predicted_ids = model.generate(input_features, forced_decoder_ids=forced_decoder_ids)
>>> # decode token ids to text
>>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
[' A very interesting work, we will finally be given on this subject.']

Evaluation

This code snippet shows how to evaluate Whisper Base on LibriSpeech test-clean:

>>> from datasets import load_dataset
>>> from transformers import WhisperForConditionalGeneration, WhisperProcessor
>>> import torch
>>> from evaluate import load

>>> librispeech_test_clean = load_dataset("librispeech_asr", "clean", split="test")

>>> processor = WhisperProcessor.from_pretrained("openai/whisper-base")
>>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-base").to("cuda")

>>> def map_to_pred(batch):
>>>     audio = batch["audio"]
>>>     input_features = processor(audio["array"], sampling_rate=audio["sampling_rate"], return_tensors="pt").input_features
>>>     batch["reference"] = processor.tokenizer._normalize(batch['text'])
>>> 
>>>     with torch.no_grad():
>>>         predicted_ids = model.generate(input_features.to("cuda"))[0]
>>>     transcription = processor.decode(predicted_ids)
>>>     batch["prediction"] = processor.tokenizer._normalize(transcription)
>>>     return batch

>>> result = librispeech_test_clean.map(map_to_pred)

>>> wer = load("wer")
>>> print(100 * wer.compute(references=result["reference"], predictions=result["prediction"]))
5.082316555716899

Long-Form Transcription

The Whisper model is intrinsically designed to work on audio samples of up to 30s in duration. However, by using a chunking algorithm, it can be used to transcribe audio samples of up to arbitrary length. This is possible through Transformers pipeline method. Chunking is enabled by setting chunk_length_s=30 when instantiating the pipeline. With chunking enabled, the pipeline can be run with batched inference. It can also be extended to predict sequence level timestamps by passing return_timestamps=True:

>>> import torch
>>> from transformers import pipeline
>>> from...

Quellen

1 Quelle
Hugging FacePrimärVersion 44c53681c73d74d3160ae23346ee82c5de51a6e9
huggingface.co/nico-martin/whisper-base-ONNX/tree/44c53681c73d74d3160ae23346ee82c5de51a6e9

Verifiziert 31. Okt.

Download files

Modellartefakte

1 Artefakt

onnx/decoder_model_merged.onnx

onnx · 217 MB · SHA-256 5f31d7adf3e6…c60b · Hugging Face

Download file

Quellenauszüge

3 Auszüge

--- license: apache-2.0 pipeline_tag: automatic-speech-recognition tags: - audio - automatic-speech-recognition - hf-asr-leaderboard - onnx - transformers.js - transformersjs - source:openai/whisper-base library_name: transformers.js --- > This is a Transformers.js-ready ONNX conversion of the original Hugging Face model [openai/whisper-base](https://huggingface.co/openai/whisper-base). > The original model card content follows below. > **Optimized for Transformers.js WebGPU:** The fp32 graph reduced returned encoder data for a 30-second input from 414.9 MiB to 2.9 MiB and reduced the hot cached-decoder branch from 1,295 to 164 nodes. On an Apple M3 Max with Transformers.js 4.2.0, median transcription time improved from 1275.6 ms to 612.1 ms (**2.08x faster**) with an identical transcript and identical segment timestamps. Segment timestamps remain supported, but `return_token_timestamps` is not supported because the unused decoder cross-attention outputs were removed. A later dispatch-optimization pass improved a local JFK benchmark from 497.5 ms to 406.6 ms (1.22x) with the same transcript. # Whisper Whisper is a pre-trained model for automatic speech recognition (ASR) and speech translation. Trained on 680k hours of labelled data, Whisper models demonstrate a strong ability to generalise to many datasets and domains **without** the need for fine-tuning. Whisper was proposed in the paper [Robust Speech Recognition via Large-Scale Weak Supervision](https://arxiv.org/abs/2212.04356) by Alec Radford et al from OpenAI. The original code repository can be found [here](https://github.com/openai/whisper). **Disclaimer**: Content for this model card has partly been written by the Hugging Face team, and parts of it were copied and pasted from the original model card. ## Model details Whisper is a Transformer based encoder-decoder model, also referred to as a _sequence-to-sequence_ model. It was trained on 680k hours of labelled speech data annotated using large-scale weak supervision. The models were trained on either English-only data or multilingual data. The English-only models were trained on the task of speech recognition. The multilingual models were trained on both speech recognition and speech translation. For speech recognition, the model predicts transcriptions in the *same* language as the audio. For speech translation, the model predicts tran...

Source context: 12 downloads · 1 likes · Pipeline automatic-speech-recognition · Library transformers.js · Repo nico-martin/whisper-base-ONNX

Source context: 18 downloads · 1 likes · Pipeline automatic-speech-recognition · Library transformers.js · Repo nico-martin/whisper-base-ONNX