Duplicate from Jzuluaga/accent-id-commonaccent_xlsr-en-english
Browse filesCo-authored-by: Juan Pablo Zuluaga <[email protected]>
- .gitattributes +35 -0
- README.md +192 -0
- custom_interface.py +158 -0
- data/.hola +0 -0
- data/malaysia_1.wav +0 -0
- data/philippines_1.wav +0 -0
- data/scotland_1.wav +0 -0
- data/us_1.wav +0 -0
- hyperparams.yaml +59 -0
- label_encoder.txt +18 -0
- model.ckpt +3 -0
- wav2vec2.ckpt +3 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
thumbnail: null
|
5 |
+
tags:
|
6 |
+
- audio-classification
|
7 |
+
- speechbrain
|
8 |
+
- embeddings
|
9 |
+
- Accent Identification
|
10 |
+
- pytorch
|
11 |
+
- wav2vec2
|
12 |
+
- XLSR
|
13 |
+
- CommonAccent
|
14 |
+
- English
|
15 |
+
license: mit
|
16 |
+
datasets:
|
17 |
+
- CommonVoice
|
18 |
+
metrics:
|
19 |
+
- Accuracy
|
20 |
+
widget:
|
21 |
+
- example_title: USA
|
22 |
+
src: >-
|
23 |
+
https://huggingface.co/Jzuluaga/accent-id-commonaccent_xlsr-en-english/resolve/main/data/us_1.wav
|
24 |
+
- example_title: Scotland
|
25 |
+
src: >-
|
26 |
+
https://huggingface.co/Jzuluaga/accent-id-commonaccent_xlsr-en-english/resolve/main/data/scotland_1.wav
|
27 |
+
- example_title: Malaysia
|
28 |
+
src: >-
|
29 |
+
https://huggingface.co/Jzuluaga/accent-id-commonaccent_xlsr-en-english/resolve/main/data/malaysia_1.wav
|
30 |
+
- example_title: Philippines
|
31 |
+
src: >-
|
32 |
+
https://huggingface.co/Jzuluaga/accent-id-commonaccent_xlsr-en-english/resolve/main/data/philippines_1.wav
|
33 |
+
---
|
34 |
+
|
35 |
+
|
36 |
+
<iframe src="https://ghbtns.com/github-btn.html?user=speechbrain&repo=speechbrain&type=star&count=true&size=large&v=2" frameborder="0" scrolling="0" width="170" height="30" title="GitHub"></iframe>
|
37 |
+
<br/><br/>
|
38 |
+
|
39 |
+
|
40 |
+
# CommonAccent: Exploring Large Acoustic Pretrained Models for Accent Classification Based on CommonVoice
|
41 |
+
|
42 |
+
**English Accent Classifier with XLSR model**
|
43 |
+
|
44 |
+
|
45 |
+
**Abstract**:
|
46 |
+
Despite the recent advancements in Automatic Speech Recognition (ASR), the recognition of accented speech still remains a dominant problem. In order to create more inclusive ASR systems, research has shown that the integration of accent information, as part of a larger ASR framework, can lead to the mitigation of accented speech errors. We address multilingual accent classification through the ECAPA-TDNN and Wav2Vec 2.0/XLSR architectures which have been proven to perform well on a variety of speech-related downstream tasks. We introduce a simple-to-follow recipe aligned to the SpeechBrain toolkit for accent classification based on Common Voice 7.0 (English) and Common Voice 11.0 (Italian, German, and Spanish). Furthermore, we establish new state-of-the-art for English accent classification with as high as 95% accuracy. We also study the internal categorization of the Wav2Vev 2.0 embeddings through t-SNE, noting that there is a level of clustering based on phonological similarity.
|
47 |
+
|
48 |
+
|
49 |
+
This repository provides all the necessary tools to perform accent identification from speech recordings with [SpeechBrain](https://github.com/speechbrain/speechbrain).
|
50 |
+
The system uses a model pretrained on the CommonAccent dataset in English (16 accents). This system is based on the CommonLanguage Recipe located here: https://github.com/speechbrain/speechbrain/tree/develop/recipes/CommonLanguage
|
51 |
+
|
52 |
+
|
53 |
+
The provided system can recognize the following 16 accents from short speech recordings in English (EN):
|
54 |
+
|
55 |
+
```
|
56 |
+
- us
|
57 |
+
- england
|
58 |
+
- australia
|
59 |
+
- indian
|
60 |
+
- canada
|
61 |
+
- bermuda
|
62 |
+
- scotland
|
63 |
+
- african
|
64 |
+
- ireland
|
65 |
+
- newzealand
|
66 |
+
- wales
|
67 |
+
- malaysia
|
68 |
+
- philippines
|
69 |
+
- singapore
|
70 |
+
- hongkong
|
71 |
+
- southatlandtic
|
72 |
+
```
|
73 |
+
|
74 |
+
<a href="https://github.com/JuanPZuluaga/accent-recog-slt2022"> <img alt="GitHub" src="https://img.shields.io/badge/GitHub-Open%20source-green"> </a> Github repository link: https://github.com/JuanPZuluaga/accent-recog-slt2022
|
75 |
+
|
76 |
+
|
77 |
+
**NOTE**: due to incompatibility with the model and the current SpeechBrain interfaces, we cannot offer the Inference API. Please, follow the steps in **"Perform Accent Identification from Speech Recordings"** to use this Italian Accent ID model.
|
78 |
+
|
79 |
+
For a better experience, we encourage you to learn more about
|
80 |
+
[SpeechBrain](https://speechbrain.github.io).
|
81 |
+
|
82 |
+
|
83 |
+
## Pipeline description
|
84 |
+
This system is composed of a fine-tuned XLSR model coupled with statistical pooling. A classifier, trained with NLL Loss, is applied on top of that.
|
85 |
+
|
86 |
+
The system is trained with recordings sampled at 16kHz (single channel).
|
87 |
+
The code will automatically normalize your audio (i.e., resampling + mono channel selection) when calling *classify_file* if needed. Make sure your input tensor is compliant with the expected sampling rate if you use *encode_batch* and *classify_batch*.
|
88 |
+
|
89 |
+
## Install SpeechBrain
|
90 |
+
|
91 |
+
First of all, please install SpeechBrain with the following command:
|
92 |
+
|
93 |
+
```
|
94 |
+
pip install speechbrain
|
95 |
+
```
|
96 |
+
|
97 |
+
Please notice that we encourage you to read our tutorials and learn more about
|
98 |
+
[SpeechBrain](https://speechbrain.github.io).
|
99 |
+
|
100 |
+
### Perform Accent Identification from Speech Recordings
|
101 |
+
|
102 |
+
```python
|
103 |
+
import torchaudio
|
104 |
+
from speechbrain.pretrained.interfaces import foreign_class
|
105 |
+
|
106 |
+
classifier = foreign_class(source="Jzuluaga/accent-id-commonaccent_xlsr-en-english", pymodule_file="custom_interface.py", classname="CustomEncoderWav2vec2Classifier")
|
107 |
+
|
108 |
+
# US Accent Example
|
109 |
+
out_prob, score, index, text_lab = classifier.classify_file('Jzuluaga/accent-id-commonaccent_xlsr-en-english/data/us.wav')
|
110 |
+
print(text_lab)
|
111 |
+
|
112 |
+
# Philippines Example
|
113 |
+
out_prob, score, index, text_lab = classifier.classify_file('Jzuluaga/accent-id-commonaccent_xlsr-en-english/data/philippines.wav')
|
114 |
+
print(text_lab)
|
115 |
+
```
|
116 |
+
|
117 |
+
### Inference on GPU
|
118 |
+
To perform inference on the GPU, add `run_opts={"device":"cuda"}` when calling the `from_hparams` method.
|
119 |
+
|
120 |
+
### Training
|
121 |
+
|
122 |
+
The model was trained with SpeechBrain.
|
123 |
+
|
124 |
+
To train it from scratch follow these steps:
|
125 |
+
|
126 |
+
1. Clone SpeechBrain:
|
127 |
+
```bash
|
128 |
+
git clone https://github.com/speechbrain/speechbrain/
|
129 |
+
```
|
130 |
+
|
131 |
+
2. Install it:
|
132 |
+
```bash
|
133 |
+
cd speechbrain
|
134 |
+
pip install -r requirements.txt
|
135 |
+
pip install -e .
|
136 |
+
```
|
137 |
+
|
138 |
+
3. Clone our repository in https://github.com/JuanPZuluaga/accent-recog-slt2022:
|
139 |
+
|
140 |
+
```bash
|
141 |
+
git clone https://github.com/JuanPZuluaga/accent-recog-slt2022
|
142 |
+
cd CommonAccent/accent_id
|
143 |
+
python train_w2v2.py hparams/train_w2v2.yaml
|
144 |
+
```
|
145 |
+
|
146 |
+
You can find our training results (models, logs, etc) in this repository's `Files and versions` page.
|
147 |
+
|
148 |
+
### Limitations
|
149 |
+
The SpeechBrain team does not provide any warranty on the performance achieved by this model when used on other datasets.
|
150 |
+
|
151 |
+
|
152 |
+
|
153 |
+
#### Cite our work: CommonAccent
|
154 |
+
|
155 |
+
If you find useful this work, please cite our work as:
|
156 |
+
|
157 |
+
```
|
158 |
+
@article{zuluaga2023commonaccent,
|
159 |
+
title={CommonAccent: Exploring Large Acoustic Pretrained Models for Accent Classification Based on Common Voice},
|
160 |
+
author={Zuluaga-Gomez, Juan and Ahmed, Sara and Visockas, Danielius and Subakan, Cem},
|
161 |
+
journal={Interspeech 2023},
|
162 |
+
url={https://arxiv.org/abs/2305.18283},
|
163 |
+
year={2023}
|
164 |
+
}
|
165 |
+
```
|
166 |
+
|
167 |
+
#### Cite XLSR model
|
168 |
+
|
169 |
+
```@article{conneau2020unsupervised,
|
170 |
+
title={Unsupervised cross-lingual representation learning for speech recognition},
|
171 |
+
author={Conneau, Alexis and Baevski, Alexei and Collobert, Ronan and Mohamed, Abdelrahman and Auli, Michael},
|
172 |
+
journal={arXiv preprint arXiv:2006.13979},
|
173 |
+
year={2020}
|
174 |
+
}
|
175 |
+
```
|
176 |
+
|
177 |
+
|
178 |
+
# **Cite SpeechBrain**
|
179 |
+
Please, cite SpeechBrain if you use it for your research or business.
|
180 |
+
|
181 |
+
|
182 |
+
```bibtex
|
183 |
+
@misc{speechbrain,
|
184 |
+
title={{SpeechBrain}: A General-Purpose Speech Toolkit},
|
185 |
+
author={Mirco Ravanelli and Titouan Parcollet and Peter Plantinga and Aku Rouhe and Samuele Cornell and Loren Lugosch and Cem Subakan and Nauman Dawalatabad and Abdelwahab Heba and Jianyuan Zhong and Ju-Chieh Chou and Sung-Lin Yeh and Szu-Wei Fu and Chien-Feng Liao and Elena Rastorgueva and François Grondin and William Aris and Hwidong Na and Yan Gao and Renato De Mori and Yoshua Bengio},
|
186 |
+
year={2021},
|
187 |
+
eprint={2106.04624},
|
188 |
+
archivePrefix={arXiv},
|
189 |
+
primaryClass={eess.AS},
|
190 |
+
note={arXiv:2106.04624}
|
191 |
+
}
|
192 |
+
```
|
custom_interface.py
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from speechbrain.pretrained import Pretrained
|
3 |
+
|
4 |
+
|
5 |
+
class CustomEncoderWav2vec2Classifier(Pretrained):
|
6 |
+
"""A ready-to-use class for utterance-level classification (e.g, speaker-id,
|
7 |
+
language-id, emotion recognition, keyword spotting, etc).
|
8 |
+
|
9 |
+
The class assumes that an self-supervised encoder like wav2vec2/hubert and a classifier model
|
10 |
+
are defined in the yaml file. If you want to
|
11 |
+
convert the predicted index into a corresponding text label, please
|
12 |
+
provide the path of the label_encoder in a variable called 'lab_encoder_file'
|
13 |
+
within the yaml.
|
14 |
+
|
15 |
+
The class can be used either to run only the encoder (encode_batch()) to
|
16 |
+
extract embeddings or to run a classification step (classify_batch()).
|
17 |
+
```
|
18 |
+
|
19 |
+
Example
|
20 |
+
-------
|
21 |
+
>>> import torchaudio
|
22 |
+
>>> from speechbrain.pretrained import EncoderClassifier
|
23 |
+
>>> # Model is downloaded from the speechbrain HuggingFace repo
|
24 |
+
>>> tmpdir = getfixture("tmpdir")
|
25 |
+
>>> classifier = EncoderClassifier.from_hparams(
|
26 |
+
... source="speechbrain/spkrec-ecapa-voxceleb",
|
27 |
+
... savedir=tmpdir,
|
28 |
+
... )
|
29 |
+
|
30 |
+
>>> # Compute embeddings
|
31 |
+
>>> signal, fs = torchaudio.load("samples/audio_samples/example1.wav")
|
32 |
+
>>> embeddings = classifier.encode_batch(signal)
|
33 |
+
|
34 |
+
>>> # Classification
|
35 |
+
>>> prediction = classifier .classify_batch(signal)
|
36 |
+
"""
|
37 |
+
|
38 |
+
def __init__(self, *args, **kwargs):
|
39 |
+
super().__init__(*args, **kwargs)
|
40 |
+
|
41 |
+
def encode_batch(self, wavs, wav_lens=None, normalize=False):
|
42 |
+
"""Encodes the input audio into a single vector embedding.
|
43 |
+
|
44 |
+
The waveforms should already be in the model's desired format.
|
45 |
+
You can call:
|
46 |
+
``normalized = <this>.normalizer(signal, sample_rate)``
|
47 |
+
to get a correctly converted signal in most cases.
|
48 |
+
|
49 |
+
Arguments
|
50 |
+
---------
|
51 |
+
wavs : torch.tensor
|
52 |
+
Batch of waveforms [batch, time, channels] or [batch, time]
|
53 |
+
depending on the model. Make sure the sample rate is fs=16000 Hz.
|
54 |
+
wav_lens : torch.tensor
|
55 |
+
Lengths of the waveforms relative to the longest one in the
|
56 |
+
batch, tensor of shape [batch]. The longest one should have
|
57 |
+
relative length 1.0 and others len(waveform) / max_length.
|
58 |
+
Used for ignoring padding.
|
59 |
+
normalize : bool
|
60 |
+
If True, it normalizes the embeddings with the statistics
|
61 |
+
contained in mean_var_norm_emb.
|
62 |
+
|
63 |
+
Returns
|
64 |
+
-------
|
65 |
+
torch.tensor
|
66 |
+
The encoded batch
|
67 |
+
"""
|
68 |
+
# Manage single waveforms in input
|
69 |
+
if len(wavs.shape) == 1:
|
70 |
+
wavs = wavs.unsqueeze(0)
|
71 |
+
|
72 |
+
# Assign full length if wav_lens is not assigned
|
73 |
+
if wav_lens is None:
|
74 |
+
wav_lens = torch.ones(wavs.shape[0], device=self.device)
|
75 |
+
|
76 |
+
# Storing waveform in the specified device
|
77 |
+
wavs, wav_lens = wavs.to(self.device), wav_lens.to(self.device)
|
78 |
+
wavs = wavs.float()
|
79 |
+
|
80 |
+
# Computing features and embeddings
|
81 |
+
outputs = self.mods.wav2vec2(wavs)
|
82 |
+
|
83 |
+
# last dim will be used for AdaptativeAVG pool
|
84 |
+
outputs = self.mods.avg_pool(outputs, wav_lens)
|
85 |
+
outputs = outputs.view(outputs.shape[0], -1)
|
86 |
+
return outputs
|
87 |
+
|
88 |
+
def classify_batch(self, wavs, wav_lens=None):
|
89 |
+
"""Performs classification on the top of the encoded features.
|
90 |
+
|
91 |
+
It returns the posterior probabilities, the index and, if the label
|
92 |
+
encoder is specified it also the text label.
|
93 |
+
|
94 |
+
Arguments
|
95 |
+
---------
|
96 |
+
wavs : torch.tensor
|
97 |
+
Batch of waveforms [batch, time, channels] or [batch, time]
|
98 |
+
depending on the model. Make sure the sample rate is fs=16000 Hz.
|
99 |
+
wav_lens : torch.tensor
|
100 |
+
Lengths of the waveforms relative to the longest one in the
|
101 |
+
batch, tensor of shape [batch]. The longest one should have
|
102 |
+
relative length 1.0 and others len(waveform) / max_length.
|
103 |
+
Used for ignoring padding.
|
104 |
+
|
105 |
+
Returns
|
106 |
+
-------
|
107 |
+
out_prob
|
108 |
+
The log posterior probabilities of each class ([batch, N_class])
|
109 |
+
score:
|
110 |
+
It is the value of the log-posterior for the best class ([batch,])
|
111 |
+
index
|
112 |
+
The indexes of the best class ([batch,])
|
113 |
+
text_lab:
|
114 |
+
List with the text labels corresponding to the indexes.
|
115 |
+
(label encoder should be provided).
|
116 |
+
"""
|
117 |
+
outputs = self.encode_batch(wavs, wav_lens)
|
118 |
+
outputs = self.mods.output_mlp(outputs)
|
119 |
+
out_prob = self.hparams.softmax(outputs)
|
120 |
+
score, index = torch.max(out_prob, dim=-1)
|
121 |
+
text_lab = self.hparams.label_encoder.decode_torch(index)
|
122 |
+
return out_prob, score, index, text_lab
|
123 |
+
|
124 |
+
def classify_file(self, path):
|
125 |
+
"""Classifies the given audiofile into the given set of labels.
|
126 |
+
|
127 |
+
Arguments
|
128 |
+
---------
|
129 |
+
path : str
|
130 |
+
Path to audio file to classify.
|
131 |
+
|
132 |
+
Returns
|
133 |
+
-------
|
134 |
+
out_prob
|
135 |
+
The log posterior probabilities of each class ([batch, N_class])
|
136 |
+
score:
|
137 |
+
It is the value of the log-posterior for the best class ([batch,])
|
138 |
+
index
|
139 |
+
The indexes of the best class ([batch,])
|
140 |
+
text_lab:
|
141 |
+
List with the text labels corresponding to the indexes.
|
142 |
+
(label encoder should be provided).
|
143 |
+
"""
|
144 |
+
waveform = self.load_audio(path)
|
145 |
+
# Fake a batch:
|
146 |
+
batch = waveform.unsqueeze(0)
|
147 |
+
rel_length = torch.tensor([1.0])
|
148 |
+
outputs = self.encode_batch(batch, rel_length)
|
149 |
+
outputs = self.mods.output_mlp(outputs).squeeze(1)
|
150 |
+
out_prob = self.hparams.softmax(outputs)
|
151 |
+
score, index = torch.max(out_prob, dim=-1)
|
152 |
+
text_lab = self.hparams.label_encoder.decode_torch(index)
|
153 |
+
return out_prob, score, index, text_lab
|
154 |
+
|
155 |
+
def forward(self, wavs, wav_lens=None, normalize=False):
|
156 |
+
return self.encode_batch(
|
157 |
+
wavs=wavs, wav_lens=wav_lens, normalize=normalize
|
158 |
+
)
|
data/.hola
ADDED
File without changes
|
data/malaysia_1.wav
ADDED
Binary file (234 kB). View file
|
|
data/philippines_1.wav
ADDED
Binary file (184 kB). View file
|
|
data/scotland_1.wav
ADDED
Binary file (94.5 kB). View file
|
|
data/us_1.wav
ADDED
Binary file (98.3 kB). View file
|
|
hyperparams.yaml
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ############################################################################
|
2 |
+
# Model: WAV2VEC XLSR model for Accent Recognition (English)
|
3 |
+
# see paper: https://arxiv.org/abs/2305.18283
|
4 |
+
# ############################################################################
|
5 |
+
|
6 |
+
# Hparams NEEDED
|
7 |
+
HPARAMS_NEEDED: ["encoder_dim", "out_n_neurons", "label_encoder", "softmax"]
|
8 |
+
# Modules Needed
|
9 |
+
MODULES_NEEDED: ["wav2vec2", "avg_pool", "output_mlp"]
|
10 |
+
|
11 |
+
# Feature parameters
|
12 |
+
# wav2vec2_hub: facebook/wav2vec2-base
|
13 |
+
wav2vec2_hub: "facebook/wav2vec2-large-xlsr-53"
|
14 |
+
|
15 |
+
# Pretrain folder (HuggingFace)
|
16 |
+
pretrained_path: Jzuluaga/accent-id-commonaccent_xlsr-en-english
|
17 |
+
# URL for the biggest Fairseq english wav2vec2 model.
|
18 |
+
|
19 |
+
# parameters
|
20 |
+
encoder_dim: 1024
|
21 |
+
out_n_neurons: 16
|
22 |
+
|
23 |
+
wav2vec2: !new:speechbrain.lobes.models.huggingface_wav2vec.HuggingFaceWav2Vec2
|
24 |
+
source: !ref <wav2vec2_hub>
|
25 |
+
output_norm: True
|
26 |
+
freeze: True
|
27 |
+
save_path: wav2vec2_checkpoints
|
28 |
+
|
29 |
+
avg_pool: !new:speechbrain.nnet.pooling.StatisticsPooling
|
30 |
+
return_std: False
|
31 |
+
|
32 |
+
output_mlp: !new:speechbrain.nnet.linear.Linear
|
33 |
+
input_size: !ref <encoder_dim>
|
34 |
+
n_neurons: !ref <out_n_neurons>
|
35 |
+
bias: False
|
36 |
+
|
37 |
+
model: !new:torch.nn.ModuleList
|
38 |
+
- [!ref <output_mlp>]
|
39 |
+
|
40 |
+
modules:
|
41 |
+
wav2vec2: !ref <wav2vec2>
|
42 |
+
output_mlp: !ref <output_mlp>
|
43 |
+
avg_pool: !ref <avg_pool>
|
44 |
+
|
45 |
+
softmax: !new:speechbrain.nnet.activations.Softmax
|
46 |
+
|
47 |
+
label_encoder: !new:speechbrain.dataio.encoder.CategoricalEncoder
|
48 |
+
|
49 |
+
|
50 |
+
pretrainer: !new:speechbrain.utils.parameter_transfer.Pretrainer
|
51 |
+
loadables:
|
52 |
+
wav2vec2: !ref <wav2vec2>
|
53 |
+
model: !ref <model>
|
54 |
+
label_encoder: !ref <label_encoder>
|
55 |
+
paths:
|
56 |
+
wav2vec2: !ref <pretrained_path>/wav2vec2.ckpt
|
57 |
+
model: !ref <pretrained_path>/model.ckpt
|
58 |
+
label_encoder: !ref <pretrained_path>/label_encoder.txt
|
59 |
+
|
label_encoder.txt
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'us' => 0
|
2 |
+
'england' => 1
|
3 |
+
'australia' => 2
|
4 |
+
'indian' => 3
|
5 |
+
'canada' => 4
|
6 |
+
'bermuda' => 5
|
7 |
+
'scotland' => 6
|
8 |
+
'african' => 7
|
9 |
+
'ireland' => 8
|
10 |
+
'newzealand' => 9
|
11 |
+
'wales' => 10
|
12 |
+
'malaysia' => 11
|
13 |
+
'philippines' => 12
|
14 |
+
'singapore' => 13
|
15 |
+
'hongkong' => 14
|
16 |
+
'southatlandtic' => 15
|
17 |
+
================
|
18 |
+
'starting_index' => 0
|
model.ckpt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:52128f15268f3fb8dc61798447b2e1aaee72806707d5f8b26b14766a87778e82
|
3 |
+
size 66411
|
wav2vec2.ckpt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6f54814f95e5880e701790339f641b968676da4d82888908f232a8828178d6ba
|
3 |
+
size 1261923125
|