iamtarun commited on
Commit
0467a60
1 Parent(s): 83ceffe

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +55 -0
README.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Wav2Vec-OSR
2
+ Finetuned facebook's wav2vec2 model for speech to text module of [The Sound Of AI open source research group](https://thesoundofaiosr.github.io/).
3
+
4
+ The original base model is pretrained and fine-tuned on 960 hours of Librispeech on 16kHz sampled speech audio. When using the model make sure that your speech input is also sampled at 16Khz.
5
+
6
+ ## Paper
7
+
8
+ Authors: Alexei Baevski, Henry Zhou, Abdelrahman Mohamed, Michael Auli
9
+
10
+ ## Abstract
11
+
12
+ We show for the first time that learning powerful representations from speech audio alone followed by fine-tuning on transcribed speech can outperform the best semi-supervised methods while being conceptually simpler. wav2vec 2.0 masks the speech input in the latent space and solves a contrastive task defined over a quantization of the latent representations which are jointly learned. Experiments using all labeled data of Librispeech achieve 1.8/3.3 WER on the clean/other test sets. When lowering the amount of labeled data to one hour, wav2vec 2.0 outperforms the previous state of the art on the 100 hour subset while using 100 times less labeled data. Using just ten minutes of labeled data and pre-training on 53k hours of unlabeled data still achieves 4.8/8.2 WER. This demonstrates the feasibility of speech recognition with limited amounts of labeled data.
13
+
14
+ The original model can be found under https://github.com/pytorch/fairseq/tree/master/examples/wav2vec#wav2vec-20.
15
+ The original model can also be found in hugging face public model repository [here](https://huggingface.co/facebook/wav2vec2-base-960h)
16
+
17
+ ## Usage
18
+ ```python
19
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
20
+ from datasets import load_dataset
21
+ import soundfile as sf
22
+ import torch
23
+
24
+ # load tokenizer, data_processor and model
25
+ tokenizer = Wav2Vec2CTCTokenizer.from_pretrained("iamtarun/wav2vec-osr")
26
+ processor = Wav2Vec2Processor.from_pretrained("iamtarun/wav2vec-osr")
27
+ model = Wav2Vec2ForCTC.from_pretrained("iamtarun/wav2vec-osr")
28
+
29
+ model = model.eval()
30
+
31
+ device = "cuda" if torch.cuda.is_available() else "cpu"
32
+ model = model.to(device)
33
+
34
+ # define function to read in sound file
35
+ def map_to_array(batch):
36
+ speech, _ = sf.read(batch["file"])
37
+ batch["speech"] = speech
38
+ return batch
39
+
40
+ # load dummy dataset and read soundfiles
41
+ ds = load_dataset("patrickvonplaten/librispeech_asr_dummy", "clean", split="validation")
42
+ ds = ds.map(map_to_array)
43
+
44
+ # speech data is passed to data processor whose output is then fed to model
45
+ input_values = processor(ds["speech"][:2], sampling_rate=rate, return_tensors="pt").input_values.to(device)
46
+ logits = model(input_values).logits
47
+
48
+ # retrieve logits
49
+ logits = model(input_values).logits
50
+
51
+ # take argmax and decode
52
+ predicted_ids = torch.argmax(logits, dim =-1)
53
+ transcriptions = tokenizer.decode(predicted_ids[0])
54
+ print(transcriptions)
55
+ ```