模型简介
模型特点
模型能力
使用案例
🚀 加泰罗尼亚语XLSR Wav2Vec大模型53
本模型基于Transformer架构,在加泰罗尼亚语语音识别任务上进行了微调。它使用了Common Voice数据集进行训练,能够有效地将加泰罗尼亚语语音转换为文本,为加泰罗尼亚语的自动语音识别提供了强大的支持。
🚀 快速开始
本模型是在facebook/wav2vec2-large-xlsr-53的基础上,使用Common Voice加泰罗尼亚语数据集进行微调得到的。使用该模型时,请确保输入的语音采样率为16kHz。
✨ 主要特性
- 数据集:使用Common Voice数据集进行训练。
- 评估指标:使用字错率(WER)作为评估指标。
- 应用场景:适用于加泰罗尼亚语的自动语音识别任务。
📦 安装指南
文档中未提及具体安装步骤,可参考Hugging Face相关模型的安装说明进行安装。
💻 使用示例
基础用法
模型可以直接使用(不使用语言模型),示例代码如下:
import torch
import torchaudio
from datasets import load_dataset
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
test_dataset = load_dataset("common_voice", "ca", split="test[:2%]")
processor = Wav2Vec2Processor.from_pretrained("PereLluis13/Wav2Vec2-Large-XLSR-53-catalan")
model = Wav2Vec2ForCTC.from_pretrained("PereLluis13/Wav2Vec2-Large-XLSR-53-catalan")
resampler = torchaudio.transforms.Resample(48_000, 16_000)
# Preprocessing the datasets.
# We need to read the aduio files as arrays
def speech_file_to_array_fn(batch):
speech_array, sampling_rate = torchaudio.load(batch["path"])
batch["speech"] = resampler(speech_array).squeeze().numpy()
return batch
test_dataset = test_dataset.map(speech_file_to_array_fn)
inputs = processor(test_dataset["speech"][:2], 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)
print("Prediction:", processor.batch_decode(predicted_ids))
print("Reference:", test_dataset["sentence"][:2])
高级用法
可以在加泰罗尼亚语的Common Voice测试数据上对模型进行评估,示例代码如下:
import torch
import torchaudio
from datasets import load_dataset, load_metric
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
import re
test_dataset = load_dataset("common_voice", "ca", split="test")
wer = load_metric("wer")
processor = Wav2Vec2Processor.from_pretrained("PereLluis13/Wav2Vec2-Large-XLSR-53-catalan")
model = Wav2Vec2ForCTC.from_pretrained("PereLluis13/Wav2Vec2-Large-XLSR-53-catalan")
model.to("cuda")
chars_to_ignore_regex = '[\,\?\.\!\;\:\"\“]'
resampler = torchaudio.transforms.Resample(48_000, 16_000)
# Preprocessing the datasets.
# We need to read the aduio files as arrays
def speech_file_to_array_fn(batch):
batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
speech_array, sampling_rate = torchaudio.load(batch["path"])
batch["speech"] = resampler(speech_array).squeeze().numpy()
return batch
test_dataset = test_dataset.map(speech_file_to_array_fn)
# Preprocessing the datasets.
# We need to read the aduio files as arrays
def evaluate(batch):
inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
with torch.no_grad():
logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
pred_ids = torch.argmax(logits, dim=-1)
batch["pred_strings"] = processor.batch_decode(pred_ids)
return batch
result = test_dataset.map(evaluate, batched=True, batch_size=8)
import jiwer
# Chunk WER computation due to memory issues, taken from https://huggingface.co/pcuenq/wav2vec2-large-xlsr-53-es
def chunked_wer(targets, predictions, chunk_size=None):
if chunk_size is None: return jiwer.wer(targets, predictions)
start = 0
end = chunk_size
H, S, D, I = 0, 0, 0, 0
while start < len(targets):
chunk_metrics = jiwer.compute_measures(targets[start:end], predictions[start:end])
H = H + chunk_metrics["hits"]
S = S + chunk_metrics["substitutions"]
D = D + chunk_metrics["deletions"]
I = I + chunk_metrics["insertions"]
start += chunk_size
end += chunk_size
return float(S + D + I) / float(H + S + D)
print("WER: {:2f}".format(100 * chunked_wer(result["sentence"], result["pred_strings"], chunk_size=4000)))
测试结果:8.11 %
📚 详细文档
免责声明
本模型是在Common Voice 6数据集上训练的。如果您需要一个用于自动语音识别的加泰罗尼亚语模型,建议查看 wav2vec2-xls-r-1b-ca-lm,这是一个基于CV8+数据集训练的带有语言模型的10亿参数模型,性能更好;或者 wav2vec2-xls-r-300m-ca-lm,该模型与本模型大小相同(3亿参数),但在CV8+数据集上训练并使用了相同的语言模型。
训练过程
使用了Common Voice的train
和validation
数据集进行训练。在第二个训练周期,由于内存问题停止了训练,随后以较小的批次大小继续训练,但累积梯度步数进行了调整,以确保在整个训练过程中批次大小相当于32。然后,模型又额外训练了10个周期,其中一半的男性样本进行了升调处理。
训练使用的脚本可以在这里找到。为了加快训练过程中按长度排序的速度,对脚本进行了一些小的修改,修改内容可以在这里找到。另一个为加泰罗尼亚语训练的版本可以在这里找到,由于它使用了额外的数据并进行了更长时间的训练,可能比本模型表现更好。不过,由于它使用了包含部分Common Voice测试集的不同分割,本版本可以用于在Common Voice数据集上获取基线结果。
🔧 技术细节
本模型基于facebook/wav2vec2-large-xlsr-53进行微调,使用了Common Voice加泰罗尼亚语数据集进行训练。在训练过程中,使用了字错率(WER)作为评估指标,以评估模型在语音识别任务上的性能。
📄 许可证
本模型使用Apache 2.0许可证。
信息表格
属性 | 详情 |
---|---|
模型类型 | 加泰罗尼亚语XLSR Wav2Vec大模型53 |
训练数据 | Common Voice加泰罗尼亚语数据集 |
评估指标 | 字错率(WER) |
测试结果 | 8.11 % |
许可证 | Apache 2.0 |



