模型概述
模型特點
模型能力
使用案例
🚀 加泰羅尼亞語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 |



