patrickvonplaten commited on
Commit
5780d16
2 Parent(s): 44f4f13 20909ce

Merge branch 'main' of https://huggingface.co/microsoft/unispeech-1350-en-90-it-ft-1h into main

Browse files
Files changed (1) hide show
  1. README.md +119 -0
README.md ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - it
4
+ datasets:
5
+ - common_voice
6
+ tags:
7
+ - audio
8
+ - automatic-speech-recognition
9
+ ---
10
+
11
+ # UniSpeech-Large-plus ITALIAN
12
+
13
+ [Microsoft's UniSpeech](https://www.microsoft.com/en-us/research/publication/unispeech-unified-speech-representation-learning-with-labeled-and-unlabeled-data/)
14
+
15
+ The large model pretrained on 16kHz sampled speech audio and phonetic labels and consequently fine-tuned on 1h of Italian phonemes.
16
+ When using the model make sure that your speech input is also sampled at 16kHz and your text in converted into a sequence of phonemes.
17
+
18
+ [Paper: UniSpeech: Unified Speech Representation Learning
19
+ with Labeled and Unlabeled Data](https://arxiv.org/abs/2101.07597)
20
+
21
+ Authors: Chengyi Wang, Yu Wu, Yao Qian, Kenichi Kumatani, Shujie Liu, Furu Wei, Michael Zeng, Xuedong Huang
22
+
23
+ **Abstract**
24
+ *In this paper, we propose a unified pre-training approach called UniSpeech to learn speech representations with both unlabeled and labeled data, in which supervised phonetic CTC learning and phonetically-aware contrastive self-supervised learning are conducted in a multi-task learning manner. The resultant representations can capture information more correlated with phonetic structures and improve the generalization across languages and domains. We evaluate the effectiveness of UniSpeech for cross-lingual representation learning on public CommonVoice corpus. The results show that UniSpeech outperforms self-supervised pretraining and supervised transfer learning for speech recognition by a maximum of 13.4% and 17.8% relative phone error rate reductions respectively (averaged over all testing languages). The transferability of UniSpeech is also demonstrated on a domain-shift speech recognition task, i.e., a relative word error rate reduction of 6% against the previous approach.*
25
+
26
+ The original model can be found under https://github.com/microsoft/UniSpeech/tree/main/UniSpeech.
27
+
28
+ # Usage
29
+
30
+ This is an speech model that has been fine-tuned on phoneme classification.
31
+
32
+ ## Inference
33
+
34
+ ```python
35
+ import torch
36
+ from datasets import load_dataset
37
+ from transformers import AutoModelForCTC, AutoProcessor
38
+ import torchaudio.functional as F
39
+
40
+ model_id = "microsoft/unispeech-1350-en-90-it-ft-1h"
41
+
42
+ sample = next(iter(load_dataset("common_voice", "it", split="test", streaming=True)))
43
+ resampled_audio = F.resample(torch.tensor(sample["audio"]["array"]), 48_000, 16_000).numpy()
44
+
45
+ model = AutoModelForCTC.from_pretrained(model_id)
46
+ processor = AutoProcessor.from_pretrained(model_id)
47
+
48
+ input_values = processor(resampled_audio, return_tensors="pt").input_values
49
+
50
+ with torch.no_grad():
51
+ logits = model(input_values).logits
52
+
53
+ prediction_ids = torch.argmax(logits, dim=-1)
54
+ transcription = processor.batch_decode(prediction_ids)
55
+ # => 'bien y qué regalo vas a abrir primero'
56
+ ```
57
+
58
+ ## Evaluation
59
+
60
+ ```python
61
+ from datasets import load_dataset, load_metric
62
+ import datasets
63
+ import torch
64
+ from transformers import AutoModelForCTC, AutoProcessor
65
+
66
+ model_id = "microsoft/unispeech-1350-en-90-it-ft-1h"
67
+
68
+ ds = load_dataset("mozilla-foundation/common_voice_3_0", "it", split="train+validation+test+other")
69
+ wer = load_metric("wer")
70
+
71
+ model = AutoModelForCTC.from_pretrained(model_id)
72
+ processor = AutoProcessor.from_pretrained(model_id)
73
+
74
+ # taken from
75
+ # https://github.com/microsoft/UniSpeech/blob/main/UniSpeech/examples/unispeech/data/it/phonesMatches_reduced.json
76
+
77
+ with open("./testSeqs_uniform_new_version.text", "r") as f:
78
+ lines = f.readlines()
79
+
80
+
81
+ # retrieve ids model is evaluated on
82
+ ids = [x.split("\t")[0] for x in lines]
83
+
84
+
85
+ ds = ds.filter(lambda p: p.split("/")[-1].split(".")[0] in ids, input_columns=["path"])
86
+
87
+ ds = ds.cast_column("audio", datasets.Audio(sampling_rate=16_000))
88
+
89
+
90
+ def decode(batch):
91
+ input_values = processor(batch["audio"]["array"], return_tensors="pt", sampling_rate=16_000)
92
+ logits = model(input_values).logits
93
+
94
+ pred_ids = torch.argmax(logits, axis=-1)
95
+
96
+ batch["prediction"] = processor.batch_decode(pred_ids)
97
+ batch["target"] = processor.tokenizer.phonemize(batch["sentence"])
98
+
99
+ return batch
100
+
101
+
102
+ out = ds.map(decode, remove_columns=ds.column_names)
103
+ per = wer.compute(predictions=out["prediction"], references=out["target"])
104
+
105
+ print("per", per)
106
+ # -> should give per 0.06685252146070828
107
+ ```
108
+
109
+ # Contribution
110
+
111
+ The model was contributed by [cywang](https://huggingface.co/cywang) and [patrickvonplaten](https://huggingface.co/patrickvonplaten).
112
+
113
+ # License
114
+
115
+ The official license can be found [here](https://github.com/microsoft/UniSpeech/blob/main/LICENSE)
116
+
117
+ See *UniSpeeech-L^{+}* - *it*:
118
+
119
+ ![design](https://raw.githubusercontent.com/patrickvonplaten/scientific_images/master/unispeech_results.png)