marma commited on
Commit
d1ed49d
1 Parent(s): fa59e50

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +28 -1
README.md CHANGED
@@ -37,4 +37,31 @@ model-index:
37
  value: 17.37743757973392
38
  ---
39
  # Wav2vec 2.0 large-voxpopuli-sv-swedish
40
- Finetuned version of Facebooks [VoxPopuli-sv large](https://huggingface.co/facebook/wav2vec2-large-sv-voxpopuli) model. WER for NST + Common Voice test set (2% of total sentences) is **5.19%**. WER for Common Voice test set is **17.38%**.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  value: 17.37743757973392
38
  ---
39
  # Wav2vec 2.0 large-voxpopuli-sv-swedish
40
+ Finetuned version of Facebooks [VoxPopuli-sv large](https://huggingface.co/facebook/wav2vec2-large-sv-voxpopuli) model. WER for NST + Common Voice test set (2% of total sentences) is **5.19%**. WER for Common Voice test set is **17.38%**.
41
+
42
+ When using this model, make sure that your speech input is sampled at 16kHz.
43
+ ## Usage
44
+ The model can be used directly (without a language model) as follows:
45
+ ```python
46
+ import torch
47
+ import torchaudio
48
+ from datasets import load_dataset
49
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
50
+ test_dataset = load_dataset("common_voice", "sv-SE", split="test[:2%]").
51
+ processor = Wav2Vec2Processor.from_pretrained("KBLab/wav2vec2-large-voxpopuli-sv-swedish")
52
+ model = Wav2Vec2ForCTC.from_pretrained("KBLab/wav2vec2-large-voxpopuli-sv-swedish")
53
+ resampler = torchaudio.transforms.Resample(48_000, 16_000)
54
+ # Preprocessing the datasets.
55
+ # We need to read the aduio files as arrays
56
+ def speech_file_to_array_fn(batch):
57
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
58
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
59
+ return batch
60
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
61
+ inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
62
+ with torch.no_grad():
63
+ logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
64
+ predicted_ids = torch.argmax(logits, dim=-1)
65
+ print("Prediction:", processor.batch_decode(predicted_ids))
66
+ print("Reference:", test_dataset["sentence"][:2])
67
+ ```