Commit
·
b1aabb0
1
Parent(s):
e5ce079
Upload model
Browse files- README.md +96 -0
- config.json +108 -0
- preprocessor_config.json +9 -0
- pytorch_model.bin +3 -0
README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
datasets:
|
| 4 |
+
- superb
|
| 5 |
+
tags:
|
| 6 |
+
- speech
|
| 7 |
+
- audio
|
| 8 |
+
- wav2vec2
|
| 9 |
+
- audio-classification
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# Wav2Vec2-Large for Keyword Spotting
|
| 14 |
+
|
| 15 |
+
## Model description
|
| 16 |
+
|
| 17 |
+
This is a ported version of
|
| 18 |
+
[S3PRL's Wav2Vec2 for the SUPERB Keyword Spotting task](https://github.com/s3prl/s3prl/tree/master/s3prl/downstream/speech_commands).
|
| 19 |
+
|
| 20 |
+
The base model is [wav2vec2-large-lv60](https://huggingface.co/facebook/wav2vec2-large-lv60), which is pretrained on 16kHz
|
| 21 |
+
sampled speech audio. When using the model make sure that your speech input is also sampled at 16Khz.
|
| 22 |
+
|
| 23 |
+
For more information refer to [SUPERB: Speech processing Universal PERformance Benchmark](https://arxiv.org/abs/2105.01051)
|
| 24 |
+
|
| 25 |
+
## Task and dataset description
|
| 26 |
+
|
| 27 |
+
Keyword Spotting (KS) detects preregistered keywords by classifying utterances into a predefined set of
|
| 28 |
+
words. The task is usually performed on-device for the fast response time. Thus, accuracy, model size, and
|
| 29 |
+
inference time are all crucial. SUPERB uses the widely used
|
| 30 |
+
[Speech Commands dataset v1.0](https://www.tensorflow.org/datasets/catalog/speech_commands) for the task.
|
| 31 |
+
The dataset consists of ten classes of keywords, a class for silence, and an unknown class to include the
|
| 32 |
+
false positive.
|
| 33 |
+
|
| 34 |
+
For the original model's training and evaluation instructions refer to the
|
| 35 |
+
[S3PRL downstream task README](https://github.com/s3prl/s3prl/tree/master/s3prl/downstream#ks-keyword-spotting).
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
## Usage examples
|
| 39 |
+
|
| 40 |
+
You can use the model via the Audio Classification pipeline:
|
| 41 |
+
```python
|
| 42 |
+
from datasets import load_dataset
|
| 43 |
+
from transformers import pipeline
|
| 44 |
+
|
| 45 |
+
dataset = load_dataset("anton-l/superb_demo", "ks", split="test")
|
| 46 |
+
|
| 47 |
+
classifier = pipeline("audio-classification", model="superb/wav2vec2-large-superb-ks")
|
| 48 |
+
labels = classifier(dataset[0]["file"], top_k=5)
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
Or use the model directly:
|
| 52 |
+
```python
|
| 53 |
+
import torch
|
| 54 |
+
from datasets import load_dataset
|
| 55 |
+
from transformers import Wav2Vec2ForSequenceClassification, Wav2Vec2FeatureExtractor
|
| 56 |
+
from torchaudio.sox_effects import apply_effects_file
|
| 57 |
+
|
| 58 |
+
effects = [["channels", "1"], ["rate", "16000"], ["gain", "-3.0"]]
|
| 59 |
+
def map_to_array(example):
|
| 60 |
+
speech, _ = apply_effects_file(example["file"], effects)
|
| 61 |
+
example["speech"] = speech.squeeze(0).numpy()
|
| 62 |
+
return example
|
| 63 |
+
|
| 64 |
+
# load a demo dataset and read audio files
|
| 65 |
+
dataset = load_dataset("anton-l/superb_demo", "ks", split="test")
|
| 66 |
+
dataset = dataset.map(map_to_array)
|
| 67 |
+
|
| 68 |
+
model = Wav2Vec2ForSequenceClassification.from_pretrained("superb/wav2vec2-large-superb-ks")
|
| 69 |
+
feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained("superb/wav2vec2-large-superb-ks")
|
| 70 |
+
|
| 71 |
+
# compute attention masks and normalize the waveform if needed
|
| 72 |
+
inputs = feature_extractor(dataset[:4]["speech"], sampling_rate=16000, padding=True, return_tensors="pt")
|
| 73 |
+
|
| 74 |
+
logits = model(**inputs).logits
|
| 75 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
| 76 |
+
labels = [model.config.id2label[_id] for _id in predicted_ids.tolist()]
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
## Eval results
|
| 80 |
+
|
| 81 |
+
The evaluation metric is accuracy.
|
| 82 |
+
|
| 83 |
+
| | **s3prl** | **transformers** |
|
| 84 |
+
|--------|-----------|------------------|
|
| 85 |
+
|**test**| `0.9666` | `N/A` |
|
| 86 |
+
|
| 87 |
+
### BibTeX entry and citation info
|
| 88 |
+
|
| 89 |
+
```bibtex
|
| 90 |
+
@article{yang2021superb,
|
| 91 |
+
title={SUPERB: Speech processing Universal PERformance Benchmark},
|
| 92 |
+
author={Yang, Shu-wen and Chi, Po-Han and Chuang, Yung-Sung and Lai, Cheng-I Jeff and Lakhotia, Kushal and Lin, Yist Y and Liu, Andy T and Shi, Jiatong and Chang, Xuankai and Lin, Guan-Ting and others},
|
| 93 |
+
journal={arXiv preprint arXiv:2105.01051},
|
| 94 |
+
year={2021}
|
| 95 |
+
}
|
| 96 |
+
```
|
config.json
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "facebook/wav2vec2-large-lv60",
|
| 3 |
+
"activation_dropout": 0.1,
|
| 4 |
+
"apply_spec_augment": true,
|
| 5 |
+
"architectures": [
|
| 6 |
+
"Wav2Vec2ForSequenceClassification"
|
| 7 |
+
],
|
| 8 |
+
"attention_dropout": 0.1,
|
| 9 |
+
"bos_token_id": 1,
|
| 10 |
+
"classifier_proj_size": 256,
|
| 11 |
+
"codevector_dim": 768,
|
| 12 |
+
"contrastive_logits_temperature": 0.1,
|
| 13 |
+
"conv_bias": true,
|
| 14 |
+
"conv_dim": [
|
| 15 |
+
512,
|
| 16 |
+
512,
|
| 17 |
+
512,
|
| 18 |
+
512,
|
| 19 |
+
512,
|
| 20 |
+
512,
|
| 21 |
+
512
|
| 22 |
+
],
|
| 23 |
+
"conv_kernel": [
|
| 24 |
+
10,
|
| 25 |
+
3,
|
| 26 |
+
3,
|
| 27 |
+
3,
|
| 28 |
+
3,
|
| 29 |
+
2,
|
| 30 |
+
2
|
| 31 |
+
],
|
| 32 |
+
"conv_stride": [
|
| 33 |
+
5,
|
| 34 |
+
2,
|
| 35 |
+
2,
|
| 36 |
+
2,
|
| 37 |
+
2,
|
| 38 |
+
2,
|
| 39 |
+
2
|
| 40 |
+
],
|
| 41 |
+
"ctc_loss_reduction": "sum",
|
| 42 |
+
"ctc_zero_infinity": false,
|
| 43 |
+
"diversity_loss_weight": 0.1,
|
| 44 |
+
"do_stable_layer_norm": true,
|
| 45 |
+
"eos_token_id": 2,
|
| 46 |
+
"feat_extract_activation": "gelu",
|
| 47 |
+
"feat_extract_dropout": 0.0,
|
| 48 |
+
"feat_extract_norm": "layer",
|
| 49 |
+
"feat_proj_dropout": 0.1,
|
| 50 |
+
"feat_quantizer_dropout": 0.0,
|
| 51 |
+
"final_dropout": 0.1,
|
| 52 |
+
"gradient_checkpointing": false,
|
| 53 |
+
"hidden_act": "gelu",
|
| 54 |
+
"hidden_dropout": 0.1,
|
| 55 |
+
"hidden_dropout_prob": 0.1,
|
| 56 |
+
"hidden_size": 1024,
|
| 57 |
+
"id2label": {
|
| 58 |
+
"0": "yes",
|
| 59 |
+
"1": "no",
|
| 60 |
+
"2": "up",
|
| 61 |
+
"3": "down",
|
| 62 |
+
"4": "left",
|
| 63 |
+
"5": "right",
|
| 64 |
+
"6": "on",
|
| 65 |
+
"7": "off",
|
| 66 |
+
"8": "stop",
|
| 67 |
+
"9": "go",
|
| 68 |
+
"10": "_unknown_",
|
| 69 |
+
"11": "_silence_"
|
| 70 |
+
},
|
| 71 |
+
"initializer_range": 0.02,
|
| 72 |
+
"intermediate_size": 4096,
|
| 73 |
+
"label2id": {
|
| 74 |
+
"_silence_": 11,
|
| 75 |
+
"_unknown_": 10,
|
| 76 |
+
"down": 3,
|
| 77 |
+
"go": 9,
|
| 78 |
+
"left": 4,
|
| 79 |
+
"no": 1,
|
| 80 |
+
"off": 7,
|
| 81 |
+
"on": 6,
|
| 82 |
+
"right": 5,
|
| 83 |
+
"stop": 8,
|
| 84 |
+
"up": 2,
|
| 85 |
+
"yes": 0
|
| 86 |
+
},
|
| 87 |
+
"layer_norm_eps": 1e-05,
|
| 88 |
+
"layerdrop": 0.1,
|
| 89 |
+
"mask_feature_length": 10,
|
| 90 |
+
"mask_feature_prob": 0.0,
|
| 91 |
+
"mask_time_length": 10,
|
| 92 |
+
"mask_time_prob": 0.05,
|
| 93 |
+
"model_type": "wav2vec2",
|
| 94 |
+
"num_attention_heads": 16,
|
| 95 |
+
"num_codevector_groups": 2,
|
| 96 |
+
"num_codevectors_per_group": 320,
|
| 97 |
+
"num_conv_pos_embedding_groups": 16,
|
| 98 |
+
"num_conv_pos_embeddings": 128,
|
| 99 |
+
"num_feat_extract_layers": 7,
|
| 100 |
+
"num_hidden_layers": 24,
|
| 101 |
+
"num_negatives": 100,
|
| 102 |
+
"pad_token_id": 0,
|
| 103 |
+
"proj_codevector_dim": 768,
|
| 104 |
+
"torch_dtype": "float32",
|
| 105 |
+
"transformers_version": "4.11.0.dev0",
|
| 106 |
+
"use_weighted_layer_sum": true,
|
| 107 |
+
"vocab_size": 32
|
| 108 |
+
}
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"do_normalize": false,
|
| 3 |
+
"feature_extractor_type": "Wav2Vec2FeatureExtractor",
|
| 4 |
+
"feature_size": 1,
|
| 5 |
+
"padding_side": "right",
|
| 6 |
+
"padding_value": 0.0,
|
| 7 |
+
"return_attention_mask": true,
|
| 8 |
+
"sampling_rate": 16000
|
| 9 |
+
}
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:be36f743cf72df29a247523f697f35fab379511ea935547fda6fa79ca9c9e874
|
| 3 |
+
size 1262980715
|