Views
No views yet
1from huggingsound import SpeechRecognitionModel
2
3model = SpeechRecognitionModel("jonatasgrosman/wav2vec2-large-xlsr-53-polish")
4audio_paths = ["/path/to/file.mp3", "/path/to/another_file.wav"]
5
6transcriptions = model.transcribe(audio_paths)1import torch
2import librosa
3from datasets import load_dataset
4from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
5
6LANG_ID = "pl"
7MODEL_ID = "jonatasgrosman/wav2vec2-large-xlsr-53-polish"
8SAMPLES = 5
9
10test_dataset = load_dataset("common_voice", LANG_ID, split=f"test[:{SAMPLES}]")
11
12processor = Wav2Vec2Processor.from_pretrained(MODEL_ID)
13model = Wav2Vec2ForCTC.from_pretrained(MODEL_ID)
14
15# Preprocessing the datasets.
16# We need to read the audio files as arrays
17def speech_file_to_array_fn(batch):
18 speech_array, sampling_rate = librosa.load(batch["path"], sr=16_000)
19 batch["speech"] = speech_array
20 batch["sentence"] = batch["sentence"].upper()
21 return batch
22
23test_dataset = test_dataset.map(speech_file_to_array_fn)
24inputs = processor(test_dataset["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
25
26with torch.no_grad():
27 logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
28
29predicted_ids = torch.argmax(logits, dim=-1)
30predicted_sentences = processor.batch_decode(predicted_ids)
31
32for i, predicted_sentence in enumerate(predicted_sentences):
33 print("-" * 100)
34 print("Reference:", test_dataset[i]["sentence"])
35 print("Prediction:", predicted_sentence)| Reference | Prediction |
|---|---|
| """CZY DRZWI BYŁY ZAMKNIĘTE?""" | PRZY DRZWI BYŁY ZAMKNIĘTE |
| GDZIEŻ TU POWÓD DO WYRZUTÓW? | WGDZIEŻ TO POM DO WYRYDÓ |
| """O TEM JEDNAK NIE BYŁO MOWY.""" | O TEM JEDNAK NIE BYŁO MOWY |
| LUBIĘ GO. | LUBIĄ GO |
| — TO MI NIE POMAGA. | TO MNIE NIE POMAGA |
| WCIĄŻ LUDZIE WYSIADAJĄ PRZED ZAMKIEM, Z MIASTA, Z PRAGI. | WCIĄŻ LUDZIE WYSIADAJĄ PRZED ZAMKIEM Z MIASTA Z PRAGI |
| ALE ON WCALE INACZEJ NIE MYŚLAŁ. | ONY MONITCENIE PONACZUŁA NA MASU |
| A WY, CO TAK STOICIE? | A WY CO TAK STOICIE |
| A TEN PRZYRZĄD DO CZEGO SŁUŻY? | A TEN PRZYRZĄD DO CZEGO SŁUŻY |
| NA JUTRZEJSZYM KOLOKWIUM BĘDZIE PIĘĆ PYTAŃ OTWARTYCH I TEST WIELOKROTNEGO WYBORU. | NAJUTRZEJSZYM KOLOKWIUM BĘDZIE PIĘĆ PYTAŃ OTWARTYCH I TEST WIELOKROTNEGO WYBORU |
mozilla-foundation/common_voice_6_0 with split testpython eval.py --model_id jonatasgrosman/wav2vec2-large-xlsr-53-polish --dataset mozilla-foundation/common_voice_6_0 --config pl --split testspeech-recognition-community-v2/dev_datapython eval.py --model_id jonatasgrosman/wav2vec2-large-xlsr-53-polish --dataset speech-recognition-community-v2/dev_data --config pl --split validation --chunk_length_s 5.0 --stride_length_s 1.01@misc{grosman2021xlsr53-large-polish,
2 title={Fine-tuned {XLSR}-53 large model for speech recognition in {P}olish},
3 author={Grosman, Jonatas},
4 howpublished={\url{https://huggingface.co/jonatasgrosman/wav2vec2-large-xlsr-53-polish}},
5 year={2021}
6}