readme: ---
  language:
  - ro
  license: apache-2.0
  tags:
  - automatic-speech-recognition
  - hf-asr-leaderboard
  - robust-speech-event
  datasets:
  - mozilla-foundation/common_voice_8_0
  - gigant/romanian_speech_synthesis_0_8_1
  model-index:
  - name: wav2vec2-ro-300m_01
    results:
    - task:
        name: Automatic Speech Recognition
        type: automatic-speech-recognition
      dataset:
        name: Robust Speech Event
        type: speech-recognition-community-v2/dev_data
        args: ro
      metrics:
      - name: Dev WER (without LM)
        type: wer
        value: 46.99
      - name: Dev CER (without LM)
        type: cer
        value: 16.04
      - name: Dev WER (with LM)
        type: wer
        value: 38.63
      - name: Dev CER (with LM)
        type: cer
        value: 14.52
    - task:
        name: Automatic Speech Recognition
        type: automatic-speech-recognition
      dataset:
        name: Common Voice
        type: mozilla-foundation/common_voice_8_0
        args: ro
      metrics:
      - name: Test WER (without LM)
        type: wer
        value: 11.73
      - name: Test CER (without LM)
        type: cer
        value: 2.93
      - name: Test WER (with LM)
        type: wer
        value: 7.31
      - name: Test CER (with LM)
        type: cer
        value: 2.17
    - task:
        name: Automatic Speech Recognition
        type: automatic-speech-recognition
      dataset:
        name: Robust Speech Event - Test Data
        type: speech-recognition-community-v2/eval_data
        args: ro
      metrics:
      - name: Test WER
        type: wer
        value: 43.23
  ---
  
  You can test this model online with the [**Space for Romanian Speech Recognition**](https://huggingface.co/spaces/gigant/romanian-speech-recognition)
  
  The model ranked **TOP-1** on Romanian Speech Recognition during HuggingFace's Robust Speech Challenge :
  
  * [**The 🤗 Speech Bench**](https://huggingface.co/spaces/huggingface/hf-speech-bench)
  
  * [**Speech Challenge Leaderboard**](https://huggingface.co/spaces/speech-recognition-community-v2/FinalLeaderboard)
  
  # Romanian Wav2Vec2
  
  This model is a fine-tuned version of [facebook/wav2vec2-xls-r-300m](https://huggingface.co/facebook/wav2vec2-xls-r-300m) on the [Common Voice 8.0 - Romanian subset](https://huggingface.co/datasets/mozilla-foundation/common_voice_8_0) dataset, with extra training data from [Romanian Speech Synthesis](https://huggingface.co/datasets/gigant/romanian_speech_synthesis_0_8_1) dataset.
  
  Without the 5-gram Language Model optimization, it achieves the following results on the evaluation set (Common Voice 8.0, Romanian subset, test split):
  - Loss: 0.1553
  - Wer: 0.1174
  - Cer: 0.0294
  
  ## Model description
  
  The architecture is based on [facebook/wav2vec2-xls-r-300m](https://huggingface.co/facebook/wav2vec2-xls-r-300m) with a speech recognition CTC head and an added 5-gram language model (using [pyctcdecode](https://github.com/kensho-technologies/pyctcdecode) and [kenlm](https://github.com/kpu/kenlm)) trained on the [Romanian Corpora Parliament](gigant/ro_corpora_parliament_processed) dataset. Those libraries are needed in order for the language model-boosted decoder to work.
  
  ## Intended uses & limitations
  
  The model is made for speech recognition in Romanian from audio clips sampled at **16kHz**. The predicted text is lowercased and does not contain any punctuation.
  
  ## How to use
  
  Make sure you have installed the correct dependencies for the language model-boosted version to work. You can just run this command to install the `kenlm` and `pyctcdecode` libraries :
  
  ```pip install https://github.com/kpu/kenlm/archive/master.zip pyctcdecode```
  
  
  With the framework `transformers` you can load the model with the following code :
  
  ```
  from transformers import AutoProcessor, AutoModelForCTC
  
  processor = AutoProcessor.from_pretrained("gigant/romanian-wav2vec2")
  
  model = AutoModelForCTC.from_pretrained("gigant/romanian-wav2vec2")
  ```
  
  Or, if you want to test the model, you can load the automatic speech recognition pipeline from `transformers` with :
  
  ```
  from transformers import pipeline
  
  asr = pipeline("automatic-speech-recognition", model="gigant/romanian-wav2vec2")
  ```
  
  
  ## Example use with the `datasets` library
  
  First, you need to load your data
  
  We will use the [Romanian Speech Synthesis](https://huggingface.co/datasets/gigant/romanian_speech_synthesis_0_8_1) dataset in this example.
  
  ```
  from datasets import load_dataset
  
  dataset = load_dataset("gigant/romanian_speech_synthesis_0_8_1")
  ```
  
  You can listen to the samples with the `IPython.display` library :
  
  ```
  from IPython.display import Audio
  
  i = 0
  sample = dataset["train"][i]
  Audio(sample["audio"]["array"], rate = sample["audio"]["sampling_rate"])
  ```
  
  The model is trained to work with audio sampled at 16kHz, so if the sampling rate of the audio in the dataset is different, we will have to resample it.
  
  In the example, the audio is sampled at 48kHz. We can see this by checking `dataset["train"][0]["audio"]["sampling_rate"]`
  
  The following code resample the audio using the `torchaudio` library :
  
  ```
  import torcha