File size: 4,969 Bytes
0e9e06c
189064e
 
f1005ee
189064e
 
 
 
 
 
 
0e9e06c
189064e
 
 
 
 
 
 
a2bf487
c9ded15
189064e
 
 
 
620bf0f
189064e
c9ded15
189064e
 
 
 
a2bf487
c9ded15
a3e419b
189064e
 
 
620bf0f
189064e
c9ded15
0e9e06c
189064e
 
3b9ee33
189064e
 
 
 
 
 
 
71b1f48
 
 
 
 
 
 
 
 
 
 
 
6bef571
71b1f48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6bef571
 
71b1f48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189064e
 
 
 
 
 
 
112a067
189064e
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
language: fo
datasets:
- carlosdanielhernandezmena/ravnursson_asr
tags:
- audio
- automatic-speech-recognition
- faroese
- xlrs-53-faroese
- ravnur-project
- faroe-islands
license: cc-by-4.0
model-index:
- name: wav2vec2-large-xlsr-53-faroese-100h
  results:
  - task:
      name: Automatic Speech Recognition
      type: automatic-speech-recognition
    dataset:
      name: Ravnursson (Test)
      type: carlosdanielhernandezmena/ravnursson_asr
      split: test
      args: 
        language: fo
    metrics:
    - name: WER
      type: wer
      value: 7.6
  - task:
      name: Automatic Speech Recognition
      type: automatic-speech-recognition
    dataset:
      name: Ravnursson (Dev)
      type: carlosdanielhernandezmena/ravnursson_asr
      split: validation
      args: 
        language: fo
    metrics:
    - name: WER
      type: wer
      value: 5.5
---

# wav2vec2-large-xlsr-53-faroese-100h
**Paper:** [ASR Language Resources for Faroese](https://aclanthology.org/2023.nodalida-1.4.pdf)

The "wav2vec2-large-xlsr-53-faroese-100h" is an acoustic model suitable for Automatic Speech Recognition in Faroese. It is the result of fine-tuning the model "facebook/wav2vec2-large-xlsr-53" with 100 hours of Faroese data released by the Ravnur Project (https://maltokni.fo/en/) from the Faroe Islands.

The specific dataset used to create the model is called "Ravnursson Faroese Speech and Transcripts" and it is available at http://hdl.handle.net/20.500.12537/276.
	
The fine-tuning process was perform during November (2022) in the servers of the Language and Voice Lab (https://lvl.ru.is/) at Reykjavík University (Iceland) by Carlos Daniel Hernández Mena.

# Evaluation
```python
import torch
from transformers import Wav2Vec2Processor
from transformers import Wav2Vec2ForCTC

#Load the processor and model.
MODEL_NAME="carlosdanielhernandezmena/wav2vec2-large-xlsr-53-faroese-100h"
processor = Wav2Vec2Processor.from_pretrained(MODEL_NAME)
model = Wav2Vec2ForCTC.from_pretrained(MODEL_NAME)

#Load the dataset
from datasets import load_dataset, Audio
ds=load_dataset("carlosdanielhernandezmena/ravnursson_asr",split='test')

#Downsample to 16kHz
ds = ds.cast_column("audio", Audio(sampling_rate=16_000))

#Process the dataset
def prepare_dataset(batch):
    audio = batch["audio"]
    #Batched output is "un-batched" to ensure mapping is correct
    batch["input_values"] = processor(audio["array"], sampling_rate=audio["sampling_rate"]).input_values[0]
    with processor.as_target_processor():
        batch["labels"] = processor(batch["normalized_text"]).input_ids
    return batch
ds = ds.map(prepare_dataset, remove_columns=ds.column_names,num_proc=1)

#Define the evaluation metric
import numpy as np
from evaluate import load
wer_metric = load("wer")
def compute_metrics(pred):
    pred_logits = pred.predictions
    pred_ids = np.argmax(pred_logits, axis=-1)
    pred.label_ids[pred.label_ids == -100] = processor.tokenizer.pad_token_id
    pred_str = processor.batch_decode(pred_ids)
    #We do not want to group tokens when computing the metrics
    label_str = processor.batch_decode(pred.label_ids, group_tokens=False)
    wer = wer_metric.compute(predictions=pred_str, references=label_str)
    return {"wer": wer}

#Do the evaluation (with batch_size=1)
model = model.to(torch.device("cuda"))
def map_to_result(batch):
    with torch.no_grad():
        input_values = torch.tensor(batch["input_values"], device="cuda").unsqueeze(0)
        logits = model(input_values).logits
    pred_ids = torch.argmax(logits, dim=-1)
    batch["pred_str"] = processor.batch_decode(pred_ids)[0]
    batch["sentence"] = processor.decode(batch["labels"], group_tokens=False)
    return batch
results = ds.map(map_to_result,remove_columns=ds.column_names)

#Compute the overall WER now.
print("Test WER: {:.3f}".format(wer_metric.compute(predictions=results["pred_str"], references=results["sentence"])))

```
**Test Result**: 0.076

# BibTeX entry and citation info
*When publishing results based on these models please refer to:*
```bibtex
@misc{mena2022xlrs53faroese,
      title={Acoustic Model in Faroese: wav2vec2-large-xlsr-53-faroese-100h.}, 
      author={Hernandez Mena, Carlos Daniel},
      url={https://huggingface.co/carlosdanielhernandezmena/wav2vec2-large-xlsr-53-faroese-100h},
      year={2022}
}
```

# Acknowledgements

We want to thank to Jón Guðnason, head of the Language and Voice Lab for providing computational power to make this model possible. We also want to thank to the "Language Technology Programme for Icelandic 2019-2023" which is managed and coordinated by Almannarómur, and it is funded by the Icelandic Ministry of Education, Science and Culture.

Special thanks to Annika Simonsen and to The Ravnur Project for making their
"Basic Language Resource Kit"(BLARK 1.0) publicly available through the research paper "Creating a Basic Language Resource Kit for Faroese" https://aclanthology.org/2022.lrec-1.495.pdf