语言: 德语
数据集:
- common_voice
推理支持: 否
评估指标:
- 词错误率(WER)
- 字符错误率(CER)
标签:
- 音频
- 自动语音识别
- 语音
- HF-ASR排行榜
许可证: Apache-2.0
模型索引:
- 名称: Hajo Nils Krabbenhöft开发的wav2vec 2.0 XLS-R 1B + TEVR标记 + 5-gram语言模型
结果:
- 任务:
名称: 语音识别
类型: 自动语音识别
数据集:
名称: Common Voice德语版
类型: common_voice
参数: de
指标:
- 名称: 测试WER
类型: wer
值: 3.6433399042523233
- 名称: 测试CER
类型: cer
值: 1.5398893560981173
概述
本目录包含一个完整训练的德语语音识别流程,包括采用新型wav2vec 2.0 XLS-R 1B TEVR架构的声学模型和一个5-gram KenLM语言模型。
关于TEVR增强技术及其设计动机的说明,请参阅我们的论文:
TEVR: 通过标记熵方差降低提升语音识别性能。

该流程在CommonVoice德语测试集上取得了极具竞争力的(截至2022年6月)3.64%词错误率,字符错误率为1.54%。
引用
若在研究中使用了该语音识别流程,请引用:
@misc{https://doi.org/10.48550/arxiv.2206.12693,
doi = {10.48550/ARXIV.2206.12693},
url = {https://arxiv.org/abs/2206.12693},
author = {Krabbenhöft, Hajo Nils and Barth, Erhardt},
keywords = {计算与语言(cs.CL), 声音(cs.SD), 音频与语音处理(eess.AS), FOS: 计算机与信息科学, FOS: 计算机与信息科学, FOS: 电子工程, 信息工程, FOS: 电子工程, 信息工程, F.2.1; I.2.6; I.2.7},
title = {TEVR: 通过标记熵方差降低提升语音识别性能},
publisher = {arXiv},
year = {2022},
copyright = {知识共享署名4.0国际许可协议}
}
TEVR标记生成器创建/测试
访问 https://huggingface.co/fxtentacle/tevr-token-entropy-predictor-de 获取:
- 论文中用于计算熵值的训练好的ByT5模型
- 从文本语料库生成TEVR标记生成器的Jupyter Notebook
- 生成论文示意图的Jupyter Notebook
评估
要自行评估该流程或处理自定义数据,请参考HF Eval Script.ipynb
笔记本或使用以下Python脚本:
!pip install --quiet --root-user-action=ignore --upgrade pip
!pip install --quiet --root-user-action=ignore "datasets>=1.18.3" "transformers==4.11.3" librosa jiwer huggingface_hub
!pip install --quiet --root-user-action=ignore https://github.com/kpu/kenlm/archive/master.zip pyctcdecode
!pip install --quiet --root-user-action=ignore --upgrade transformers
!pip install --quiet --root-user-action=ignore torch_audiomentations audiomentations
from datasets import load_dataset, Audio, load_metric
from transformers import AutoModelForCTC, Wav2Vec2ProcessorWithLM
import torchaudio.transforms as T
import torch
import unicodedata
import numpy as np
import re
testing_dataset = load_dataset("common_voice", "de", split="test")
allchars = list(set([c for t in testing_dataset['sentence'] for c in list(t)]))
map_to_space = [c for c in allchars if unicodedata.category(c)[0] in 'PSZ' and c not in 'ʻ-']
replacements = ''.maketrans(''.join(map_to_space), ''.join(' ' for i in range(len(map_to_space))), '\'ʻ')
def text_fix(text):
text = text.replace('ß','ss')
text = text.replace('-',' ').replace(' ',' ').replace(' ',' ')
text = text.lower()
text = text.translate(replacements).strip()
text = re.sub("[âşěýňעảנźțãòàǔł̇æồאắîשðșęūāñë生בøúıśžçćńřğ]+","?",text)
text = ' '.join([w for w in text.split(' ') if w != ''])
return text
model = AutoModelForCTC.from_pretrained("fxtentacle/wav2vec2-xls-r-1b-tevr")
model.to('cuda')
class HajoProcessor(Wav2Vec2ProcessorWithLM):
@staticmethod
def get_missing_alphabet_tokens(decoder, tokenizer):
return []
processor = HajoProcessor.from_pretrained("fxtentacle/wav2vec2-xls-r-1b-tevr")
def predict_single_audio(batch, image=False):
audio = batch['audio']['array']
if batch['audio']['sampling_rate'] != 16000:
audio = T.Resample(orig_freq=batch['audio']['sampling_rate'], new_freq=16000)(torch.from_numpy(audio)).numpy()
audio = (audio - audio.mean()) / np.sqrt(audio.var() + 1e-7)
input_values = processor(audio, return_tensors="pt", sampling_rate=16_000).input_values
with torch.no_grad():
logits = model(input_values.to('cuda')).logits.cpu().numpy()[0]
decoded = processor.decode(logits, beam_width=500)
return { 'groundtruth': text_fix(batch['sentence']), 'prediction': decoded.text }
all_predictions = testing_dataset.map(predict_single_audio, remove_columns=testing_dataset.column_names)
print('WER', load_metric("wer").compute(predictions=all_predictions['prediction'], references=all_predictions['groundtruth'])*100.0, '%')
print('CER', load_metric("cer").compute(predictions=all_predictions['prediction'], references=all_predictions['groundtruth'])*100.0, '%')
WER 3.6433399042523233 %
CER 1.5398893560981173 %