carlosdanielhernandezmena
commited on
Commit
•
761ee23
1
Parent(s):
7d80113
Adding info to the readme file
Browse files
README.md
CHANGED
@@ -14,4 +14,176 @@ tags:
|
|
14 |
- barcelona-supercomputing-center
|
15 |
- automatic-speech-recognition
|
16 |
- whisper-large-v3
|
17 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
- barcelona-supercomputing-center
|
15 |
- automatic-speech-recognition
|
16 |
- whisper-large-v3
|
17 |
+
---
|
18 |
+
|
19 |
+
# whisper-large-v3-tiny-caesar
|
20 |
+
|
21 |
+
## Table of Contents
|
22 |
+
<details>
|
23 |
+
<summary>Click to expand</summary>
|
24 |
+
|
25 |
+
- [Model Description](#model-description)
|
26 |
+
- [Intended Uses and Limitations](#intended-uses-and-limitations)
|
27 |
+
- [How to Get Started with the Model](#how-to-get-started-with-the-model)
|
28 |
+
- [Training Details](#training-details)
|
29 |
+
- [Citation](#citation)
|
30 |
+
- [Additional Information](#additional-information)
|
31 |
+
|
32 |
+
</details>
|
33 |
+
|
34 |
+
## Summary
|
35 |
+
|
36 |
+
The "whisper-large-v3-tiny-caesar" is an acoustic model based on ["openai/whisper-large-v3"](https://huggingface.co/openai/whisper-large-v3) suitable for Automatic Speech Recognition in code switching conditions between Spanish and Catalan.
|
37 |
+
|
38 |
+
## Model Description
|
39 |
+
|
40 |
+
The "whisper-large-v3-tiny-caesar" is an acoustic model suitable for Automatic Speech Recognition in code switching conditions between Spanish and Catalan. It is the result of finetuning the model ["openai/whisper-large-v3"](https://huggingface.co/openai/whisper-large-v3) with 2 hours of synthetic code switching data in Spanish/Catalan generated by the [Projecte AINA](https://projecteaina.cat/) from Barcelona, Spain.
|
41 |
+
|
42 |
+
CAESAR is an acronym with the following meaning:
|
43 |
+
|
44 |
+
(CA)talan (ES)panish (A)utomatic (Recognition)
|
45 |
+
|
46 |
+
While "tiny" indicates that this model was finetuned with a very small amount of synthetic data (2 hours only).
|
47 |
+
|
48 |
+
## Intended Uses and Limitations
|
49 |
+
|
50 |
+
This model can be used for Automatic Speech Recognition (ASR) in code switching conditions between Spanish and Catalan. The model is intended to transcribe audio files to plain text.
|
51 |
+
|
52 |
+
## How to Get Started with the Model
|
53 |
+
|
54 |
+
To see an updated and functional version of this code, please see our our [Notebook](https://colab.research.google.com/drive/1MHiPrffNTwiyWeUyMQvSdSbfkef_8aJC?usp=sharing)
|
55 |
+
|
56 |
+
### Installation
|
57 |
+
|
58 |
+
In order to use this model, you may install [datasets](https://huggingface.co/docs/datasets/installation) and [transformers](https://huggingface.co/docs/transformers/installation):
|
59 |
+
|
60 |
+
Create a virtual environment:
|
61 |
+
```bash
|
62 |
+
python -m venv /path/to/venv
|
63 |
+
```
|
64 |
+
Activate the environment:
|
65 |
+
```bash
|
66 |
+
source /path/to/venv/bin/activate
|
67 |
+
```
|
68 |
+
Install the modules:
|
69 |
+
```bash
|
70 |
+
pip install datasets transformers
|
71 |
+
```
|
72 |
+
|
73 |
+
### For Inference
|
74 |
+
In order to transcribe audio in Catalan using this model, you can follow this example:
|
75 |
+
|
76 |
+
```bash
|
77 |
+
#Install Prerequisites
|
78 |
+
pip install torch
|
79 |
+
pip install datasets
|
80 |
+
pip install 'transformers[torch]'
|
81 |
+
pip install evaluate
|
82 |
+
pip install jiwer
|
83 |
+
```
|
84 |
+
|
85 |
+
```python
|
86 |
+
#This code works with GPU
|
87 |
+
|
88 |
+
#Notice that: load_metric is no longer part of datasets.
|
89 |
+
#you have to remove it and use evaluate's load instead.
|
90 |
+
#(Note from November 2024)
|
91 |
+
|
92 |
+
import torch
|
93 |
+
from transformers import WhisperForConditionalGeneration, WhisperProcessor
|
94 |
+
|
95 |
+
#Load the processor and model.
|
96 |
+
MODEL_NAME="projecte-aina/whisper-large-v3-tiny-caesar"
|
97 |
+
processor = WhisperProcessor.from_pretrained(MODEL_NAME)
|
98 |
+
model = WhisperForConditionalGeneration.from_pretrained(MODEL_NAME).to("cuda")
|
99 |
+
|
100 |
+
#Load the dataset
|
101 |
+
from datasets import load_dataset, load_metric, Audio
|
102 |
+
ds=load_dataset("projecte-aina/3catparla_asr",split='test')
|
103 |
+
|
104 |
+
#Downsample to 16kHz
|
105 |
+
ds = ds.cast_column("audio", Audio(sampling_rate=16_000))
|
106 |
+
|
107 |
+
#Process the dataset
|
108 |
+
def map_to_pred(batch):
|
109 |
+
audio = batch["audio"]
|
110 |
+
input_features = processor(audio["array"], sampling_rate=audio["sampling_rate"], return_tensors="pt").input_features
|
111 |
+
batch["reference"] = processor.tokenizer._normalize(batch['normalized_text'])
|
112 |
+
|
113 |
+
with torch.no_grad():
|
114 |
+
predicted_ids = model.generate(input_features.to("cuda"))[0]
|
115 |
+
|
116 |
+
transcription = processor.decode(predicted_ids)
|
117 |
+
batch["prediction"] = processor.tokenizer._normalize(transcription)
|
118 |
+
|
119 |
+
return batch
|
120 |
+
|
121 |
+
#Do the evaluation
|
122 |
+
result = ds.map(map_to_pred)
|
123 |
+
|
124 |
+
#Compute the overall WER now.
|
125 |
+
from evaluate import load
|
126 |
+
|
127 |
+
wer = load("wer")
|
128 |
+
WER=100 * wer.compute(references=result["reference"], predictions=result["prediction"])
|
129 |
+
print(WER)
|
130 |
+
```
|
131 |
+
|
132 |
+
## Training Details
|
133 |
+
|
134 |
+
### Training data
|
135 |
+
|
136 |
+
The specific dataset used to create the model is a corpus called CAESAR-tiny which has not been released at the moment.
|
137 |
+
|
138 |
+
### Training procedure
|
139 |
+
|
140 |
+
This model is the result of finetuning the model ["openai/whisper-large-v3"](https://huggingface.co/openai/whisper-large-v3) by following this [tutorial](https://huggingface.co/blog/fine-tune-whisper) provided by Hugging Face.
|
141 |
+
|
142 |
+
### Training Hyperparameters
|
143 |
+
|
144 |
+
* language: Spanish
|
145 |
+
* hours of training audio: 2
|
146 |
+
* learning rate: 1e-5
|
147 |
+
* sample rate: 16000
|
148 |
+
* train batch size: 32 (x4 GPUs)
|
149 |
+
* gradient accumulation steps: 1
|
150 |
+
* eval batch size: 32
|
151 |
+
* save total limit: 3
|
152 |
+
* max steps: 80
|
153 |
+
* warmup steps: 8
|
154 |
+
* eval steps: 8
|
155 |
+
* save steps: 8
|
156 |
+
* shuffle buffer size: 480
|
157 |
+
|
158 |
+
## Citation
|
159 |
+
If this model contributes to your research, please cite the work:
|
160 |
+
```bibtex
|
161 |
+
@misc{mena2024whisperlarge3catparla,
|
162 |
+
title={Acoustic Model in Catalan: whisper-large-v3-tiny-caesar.},
|
163 |
+
author={Hernandez Mena, Carlos Daniel; Giraldo, Jose ;Armentano-Oller, Carme; Solito, Sarah; Messaoudi, Abir; Acosta, Federico; Zeballos, Rodolfo},
|
164 |
+
organization={Barcelona Supercomputing Center},
|
165 |
+
url={https://huggingface.co/projecte-aina/whisper-large-v3-tiny-caesar},
|
166 |
+
year={2024}
|
167 |
+
}
|
168 |
+
```
|
169 |
+
|
170 |
+
## Additional Information
|
171 |
+
|
172 |
+
### Author
|
173 |
+
|
174 |
+
The fine-tuning process was perform during November (2024) in the [Language Technologies Unit](https://huggingface.co/BSC-LT) of the [Barcelona Supercomputing Center](https://www.bsc.es/) by [Carlos Daniel Hernández Mena](https://huggingface.co/carlosdanielhernandezmena).
|
175 |
+
|
176 |
+
### Contact
|
177 |
+
For further information, please send an email to <langtech@bsc.es>.
|
178 |
+
|
179 |
+
### Copyright
|
180 |
+
Copyright(c) 2024 by Language Technologies Unit, Barcelona Supercomputing Center.
|
181 |
+
|
182 |
+
### License
|
183 |
+
|
184 |
+
[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
185 |
+
|
186 |
+
### Funding
|
187 |
+
This work has been promoted and financed by the Generalitat de Catalunya through the [Aina project](https://projecteaina.cat/).
|
188 |
+
|
189 |
+
The training of the model was possible thanks to the compute time provided by [Barcelona Supercomputing Center](https://www.bsc.es/) through MareNostrum 5.
|