Compare commits
No commits in common. "54074b1c16f4de6a5ad59affb4caa8f2ea03a119" and "ea0bff11d7090f441908e47765d058d906c2fcf4" have entirely different histories.
54074b1c16
...
ea0bff11d7
|
@ -14,4 +14,3 @@
|
|||
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
|
|
68
README.md
68
README.md
|
@ -6,39 +6,7 @@ tags:
|
|||
- speech
|
||||
- audio
|
||||
- automatic-speech-recognition
|
||||
- hf-asr-leaderboard
|
||||
license: apache-2.0
|
||||
model-index:
|
||||
- name: wav2vec2-large-960h-lv60
|
||||
results:
|
||||
- task:
|
||||
name: Automatic Speech Recognition
|
||||
type: automatic-speech-recognition
|
||||
dataset:
|
||||
name: LibriSpeech (clean)
|
||||
type: librispeech_asr
|
||||
config: clean
|
||||
split: test
|
||||
args:
|
||||
language: en
|
||||
metrics:
|
||||
- name: Test WER
|
||||
type: wer
|
||||
value: 1.9
|
||||
- task:
|
||||
name: Automatic Speech Recognition
|
||||
type: automatic-speech-recognition
|
||||
dataset:
|
||||
name: LibriSpeech (other)
|
||||
type: librispeech_asr
|
||||
config: other
|
||||
split: test
|
||||
args:
|
||||
language: en
|
||||
metrics:
|
||||
- name: Test WER
|
||||
type: wer
|
||||
value: 3.9
|
||||
---
|
||||
|
||||
# Wav2Vec2-Large-960h-Lv60 + Self-Training
|
||||
|
@ -63,26 +31,34 @@ The original model can be found under https://github.com/pytorch/fairseq/tree/ma
|
|||
To transcribe audio files the model can be used as a standalone acoustic model as follows:
|
||||
|
||||
```python
|
||||
from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
|
||||
from transformers import Wav2Vec2Tokenizer, Wav2Vec2ForCTC
|
||||
from datasets import load_dataset
|
||||
import soundfile as sf
|
||||
import torch
|
||||
|
||||
# load model and processor
|
||||
processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-large-960h-lv60-self")
|
||||
# load model and tokenizer
|
||||
tokenizer = Wav2Vec2Tokenizer.from_pretrained("facebook/wav2vec2-large-960h-lv60-self")
|
||||
model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-large-960h-lv60-self")
|
||||
|
||||
# define function to read in sound file
|
||||
def map_to_array(batch):
|
||||
speech, _ = sf.read(batch["file"])
|
||||
batch["speech"] = speech
|
||||
return batch
|
||||
|
||||
# load dummy dataset and read soundfiles
|
||||
ds = load_dataset("patrickvonplaten/librispeech_asr_dummy", "clean", split="validation")
|
||||
ds = ds.map(map_to_array)
|
||||
|
||||
# tokenize
|
||||
input_values = processor(ds[0]["audio"]["array"], return_tensors="pt", padding="longest").input_values
|
||||
input_values = tokenizer(ds["speech"][:2], return_tensors="pt", padding="longest").input_values # Batch size 1
|
||||
|
||||
# retrieve logits
|
||||
logits = model(input_values).logits
|
||||
|
||||
# take argmax and decode
|
||||
predicted_ids = torch.argmax(logits, dim=-1)
|
||||
transcription = processor.batch_decode(predicted_ids)
|
||||
transcription = tokenizer.batch_decode(predicted_ids)
|
||||
```
|
||||
|
||||
## Evaluation
|
||||
|
@ -91,7 +67,8 @@ To transcribe audio files the model can be used as a standalone acoustic model a
|
|||
|
||||
```python
|
||||
from datasets import load_dataset
|
||||
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
||||
from transformers import Wav2Vec2ForCTC, Wav2Vec2Tokenizer
|
||||
import soundfile as sf
|
||||
import torch
|
||||
from jiwer import wer
|
||||
|
||||
|
@ -99,10 +76,17 @@ from jiwer import wer
|
|||
librispeech_eval = load_dataset("librispeech_asr", "clean", split="test")
|
||||
|
||||
model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-large-960h-lv60-self").to("cuda")
|
||||
processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-large-960h-lv60-self")
|
||||
tokenizer = Wav2Vec2Tokenizer.from_pretrained("facebook/wav2vec2-large-960h-lv60-self")
|
||||
|
||||
def map_to_array(batch):
|
||||
speech, _ = sf.read(batch["file"])
|
||||
batch["speech"] = speech
|
||||
return batch
|
||||
|
||||
librispeech_eval = librispeech_eval.map(map_to_array)
|
||||
|
||||
def map_to_pred(batch):
|
||||
inputs = processor(batch["audio"]["array"], return_tensors="pt", padding="longest")
|
||||
inputs = tokenizer(batch["speech"], return_tensors="pt", padding="longest")
|
||||
input_values = inputs.input_values.to("cuda")
|
||||
attention_mask = inputs.attention_mask.to("cuda")
|
||||
|
||||
|
@ -110,11 +94,11 @@ def map_to_pred(batch):
|
|||
logits = model(input_values, attention_mask=attention_mask).logits
|
||||
|
||||
predicted_ids = torch.argmax(logits, dim=-1)
|
||||
transcription = processor.batch_decode(predicted_ids)
|
||||
transcription = tokenizer.batch_decode(predicted_ids)
|
||||
batch["transcription"] = transcription
|
||||
return batch
|
||||
|
||||
result = librispeech_eval.map(map_to_pred, remove_columns=["audio"])
|
||||
result = librispeech_eval.map(map_to_pred, batched=True, batch_size=16, remove_columns=["speech"])
|
||||
|
||||
print("WER:", wer(result["text"], result["transcription"]))
|
||||
```
|
||||
|
|
28
config.json
28
config.json
|
@ -1,14 +1,7 @@
|
|||
{
|
||||
"_name_or_path": "facebook/wav2vec2-large-960h-lv60-self",
|
||||
"activation_dropout": 0.1,
|
||||
"apply_spec_augment": true,
|
||||
"architectures": [
|
||||
"Wav2Vec2ForCTC"
|
||||
],
|
||||
"attention_dropout": 0.1,
|
||||
"bos_token_id": 1,
|
||||
"codevector_dim": 256,
|
||||
"contrastive_logits_temperature": 0.1,
|
||||
"conv_bias": true,
|
||||
"conv_dim": [
|
||||
512,
|
||||
|
@ -37,41 +30,22 @@
|
|||
2,
|
||||
2
|
||||
],
|
||||
"ctc_loss_reduction": "sum",
|
||||
"ctc_zero_infinity": false,
|
||||
"diversity_loss_weight": 0.1,
|
||||
"do_stable_layer_norm": true,
|
||||
"eos_token_id": 2,
|
||||
"feat_extract_activation": "gelu",
|
||||
"feat_extract_dropout": 0.0,
|
||||
"feat_extract_norm": "layer",
|
||||
"feat_proj_dropout": 0.1,
|
||||
"feat_quantizer_dropout": 0.0,
|
||||
"final_dropout": 0.1,
|
||||
"gradient_checkpointing": false,
|
||||
"hidden_act": "gelu",
|
||||
"hidden_dropout": 0.1,
|
||||
"hidden_dropout_prob": 0.1,
|
||||
"hidden_size": 1024,
|
||||
"initializer_range": 0.02,
|
||||
"intermediate_size": 4096,
|
||||
"layer_norm_eps": 1e-05,
|
||||
"layerdrop": 0.1,
|
||||
"mask_feature_length": 10,
|
||||
"mask_feature_prob": 0.0,
|
||||
"mask_time_length": 10,
|
||||
"mask_time_prob": 0.05,
|
||||
"model_type": "wav2vec2",
|
||||
"num_attention_heads": 16,
|
||||
"num_codevector_groups": 2,
|
||||
"num_codevectors_per_group": 320,
|
||||
"num_conv_pos_embedding_groups": 16,
|
||||
"num_conv_pos_embeddings": 128,
|
||||
"num_feat_extract_layers": 7,
|
||||
"num_hidden_layers": 24,
|
||||
"num_negatives": 100,
|
||||
"pad_token_id": 0,
|
||||
"proj_codevector_dim": 256,
|
||||
"transformers_version": "4.7.0.dev0",
|
||||
"transformers_version": "4.3.0.dev0",
|
||||
"vocab_size": 32
|
||||
}
|
||||
|
|
BIN
flax_model.msgpack (Stored with Git LFS)
BIN
flax_model.msgpack (Stored with Git LFS)
Binary file not shown.
BIN
tf_model.h5 (Stored with Git LFS)
BIN
tf_model.h5 (Stored with Git LFS)
Binary file not shown.
Loading…
Reference in New Issue