Views
No views yet
| Model Name | #params | checkpoint |
|---|---|---|
| W2v-BERT 2.0 | 600M | checkpoint |
1from transformers import AutoFeatureExtractor, Wav2Vec2BertModel
2import torch
3from datasets import load_dataset
4
5dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation")
6dataset = dataset.sort("id")
7sampling_rate = dataset.features["audio"].sampling_rate
8
9processor = AutoProcessor.from_pretrained("Aspik101/distil-whisper-large-v3-pl")
10model = Wav2Vec2BertModel.from_pretrained("Aspik101/distil-whisper-large-v3-pl")
11
12# audio file is decoded on the fly
13inputs = processor(dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="pt")
14with torch.no_grad():
15 outputs = model(**inputs)1import torch
2
3from fairseq2.data.audio import AudioDecoder, WaveformToFbankConverter
4from fairseq2.memory import MemoryBlock
5from fairseq2.nn.padding import get_seqs_and_padding_mask
6from pathlib import Path
7from seamless_communication.models.conformer_shaw import load_conformer_shaw_model
8
9
10audio_wav_path, device, dtype = ...
11audio_decoder = AudioDecoder(dtype=torch.float32, device=device)
12fbank_converter = WaveformToFbankConverter(
13 num_mel_bins=80,
14 waveform_scale=2**15,
15 channel_last=True,
16 standardize=True,
17 device=device,
18 dtype=dtype,
19)
20collater = Collater(pad_value=1)
21
22model = load_conformer_shaw_model("conformer_shaw", device=device, dtype=dtype)
23model.eval()
24
25with Path(audio_wav_path).open("rb") as fb:
26 block = MemoryBlock(fb.read())
27
28decoded_audio = audio_decoder(block)
29src = collater(fbank_converter(decoded_audio))["fbank"]
30seqs, padding_mask = get_seqs_and_padding_mask(src)
31
32with torch.inference_mode():
33 seqs, padding_mask = model.encoder_frontend(seqs, padding_mask)
34 seqs, padding_mask = model.encoder(seqs, padding_mask)