--- language: zh datasets: - aishell1 metrics: - wer tags: - audio - automatic-speech-recognition - speech - xlsr-fine-tuning-week license: apache-2.0 model-index: - name: XLSR Wav2Vec2 Large 53 - Chinese (zh-CN), by Yue Qin results: - task: name: Speech Recognition type: automatic-speech-recognition dataset: name: AISHELL-1 zh-CN type: aishell1 args: zh-CN metrics: - name: Test WER type: wer value: 7.04 --- # Wav2Vec2-Large-XLSR-53-Chinese-zh-CN-aishell1 Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Chinese using the [AISHELL-1](https://github.com/kaldi-asr/kaldi/tree/master/egs/aishell) dataset. When using this model, make sure that your speech input is sampled at 16kHz. ## Usage The model can be used directly (without a language model) as follows: ```python import torch import librosa from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor device = "cuda:0" if torch.cuda.is_available() else "cpu" processor = Wav2Vec2Processor.from_pretrained( 'qinyue/wav2vec2-large-xlsr-53-chinese-zn-cn-aishell1') model = Wav2Vec2ForCTC.from_pretrained( 'qinyue/wav2vec2-large-xlsr-53-chinese-zn-cn-aishell1').to(device) filepath = 'test.wav' audio, sr = librosa.load(filepath, sr=16000, mono=True) inputs = processor(audio, sample_rate=16000, return_tensors="pt").to(device) with torch.no_grad(): logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits predicted_ids = torch.argmax(logits, dim=-1) pred_str = processor.decode(predicted_ids[0]) print(pred_str) ``` ## Evaluation ```python wer_metric = load_metric("wer") def compute_metrics(pred): pred_logits = pred.predictions pred_ids = np.argmax(pred_logits, axis=-1) pred.label_ids[pred.label_ids == -100] = processor.tokenizer.pad_token_id pred_str = processor.batch_decode(pred_ids, spaces_between_special_tokens=True) label_str = processor.batch_decode(pred.label_ids, group_tokens=False, spaces_between_special_tokens=True) wer = wer_metric.compute(predictions=pred_str, references=label_str) return {"wer": wer} ``` ## Results | Reference | Prediction | | ------------- | ------------- | | 据 伟 业 我 爱 我 家 市 场 研 究 院 测 算 | 据 北 业 我 爱 我 家 市 场 研 究 院 测 算 | | 七 月 北 京 公 积 金 贷 款 成 交 量 提 升 了 百 分 之 五 | 七 月 北 京 公 积 金 贷 款 成 交 量 提 升 了 百 分 之 五 | | 培 育 门 类 丰 富 层 次 齐 用 的 综 合 利 用 产 业 | 培 育 门 类 丰 富 层 资 集 业 的 综 合 利 用 产 业 | | 我 们 迎 来 了 赶 超 发 达 国 家 的 难 得 机 遇 | 我 们 迎 来 了 赶 超 发 达 国 家 的 单 得 机 遇 | | 坚 持 基 本 草 原 保 护 制 度 | 坚 持 基 本 草 员 保 护 制 度 | | 强 化 水 生 生 态 修 复 和 建 设 | 强 化 水 生 生 态 修 复 和 建 设 | | 温 州 两 男 子 为 争 女 人 驾 奔 驰 宝 马 街 头 四 次 对 撞 | 温 州 两 男 子 为 争 女 人 架 奔 驰 宝 马 接 头 四 次 对 重 | | 她 表 示 应 该 是 吃 吃 饭 看 电 影 之 类 的 | 他 表 示 一 的 是 吃 吃 饭 看 电 影 之 理 | | 加 强 畜 禽 遗 传 资 源 和 农 业 野 生 植 物 资 源 保 护 | 加 强 续 紧 遗 传 资 源 和 农 业 野 生 职 物 资 源 保 护 | | 两 人 都 是 依 赖 电 话 沟 通 | 两 人 都 是 依 赖 电 话 沟 通 | **Test Result**: In the table below I report the Word Error Rate (WER) of the model on the AISHELL-1 test dataset. | Model | WER | WER-with-LM | | ------------- | ------------- | ------------- | | qinyue/wav2vec2-large-xlsr-53-chinese-zn-cn-aishell1 | **7.04%** | **3.96%** |