Views
No views yet


pipeline class for audio transcription.chunk_length_s argument. This approach segments the audio into smaller segments, processes them in parallel, and then joins them at the strides by finding the longest common sequence. While this chunked long-form approach may have a slight compromise in performance compared to OpenAI's sequential algorithm, it provides 9x faster inference speed.1import torch
2from datasets import load_dataset
3from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
4
5device = "cuda:0" if torch.cuda.is_available() else "cpu"
6torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
7
8# Load model
9model_name_or_path = "bofenghuang/whisper-large-v3-french-distil-dec8"
10processor = AutoProcessor.from_pretrained(model_name_or_path)
11model = AutoModelForSpeechSeq2Seq.from_pretrained(
12 model_name_or_path,
13 torch_dtype=torch_dtype,
14 low_cpu_mem_usage=True,
15)
16model.to(device)
17
18# Init pipeline
19pipe = pipeline(
20 "automatic-speech-recognition",
21 model=model,
22 feature_extractor=processor.feature_extractor,
23 tokenizer=processor.tokenizer,
24 torch_dtype=torch_dtype,
25 device=device,
26 # chunk_length_s=30, # for long-form transcription
27 max_new_tokens=128,
28)
29
30# Example audio
31dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
32sample = dataset[0]["audio"]
33
34# Run pipeline
35result = pipe(sample)
36print(result["text"])1import torch
2from datasets import load_dataset
3from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
4
5device = "cuda:0" if torch.cuda.is_available() else "cpu"
6torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
7
8# Load model
9model_name_or_path = "bofenghuang/whisper-large-v3-french-distil-dec8"
10processor = AutoProcessor.from_pretrained(model_name_or_path)
11model = AutoModelForSpeechSeq2Seq.from_pretrained(
12 model_name_or_path,
13 torch_dtype=torch_dtype,
14 low_cpu_mem_usage=True,
15)
16model.to(device)
17
18# Example audio
19dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
20sample = dataset[0]["audio"]
21
22# Extract feautres
23input_features = processor(
24 sample["array"], sampling_rate=sample["sampling_rate"], return_tensors="pt"
25).input_features
26
27
28# Generate tokens
29predicted_ids = model.generate(
30 input_features.to(dtype=torch_dtype).to(device), max_new_tokens=128
31)
32
33# Detokenize to text
34transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
35print(transcription)assistant_model within the generation configurations.1import torch
2from datasets import load_dataset
3from transformers import (
4 AutoModelForCausalLM,
5 AutoModelForSpeechSeq2Seq,
6 AutoProcessor,
7 pipeline,
8)
9
10device = "cuda:0" if torch.cuda.is_available() else "cpu"
11torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
12
13# Load model
14model_name_or_path = "bofenghuang/whisper-large-v3-french"
15processor = AutoProcessor.from_pretrained(model_name_or_path)
16model = AutoModelForSpeechSeq2Seq.from_pretrained(
17 model_name_or_path,
18 torch_dtype=torch_dtype,
19 low_cpu_mem_usage=True,
20)
21model.to(device)
22
23# Load draft model
24assistant_model_name_or_path = "bofenghuang/whisper-large-v3-french-distil-dec2"
25assistant_model = AutoModelForCausalLM.from_pretrained(
26 assistant_model_name_or_path,
27 torch_dtype=torch_dtype,
28 low_cpu_mem_usage=True,
29)
30assistant_model.to(device)
31
32# Init pipeline
33pipe = pipeline(
34 "automatic-speech-recognition",
35 model=model,
36 feature_extractor=processor.feature_extractor,
37 tokenizer=processor.tokenizer,
38 torch_dtype=torch_dtype,
39 device=device,
40 generate_kwargs={"assistant_model": assistant_model},
41 max_new_tokens=128,
42)
43
44# Example audio
45dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
46sample = dataset[0]["audio"]
47
48# Run pipeline
49result = pipe(sample)
50print(result["text"])pip install -U openai-whisperpython -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='bofenghuang/whisper-large-v3-french-distil-dec8', filename='original_model.pt', local_dir='./models/whisper-large-v3-french-distil-dec8')"1import whisper
2from datasets import load_dataset
3
4# Load model
5model = whisper.load_model("./models/whisper-large-v3-french-distil-dec8/original_model.pt")
6
7# Example audio
8dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
9sample = dataset[0]["audio"]["array"].astype("float32")
10
11# Transcribe
12result = model.transcribe(sample, language="fr")
13print(result["text"])pip install faster-whisperpython -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='bofenghuang/whisper-large-v3-french-distil-dec8', local_dir='./models/whisper-large-v3-french-distil-dec8', allow_patterns='ctranslate2/*')"1from datasets import load_dataset
2from faster_whisper import WhisperModel
3
4# Load model
5model = WhisperModel("./models/whisper-large-v3-french-distil-dec8/ctranslate2", device="cuda", compute_type="float16") # Run on GPU with FP16
6
7# Example audio
8dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
9sample = dataset[0]["audio"]["array"].astype("float32")
10
11segments, info = model.transcribe(sample, beam_size=5, language="fr")
12
13for segment in segments:
14 print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))1git clone https://github.com/ggerganov/whisper.cpp.git
2cd whisper.cpp
3
4# build the main example
5make1# Download model quantized with Q5_0 method
2python -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='bofenghuang/whisper-large-v3-french-distil-dec8', filename='ggml-model-q5_0.bin', local_dir='./models/whisper-large-v3-french-distil-dec8')"./main -m ./models/whisper-large-v3-french-distil-dec8/ggml-model-q5_0.bin -l fr -f /path/to/audio/file --print-colors1git clone https://github.com/huggingface/candle.git
2cd candle/candle-examples/examples/whispercargo run --example whisper --release -- --model large-v3 --model-id bofenghuang/whisper-large-v3-french-distil-dec8 --language fr --input /path/to/audio/file--features cuda to the example command line:cargo run --example whisper --release --features cuda -- --model large-v3 --model-id bofenghuang/whisper-large-v3-french-distil-dec8 --language fr --input /path/to/audio/file1git clone https://github.com/ml-explore/mlx-examples.git
2cd mlx-examples/whisperpip install -r requirements.txt1# Download
2python -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='bofenghuang/whisper-large-v3-french-distil-dec8', filename='original_model.pt', local_dir='./models/whisper-large-v3-french-distil-dec8')"
3# Convert into .npz
4python convert.py --torch-name-or-path ./models/whisper-large-v3-french-distil-dec8/original_model.pt --mlx-path ./mlx_models/whisper-large-v3-french-distil-dec81import whisper
2
3result = whisper.transcribe("/path/to/audio/file", path_or_hf_repo="mlx_models/whisper-large-v3-french-distil-dec8", language="fr")
4print(result["text"])