🚀 ruT5-ASR
ruT5-ASR 模型由 bond005 訓練,用於糾正自動語音識別(ASR)輸出中的錯誤(特別是 Wav2Vec2-Large-Ru-Golos 的輸出)。該模型基於 ruT5-base 構建。
🚀 快速開始
本模型可作為獨立的序列到序列模型,用於糾正自動語音識別(ASR)的輸出,具體使用方法如下。
💻 使用示例
基礎用法
from transformers import T5ForConditionalGeneration, T5Tokenizer
import torch
def rescore(text: str, tokenizer: T5Tokenizer,
model: T5ForConditionalGeneration) -> str:
if len(text) == 0:
return ''
ru_letters = set('аоуыэяеёюибвгдйжзклмнпрстфхцчшщьъ')
punct = set('.,:/\\?!()[]{};"\'-')
x = tokenizer(text, return_tensors='pt', padding=True).to(model.device)
max_size = int(x.input_ids.shape[1] * 1.5 + 10)
min_size = 3
if x.input_ids.shape[1] <= min_size:
return text
out = model.generate(**x, do_sample=False, num_beams=5,
max_length=max_size, min_length=min_size)
res = tokenizer.decode(out[0], skip_special_tokens=True).lower().strip()
res = ' '.join(res.split())
postprocessed = ''
for cur in res:
if cur.isspace() or (cur in punct):
postprocessed += ' '
elif cur in ru_letters:
postprocessed += cur
return (' '.join(postprocessed.strip().split())).replace('ё', 'е')
tokenizer_for_rescoring = T5Tokenizer.from_pretrained('bond005/ruT5-ASR')
model_for_rescoring = T5ForConditionalGeneration.from_pretrained('bond005/ruT5-ASR')
if torch.cuda.is_available():
model_for_rescoring = model_for_rescoring.cuda()
input_examples = [
'уласны в москве интерне только в большом году что лепровели',
'мороз и солнце день чудесный',
'нейро сети эта харошо',
'да'
]
for src in input_examples:
rescored = rescore(src, tokenizer_for_rescoring, model_for_rescoring)
print(f'{src} -> {rescored}')
運行上述代碼後,會得到如下輸出示例:
уласны в москве интерне только в большом году что лепровели -> у нас в москве интернет только в прошлом году что ли провели
мороз и солнце день чудесный -> мороз и солнце день чудесный
нейро сети эта харошо -> нейросети это хорошо
да -> да
📚 詳細文檔
本模型在 SberDevices Golos、Common Voice 6.0(俄語部分)和 Russian Librispeech 的測試子集上進行了評估,但僅在 SberDevices Golos 的訓練子集上進行了訓練。你可以在我的 Kaggle 網頁 https://www.kaggle.com/code/bond005/wav2vec2-t5-ru-eval 上查看在其他數據集(包括 Russian Librispeech 和 SOVA RuDevices)上的評估腳本。
與 “純” Wav2Vec2-Large-Ru-Golos 的比較(字錯率,%)
數據集名稱 |
純 ASR |
經本模型糾正後的 ASR |
Voxforge Ru |
27.08 |
40.48 |
Russian LibriSpeech |
21.87 |
23.77 |
Sova RuDevices |
25.41 |
20.13 |
Golos Crowd |
10.14 |
9.42 |
Golos Farfield |
20.35 |
17.99 |
CommonVoice Ru |
18.55 |
11.60 |
📄 許可證
本項目採用 apache-2.0
許可證。