Update README.md
Browse files
README.md
CHANGED
@@ -87,15 +87,17 @@ import torch
|
|
87 |
from datasets import load_dataset
|
88 |
from transformers import AutoModelForCTC, AutoProcessor
|
89 |
import torchaudio.functional as F
|
|
|
90 |
model_id = "Maniac/wav2vec2-xls-r-urdu"
|
91 |
-
|
|
|
92 |
sample = next(sample_iter)
|
93 |
resampled_audio = F.resample(torch.tensor(sample["audio"]["array"]), 48_000, 16_000).numpy()
|
94 |
model = AutoModelForCTC.from_pretrained(model_id)
|
95 |
processor = AutoProcessor.from_pretrained(model_id)
|
96 |
input_values = processor(resampled_audio, return_tensors="pt").input_values
|
|
|
97 |
with torch.no_grad():
|
98 |
logits = model(input_values).logits
|
99 |
transcription = processor.batch_decode(logits.numpy()).text
|
100 |
-
# => "jag lämnade grovjobbet åt honom"
|
101 |
```
|
|
|
87 |
from datasets import load_dataset
|
88 |
from transformers import AutoModelForCTC, AutoProcessor
|
89 |
import torchaudio.functional as F
|
90 |
+
|
91 |
model_id = "Maniac/wav2vec2-xls-r-urdu"
|
92 |
+
|
93 |
+
sample_iter = iter(load_dataset("mozilla-foundation/common_voice_7_0", "ur", split="test", streaming=True, use_auth_token=True))
|
94 |
sample = next(sample_iter)
|
95 |
resampled_audio = F.resample(torch.tensor(sample["audio"]["array"]), 48_000, 16_000).numpy()
|
96 |
model = AutoModelForCTC.from_pretrained(model_id)
|
97 |
processor = AutoProcessor.from_pretrained(model_id)
|
98 |
input_values = processor(resampled_audio, return_tensors="pt").input_values
|
99 |
+
|
100 |
with torch.no_grad():
|
101 |
logits = model(input_values).logits
|
102 |
transcription = processor.batch_decode(logits.numpy()).text
|
|
|
103 |
```
|