1、使用方式说明
ASR对应的文本越长,识别准确率和召回率越高
识别的错误分类:
编号 | 错误类型 | 示例 |
---|---|---|
1 | 谐音字词 | 配副眼睛-配副眼镜 |
2 | 混淆音字词 | 流浪织女-牛郎织女 |
3 | 多字错误 | 关关机-关机 |
4 | 少字错误 | 爱有天意-假如爱有天意 |
5 | 形似字错误 | 高梁-高粱 |
6 | 中文拼音全拼 | xingfu-幸福 |
7 | 中文拼音缩写 | sz-深圳 |
8 | 语法错误 | 想象难以-难以想象 |
ASR纠错,主要是解决1、2、3、4、5几个问题
ASR是实时语音回话,所以对性能要求极高,模型性能要求:
1、可以快速并行纠错。可以解决上线实时处理需求,时延在100ms以内。
备选对比模型:
模型1:fastcorrect、fastcorrect2
模型2:softcorrect
模型3:macbert
本次探讨fastcorrect模型
fast correct 环境准备
conda create -n fast_speech python=3.7 cudnn=8.9.2.26 cudatoolkit=11.3.1
pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113
git clone https://github.com/pytorch/fairseq (可以手动下载指定的稳定版本代码,建议下载0.10.1)
cd fairseq
pip install --editable ./pip install sentencepiece
**********************数据预处理************************************
*********************数据对齐************************************
align_cal_werdur_v2.py original_query_file target_query_file 可以将纠错内容进行对齐生成对齐数据集
********************训练数据二进制编码合成************************************
cd FastCorrect/runs
vi data-gen.sh (第9行数据赋值为data-bin)
chmod +x data-gen.sh
./data-gen.sh
**********************生成预训练模型*************************************
cd FastCorrect/runs
vi train_pretrain.sh (第9行数据赋值为data-bin,第12行为data-pretrain,第13行修改增加CUDA_VISIBLE_DEVICES=3,4)
chmod +x train_pretrain.sh
./train_pretrain.sh
**********************下载sentencepiece对应的模型*************************************
我下载的是https://hf-mirror.com/IDEA-CCNL/Erlangshen-DeBERTa-v2-186M-Chinese-SentencePiece/tree/main/spm.model
创建一个目录sentencepiece_model_path 并将模型复制到这个目录下
*********************模型推理*************************************
from fairseq import utils
utils.import_user_module(argparse.Namespace(user_dir='./FastCorrect'))
from FastCorrect.fastcorrect_model import FastCorrectModelmodel_name_or_path=saved_model_path
checkpoint_file = "checkpoint_best.pt" 可以指定具体的模型文件(多个版本选择)
data_name_or_path ="" #数据预处理data-gen 生成的训练数据二进制文件夹。默认为data-bin
bpe = "sentencepiece"
sentencepiece_model_path="" #sentencepiece_model_path 包含模型名称
transf_gec = FastCorrectModel.from_pretrained(model_name_or_path, checkpoint_file=checkpoint_file, data_name_or_path=data_name_or_path, bpe=bpe,sentencepiece_model=sentencepiece_model_path)
transf_gec.eval()
transf_gec.cuda()input_text= remove_ch_spaces(input_text)
standard_input = " ".join(list(input_text))
text = transf_gec.binarize(standard_input)batched_hypos = transf_gec.generate(text, iter_decode_max_iter=10)
translated = [transf_gec.decode(hypos[0]['tokens']) for hypos in batched_hypos][0]
print(translated )
结论:训练epoch 为200
对于1、2、5错误,解决较好。对于3、4的多字、少字错误解决不是狠理想。
相关参考链接:
FastCorrect git:https://github.com/microsoft/NeuralSpeech/tree/master/FastCorrect
Fairseq git:https://github.com/facebookresearch/fairseq
Fairseq 文档:https://fairseq.readthedocs.io/en/latest/command_line_tools.html
fairseq训练参数说明:https://www.cnblogs.com/hanlaomo/p/16708102.html