🚀 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
许可证。