Instructions to use patrickvonplaten/wav2vec2_tiny_random_robust with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use patrickvonplaten/wav2vec2_tiny_random_robust with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("automatic-speech-recognition", model="patrickvonplaten/wav2vec2_tiny_random_robust")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModel processor = AutoProcessor.from_pretrained("patrickvonplaten/wav2vec2_tiny_random_robust") model = AutoModel.from_pretrained("patrickvonplaten/wav2vec2_tiny_random_robust", device_map="auto") - Notebooks
- Google Colab
- Kaggle
|
Download README.md from patrickvonplaten/wav2vec2_tiny_random_robust: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/patrickvonplaten/wav2vec2_tiny_random_robust/resolve/main/README.md
- Command line
-
hf download hf://patrickvonplaten/wav2vec2_tiny_random_robust/README.md
-
curl -L -o README.md https://huggingface.co/patrickvonplaten/wav2vec2_tiny_random_robust/resolve/main/README.md
1.13 kB
| language: en | |
| datasets: | |
| - librispeech_asr | |
| tags: | |
| - automatic-speech-recognition | |
| license: apache-2.0 | |
| ## Test model | |
| To test this model run the following code: | |
| ```python | |
| from datasets import load_dataset | |
| from transformers import Wav2Vec2ForCTC | |
| import torchaudio | |
| import torch | |
| ds = load_dataset("patrickvonplaten/librispeech_asr_dummy", "clean", split="validation") | |
| model = Wav2Vec2ForCTC.from_pretrained("patrickvonplaten/wav2vec2_tiny_random_robust") | |
| def load_audio(batch): | |
| batch["samples"], _ = torchaudio.load(batch["file"]) | |
| return batch | |
| ds = ds.map(load_audio) | |
| input_values = torch.nn.utils.rnn.pad_sequence([torch.tensor(x[0]) for x in ds["samples"][:10]], batch_first=True) | |
| # forward | |
| logits = model(input_values).logits | |
| pred_ids = torch.argmax(logits, dim=-1) | |
| # dummy loss | |
| dummy_labels = pred_ids.clone() | |
| dummy_labels[dummy_labels == model.config.pad_token_id] = 1 # can't have CTC blank token in label | |
| dummy_labels = dummy_labels[:, -(dummy_labels.shape[1] // 4):] # make sure labels are shorter to avoid "inf" loss (can still happen though...) | |
| loss = model(input_values, labels=dummy_labels).loss | |
| ``` | |