🚀 用于西班牙语语音识别的微调XLS - R 1B模型
本模型是在西班牙语数据集上对[facebook/wav2vec2 - xls - r - 1b](https://huggingface.co/facebook/wav2vec2 - xls - r - 1b)进行微调得到的。训练和验证数据来自[Common Voice 8.0](https://huggingface.co/datasets/mozilla - foundation/common_voice_8_0)、MediaSpeech、Multilingual TEDx、Multilingual LibriSpeech和Voxpopuli。使用此模型时,请确保输入的语音采样率为16kHz。
该模型由HuggingSound工具进行微调,感谢[OVHcloud](https://www.ovhcloud.com/en/public - cloud/ai - training/)慷慨提供的GPU计算资源。
🚀 快速开始
本模型可用于西班牙语的自动语音识别任务,通过微调预训练模型在多个数据集上进行训练,提升了语音识别的准确性。
✨ 主要特性
- 多数据集训练:使用多个西班牙语数据集进行训练,提高了模型的泛化能力。
- 微调优化:对预训练的XLS - R 1B模型进行微调,使其更适合西班牙语语音识别。
- 多指标评估:使用WER(词错误率)和CER(字符错误率)等指标进行评估,全面衡量模型性能。
📦 安装指南
文档未提及具体安装步骤,可参考相关依赖库的官方文档进行安装,如huggingsound
、transformers
、torch
、librosa
、datasets
等。
💻 使用示例
基础用法
使用HuggingSound库进行语音识别:
from huggingsound import SpeechRecognitionModel
model = SpeechRecognitionModel("jonatasgrosman/wav2vec2-xls-r-1b-spanish")
audio_paths = ["/path/to/file.mp3", "/path/to/another_file.wav"]
transcriptions = model.transcribe(audio_paths)
高级用法
编写自己的推理脚本:
import torch
import librosa
from datasets import load_dataset
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
LANG_ID = "es"
MODEL_ID = "jonatasgrosman/wav2vec2-xls-r-1b-spanish"
SAMPLES = 10
test_dataset = load_dataset("common_voice", LANG_ID, split=f"test[:{SAMPLES}]")
processor = Wav2Vec2Processor.from_pretrained(MODEL_ID)
model = Wav2Vec2ForCTC.from_pretrained(MODEL_ID)
def speech_file_to_array_fn(batch):
speech_array, sampling_rate = librosa.load(batch["path"], sr=16_000)
batch["speech"] = speech_array
batch["sentence"] = batch["sentence"].upper()
return batch
test_dataset = test_dataset.map(speech_file_to_array_fn)
inputs = processor(test_dataset["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
with torch.no_grad():
logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
predicted_ids = torch.argmax(logits, dim=-1)
predicted_sentences = processor.batch_decode(predicted_ids)
📚 详细文档
评估命令
- 在
mozilla - foundation/common_voice_8_0
数据集的test
分割上进行评估:
python eval.py --model_id jonatasgrosman/wav2vec2-xls-r-1b-spanish --dataset mozilla-foundation/common_voice_8_0 --config es --split test
- 在
speech - recognition - community - v2/dev_data
数据集上进行评估:
python eval.py --model_id jonatasgrosman/wav2vec2-xls-r-1b-spanish --dataset speech-recognition-community-v2/dev_data --config es --split validation --chunk_length_s 5.0 --stride_length_s 1.0
模型信息
属性 |
详情 |
模型类型 |
用于西班牙语语音识别的微调XLS - R 1B模型 |
训练数据 |
Common Voice 8.0、MediaSpeech、Multilingual TEDx、Multilingual LibriSpeech、Voxpopuli |
评估结果
任务 |
数据集 |
评估指标 |
值 |
自动语音识别 |
Common Voice 8 |
测试WER |
9.97 |
自动语音识别 |
Common Voice 8 |
测试CER |
2.85 |
自动语音识别 |
Common Voice 8(+LM) |
测试WER |
6.74 |
自动语音识别 |
Common Voice 8(+LM) |
测试CER |
2.24 |
自动语音识别 |
Robust Speech Event - Dev Data |
开发WER |
24.79 |
自动语音识别 |
Robust Speech Event - Dev Data |
开发CER |
9.7 |
自动语音识别 |
Robust Speech Event - Dev Data(+LM) |
开发WER |
16.37 |
自动语音识别 |
Robust Speech Event - Dev Data(+LM) |
开发CER |
8.84 |
自动语音识别 |
Robust Speech Event - Test Data |
测试WER |
16.67 |
📄 许可证
本项目采用Apache 2.0许可证。
📖 引用
如果您想引用此模型,可以使用以下格式:
@misc{grosman2021xlsr-1b-spanish,
title={Fine-tuned {XLS-R} 1{B} model for speech recognition in {S}panish},
author={Grosman, Jonatas},
howpublished={\url{https://huggingface.co/jonatasgrosman/wav2vec2-xls-r-1b-spanish}},
year={2022}
}