Views
No views yet
pip install -U torch transformers accelerate soundfile1import torch
2from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
3
4model_id = "inesc-id/WhisperLv3-FT-EP-CPP"
5
6# Use the base Whisper large-v3 processor.
7# This is needed because the fine-tuned model repo may not include processor files.
8processor_id = "openai/whisper-large-v3"
9
10device = 0 if torch.cuda.is_available() else -1
11torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
12
13processor = AutoProcessor.from_pretrained(processor_id)
14
15model = AutoModelForSpeechSeq2Seq.from_pretrained(
16 model_id,
17 torch_dtype=torch_dtype,
18 low_cpu_mem_usage=True,
19 use_safetensors=True,
20)
21
22if torch.cuda.is_available():
23 model.to("cuda")
24
25forced_decoder_ids = processor.get_decoder_prompt_ids(
26 language="portuguese",
27 task="transcribe",
28)
29
30asr = pipeline(
31 task="automatic-speech-recognition",
32 model=model,
33 tokenizer=processor.tokenizer,
34 feature_extractor=processor.feature_extractor,
35 torch_dtype=torch_dtype,
36 device=device,
37 generate_kwargs={
38 "forced_decoder_ids": forced_decoder_ids,
39 "num_beams": 1,
40 },
41)
42
43result = asr("audio.wav")
44print(result["text"])Miamoto/WhisperLv3-FT-EP-CPPopenai/whisper-large-v3preprocessor_config.json.@inproceedings{camoes,
title={{CAMÕES: A Comprehensive Automatic Speech Recognition Benchmark for European Portuguese}},
author={Carlos Carvalho, Francisco Teixeira, Catarina Botelho, Anna Pompili, Rubén Solera-Ureña, Sérgio Paulo, Mariana Julião, Thomas Rolland, John Mendonça, Diogo Pereira, Isabel Trancoso, Alberto Abad},
booktitle={Proceedings of the IEEE Automatic Speech Recognition and Understanding Workshop (ASRU)},
year={2025},
}