marma commited on
Commit
d6ef8eb
1 Parent(s): 0b97a39

Update README.md

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