commit 4c37b13fbc82c7bb08e5a7393827edcfee3d8558 Author: ModelHub XC Date: Thu May 14 22:35:55 2026 +0800 初始化项目,由ModelHub XC社区提供模型 Model: khanhld/wav2vec2-base-vietnamese-160h Source: Original Platform diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..ac481c8 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,27 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.parquet filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zstandard filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text diff --git a/README.md b/README.md new file mode 100644 index 0000000..9187c88 --- /dev/null +++ b/README.md @@ -0,0 +1,178 @@ +--- +language: vi +datasets: +- vivos +- common_voice +- FOSD +- VLSP +metrics: +- wer +pipeline_tag: automatic-speech-recognition +tags: +- audio +- speech +- Transformer +- wav2vec2 +- automatic-speech-recognition +- vietnamese +license: cc-by-nc-4.0 +widget: +- example_title: common_voice_vi_30519758.mp3 + src: https://huggingface.co/khanhld/wav2vec2-base-vietnamese-160h/raw/main/examples/common_voice_vi_30519758.mp3 +- example_title: VIVOSDEV15_020.wav + src: https://huggingface.co/khanhld/wav2vec2-base-vietnamese-160h/raw/main/examples/VIVOSDEV15_020.wav +model-index: +- name: Wav2vec2 Base Vietnamese 160h + results: + - task: + name: Speech Recognition + type: automatic-speech-recognition + dataset: + name: common-voice-vietnamese + type: common_voice + args: vi + metrics: + - name: Test WER + type: wer + value: 10.78 + - task: + name: Speech Recognition + type: automatic-speech-recognition + dataset: + name: VIVOS + type: vivos + args: vi + metrics: + - name: Test WER + type: wer + value: 15.05 +--- +[![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/wav2vec2-base-vietnamese-160h/speech-recognition-on-common-voice-vi)](https://paperswithcode.com/sota/speech-recognition-on-common-voice-vi?p=wav2vec2-base-vietnamese-160h) +[![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/wav2vec2-base-vietnamese-160h/speech-recognition-on-vivos)](https://paperswithcode.com/sota/speech-recognition-on-vivos?p=wav2vec2-base-vietnamese-160h) + +# Vietnamese Speech Recognition using Wav2vec 2.0 +### Table of contents +1. [Model Description](#description) +2. [Implementation](#implementation) +3. [Benchmark Result](#benchmark) +4. [Example Usage](#example) +5. [Evaluation](#evaluation) +6. [Citation](#citation) +7. [Contact](#contact) + + +### Model Description +Fine-tuned the Wav2vec2-based model on about 160 hours of Vietnamese speech dataset from different resources, including [VIOS](https://huggingface.co/datasets/vivos), [COMMON VOICE](https://huggingface.co/datasets/mozilla-foundation/common_voice_8_0), [FOSD](https://data.mendeley.com/datasets/k9sxg2twv4/4) and [VLSP 100h](https://drive.google.com/file/d/1vUSxdORDxk-ePUt-bUVDahpoXiqKchMx/view). We have not yet incorporated the Language Model into our ASR system but still gained a promising result. + +### Implementation +We also provide code for Pre-training and Fine-tuning the Wav2vec2 model. If you wish to train on your dataset, check it out here: +- [Pre-train code](https://github.com/khanld/Wav2vec2-Pretraining) +- [Fine-tune code](https://github.com/khanld/ASR-Wa2vec-Finetune) + + +### Benchmark WER Result +| | [VIVOS](https://huggingface.co/datasets/vivos) | [COMMON VOICE 8.0](https://huggingface.co/datasets/mozilla-foundation/common_voice_8_0) | +|---|---|---| +|without LM| 15.05 | 10.78 | +|with LM| in progress | in progress | + + +### Example Usage [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1blz1KclnIfbOp8o2fW3WJgObOQ9SMGBo?usp=sharing) +```python +from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC +import librosa +import torch + +device = torch.device("cuda" if torch.cuda.is_available() else "cpu") + +processor = Wav2Vec2Processor.from_pretrained("khanhld/wav2vec2-base-vietnamese-160h") +model = Wav2Vec2ForCTC.from_pretrained("khanhld/wav2vec2-base-vietnamese-160h") +model.to(device) + +def transcribe(wav): + input_values = processor(wav, sampling_rate=16000, return_tensors="pt").input_values + logits = model(input_values.to(device)).logits + pred_ids = torch.argmax(logits, dim=-1) + pred_transcript = processor.batch_decode(pred_ids)[0] + return pred_transcript + + +wav, _ = librosa.load('path/to/your/audio/file', sr = 16000) +print(f"transcript: {transcribe(wav)}") + +``` + + +### Evaluation [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1XQCq4YGLnl23tcKmYeSwaksro4IgC_Yi?usp=sharing) + +```python +from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC +from datasets import load_dataset +import torch +import re +from datasets import load_dataset, load_metric, Audio + +wer = load_metric("wer") +device = torch.device("cuda" if torch.cuda.is_available() else "cpu") + +# load processor and model +processor = Wav2Vec2Processor.from_pretrained("khanhld/wav2vec2-base-vietnamese-160h") +model = Wav2Vec2ForCTC.from_pretrained("khanhld/wav2vec2-base-vietnamese-160h") +model.to(device) +model.eval() + +# Load dataset +test_dataset = load_dataset("mozilla-foundation/common_voice_8_0", "vi", split="test", use_auth_token="your_huggingface_auth_token") +test_dataset = test_dataset.cast_column("audio", Audio(sampling_rate=16000)) +chars_to_ignore = r'[,?.!\-;:"“%\'�]' # ignore special characters + +# preprocess data +def preprocess(batch): + audio = batch["audio"] + batch["input_values"] = audio["array"] + batch["transcript"] = re.sub(chars_to_ignore, '', batch["sentence"]).lower() + return batch + +# run inference +def inference(batch): + input_values = processor(batch["input_values"], + sampling_rate=16000, + return_tensors="pt").input_values + logits = model(input_values.to(device)).logits + pred_ids = torch.argmax(logits, dim=-1) + batch["pred_transcript"] = processor.batch_decode(pred_ids) + return batch + +test_dataset = test_dataset.map(preprocess) +result = test_dataset.map(inference, batched=True, batch_size=1) +print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_transcript"], references=result["transcript"]))) +``` +**Test Result**: 10.78% + + +### Citation +[![DOI](https://zenodo.org/badge/491468343.svg)](https://zenodo.org/badge/latestdoi/491468343) +BibTeX +``` +@mics{Duy_Khanh_Finetune_Wav2vec_2_0_2022, + author = {Duy Khanh, Le}, + doi = {10.5281/zenodo.6542357}, + license = {CC-BY-NC-4.0}, + month = {5}, + title = {{Finetune Wav2vec 2.0 For Vietnamese Speech Recognition}}, + url = {https://github.com/khanld/ASR-Wa2vec-Finetune}, + year = {2022} +} +``` +APA +``` +Duy Khanh, L. (2022). Finetune Wav2vec 2.0 For Vietnamese Speech Recognition [Data set]. https://doi.org/10.5281/zenodo.6542357 +``` + + +### Contact +- khanhld218@gmail.com +- [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/) +- [![LinkedIn](https://img.shields.io/badge/linkedin-%230077B5.svg?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/khanhld257/) + + diff --git a/config.json b/config.json new file mode 100644 index 0000000..22dc5d8 --- /dev/null +++ b/config.json @@ -0,0 +1,118 @@ +{ + "_name_or_path": "facebook/wav2vec2-base", + "activation_dropout": 0.0, + "adapter_kernel_size": 3, + "adapter_stride": 2, + "add_adapter": false, + "apply_spec_augment": true, + "architectures": [ + "Wav2Vec2ForCTC" + ], + "attention_dropout": 0.1, + "bos_token_id": 1, + "classifier_proj_size": 256, + "codevector_dim": 256, + "contrastive_logits_temperature": 0.1, + "conv_bias": false, + "conv_dim": [ + 512, + 512, + 512, + 512, + 512, + 512, + 512 + ], + "conv_kernel": [ + 10, + 3, + 3, + 3, + 3, + 2, + 2 + ], + "conv_stride": [ + 5, + 2, + 2, + 2, + 2, + 2, + 2 + ], + "ctc_loss_reduction": "mean", + "ctc_zero_infinity": false, + "diversity_loss_weight": 0.1, + "do_stable_layer_norm": false, + "eos_token_id": 2, + "feat_extract_activation": "gelu", + "feat_extract_norm": "group", + "feat_proj_dropout": 0.1, + "feat_quantizer_dropout": 0.0, + "final_dropout": 0.0, + "freeze_feat_extract_train": true, + "gradient_checkpointing": false, + "hidden_act": "gelu", + "hidden_dropout": 0.1, + "hidden_size": 768, + "initializer_range": 0.02, + "intermediate_size": 3072, + "layer_norm_eps": 1e-05, + "layerdrop": 0.0, + "mask_channel_length": 10, + "mask_channel_min_space": 1, + "mask_channel_other": 0.0, + "mask_channel_prob": 0.0, + "mask_channel_selection": "static", + "mask_feature_length": 10, + "mask_feature_min_masks": 0, + "mask_feature_prob": 0.0, + "mask_time_length": 10, + "mask_time_min_masks": 2, + "mask_time_min_space": 1, + "mask_time_other": 0.0, + "mask_time_prob": 0.05, + "mask_time_selection": "static", + "model_type": "wav2vec2", + "no_mask_channel_overlap": false, + "no_mask_time_overlap": false, + "num_adapter_layers": 3, + "num_attention_heads": 12, + "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": 12, + "num_negatives": 100, + "output_hidden_size": 768, + "pad_token_id": 95, + "proj_codevector_dim": 256, + "tdnn_dilation": [ + 1, + 2, + 3, + 1, + 1 + ], + "tdnn_dim": [ + 512, + 512, + 512, + 512, + 1500 + ], + "tdnn_kernel": [ + 5, + 3, + 3, + 1, + 1 + ], + "torch_dtype": "float32", + "transformers_version": "4.18.0", + "use_weighted_layer_sum": false, + "vocab_size": 96, + "xvector_output_dim": 512 +} diff --git a/examples/VIVOSDEV15_020.wav b/examples/VIVOSDEV15_020.wav new file mode 100644 index 0000000..30db37c Binary files /dev/null and b/examples/VIVOSDEV15_020.wav differ diff --git a/examples/common_voice_vi_30519758.mp3 b/examples/common_voice_vi_30519758.mp3 new file mode 100644 index 0000000..580a9c7 Binary files /dev/null and b/examples/common_voice_vi_30519758.mp3 differ diff --git a/preprocessor_config.json b/preprocessor_config.json new file mode 100644 index 0000000..c626b55 --- /dev/null +++ b/preprocessor_config.json @@ -0,0 +1,10 @@ +{ + "do_normalize": true, + "feature_extractor_type": "Wav2Vec2FeatureExtractor", + "feature_size": 1, + "padding_side": "right", + "padding_value": 0.0, + "processor_class": "Wav2Vec2Processor", + "return_attention_mask": false, + "sampling_rate": 16000 +} diff --git a/pytorch_model.bin b/pytorch_model.bin new file mode 100644 index 0000000..47ea22b --- /dev/null +++ b/pytorch_model.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a83c98ecfa60dabd639cd0838819ef3c77c05fba6b43260593828d62fddbdd4 +size 377856300 diff --git a/special_tokens_map.json b/special_tokens_map.json new file mode 100644 index 0000000..9abf719 --- /dev/null +++ b/special_tokens_map.json @@ -0,0 +1 @@ +{"bos_token": "", "eos_token": "", "unk_token": "[UNK]", "pad_token": "[PAD]"} \ No newline at end of file diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..1c43412 --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1 @@ +{"unk_token": "[UNK]", "bos_token": "", "eos_token": "", "pad_token": "[PAD]", "do_lower_case": false, "word_delimiter_token": "|", "replace_word_delimiter_char": " ", "tokenizer_class": "Wav2Vec2CTCTokenizer", "processor_class": "Wav2Vec2Processor"} \ No newline at end of file diff --git a/vocab.json b/vocab.json new file mode 100644 index 0000000..3f33e35 --- /dev/null +++ b/vocab.json @@ -0,0 +1 @@ +{"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9, "j": 10, "k": 11, "l": 12, "m": 13, "n": 14, "o": 15, "p": 16, "q": 17, "r": 18, "s": 19, "t": 20, "u": 21, "v": 22, "w": 23, "x": 24, "y": 25, "z": 26, "à": 27, "á": 28, "â": 29, "ã": 30, "è": 31, "é": 32, "ê": 33, "ì": 34, "í": 35, "ò": 36, "ó": 37, "ô": 38, "õ": 39, "ù": 40, "ú": 41, "ý": 42, "ă": 43, "đ": 44, "ĩ": 45, "ũ": 46, "ơ": 47, "ư": 48, "ạ": 49, "ả": 50, "ấ": 51, "ầ": 52, "ẩ": 53, "ẫ": 54, "ậ": 55, "ắ": 56, "ằ": 57, "ẳ": 58, "ẵ": 59, "ặ": 60, "ẹ": 61, "ẻ": 62, "ẽ": 63, "ế": 64, "ề": 65, "ể": 66, "ễ": 67, "ệ": 68, "ỉ": 69, "ị": 70, "ọ": 71, "ỏ": 72, "ố": 73, "ồ": 74, "ổ": 75, "ỗ": 76, "ộ": 77, "ớ": 78, "ờ": 79, "ở": 80, "ỡ": 81, "ợ": 82, "ụ": 83, "ủ": 84, "ứ": 85, "ừ": 86, "ử": 87, "ữ": 88, "ự": 89, "ỳ": 90, "ỵ": 91, "ỷ": 92, "ỹ": 93, "|": 0, "[UNK]": 94, "[PAD]": 95} \ No newline at end of file