Update README.md
Browse files
README.md
CHANGED
@@ -31,65 +31,21 @@ model-index:
|
|
31 |
This a the demonstration of a fine-tuned Wav2vec model for Portuguese using the following [CORAA dataset](https://github.com/nilc-nlp/CORAA)
|
32 |
|
33 |
|
34 |
-
## Imports and dependencies
|
35 |
|
|
|
36 |
|
37 |
```python
|
38 |
-
%%capture
|
39 |
-
!pip install datasets
|
40 |
-
!pip install jiwer
|
41 |
-
!pip install torchaudio
|
42 |
-
!pip install transformers
|
43 |
-
!pip install soundfile
|
44 |
-
```
|
45 |
-
|
46 |
-
|
47 |
-
```python
|
48 |
-
import torchaudio
|
49 |
-
from datasets import load_dataset, load_metric
|
50 |
-
from transformers import (
|
51 |
-
Wav2Vec2ForCTC,
|
52 |
-
Wav2Vec2Processor,
|
53 |
-
)
|
54 |
-
import torch
|
55 |
-
import re
|
56 |
-
import sys
|
57 |
-
```
|
58 |
-
|
59 |
-
## Preparation
|
60 |
-
|
61 |
-
|
62 |
-
```python
|
63 |
-
chars_to_ignore_regex = '[\,\?\.\!\;\:\"]' # noqa: W605
|
64 |
-
wer = load_metric("wer")
|
65 |
-
device = "cuda"
|
66 |
-
```
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
processor = Wav2Vec2Processor.from_pretrained(model_name)
|
72 |
-
```
|
73 |
|
74 |
-
|
75 |
-
def map_to_pred(batch):
|
76 |
-
features = processor(batch["speech"], sampling_rate=batch["sampling_rate"][0], padding=True, return_tensors="pt")
|
77 |
-
input_values = features.input_values.to(device)
|
78 |
-
attention_mask = features.attention_mask.to(device)
|
79 |
-
with torch.no_grad():
|
80 |
-
logits = model(input_values, attention_mask=attention_mask).logits
|
81 |
-
pred_ids = torch.argmax(logits, dim=-1)
|
82 |
-
batch["predicted"] = processor.batch_decode(pred_ids)
|
83 |
-
batch["predicted"] = [pred.lower() for pred in batch["predicted"]]
|
84 |
-
batch["target"] = batch["sentence"]
|
85 |
-
return batch
|
86 |
```
|
87 |
-
|
88 |
-
## Tests
|
89 |
-
|
90 |
For the results consult the [CORAA article](https://arxiv.org/abs/2110.15731)
|
91 |
|
92 |
-
|
93 |
|
94 |
|
95 |
```python
|
|
|
31 |
This a the demonstration of a fine-tuned Wav2vec model for Portuguese using the following [CORAA dataset](https://github.com/nilc-nlp/CORAA)
|
32 |
|
33 |
|
|
|
34 |
|
35 |
+
# Use this model
|
36 |
|
37 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
from transformers import AutoTokenizer, Wav2Vec2ForCTC
|
40 |
+
|
41 |
+
tokenizer = AutoTokenizer.from_pretrained("Edresson/wav2vec2-large-xlsr-coraa-portuguese")
|
|
|
|
|
42 |
|
43 |
+
model = Wav2Vec2ForCTC.from_pretrained("Edresson/wav2vec2-large-xlsr-coraa-portuguese")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
```
|
45 |
+
# Results
|
|
|
|
|
46 |
For the results consult the [CORAA article](https://arxiv.org/abs/2110.15731)
|
47 |
|
48 |
+
# Example test with Common Voice Dataset
|
49 |
|
50 |
|
51 |
```python
|