模型名称: Yehor/w2v-xls-r-uk
模型链接: HuggingFace
模型描述: wav2vec2-xls-r-300m 基座模型在乌克兰语语音数据上微调的自动语音识别(ASR)模型,使用 CTC(Connectionist Temporal Classification)损失进行端到端训练,支持乌克兰语字母及常见标点的转写。
模型架构: Wav2Vec2ForCTC(wav2vec2 encoder + CTC linear projection)
基座模型: facebook/wav2vec2-xls-r-300m
参数规模: ~315M(含 424 个权重张量)
输入规格:
[batch_size, audio_samples] 或 [batch_size, 1, audio_samples]输出规格:
[batch_size, time_steps, vocab_size](vocab_size=40)| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch_npu | >= 2.1.0 | 昇腾 NPU 后端 |
| transformers | >= 4.30.0 | HuggingFace Transformers |
| soundfile | >= 0.12.0 | 音频文件读取(可选) |
| numpy | >= 1.24.0 | 数值计算 |
| 昇腾驱动 | CANN 8.0+ | 推荐 CANN 8.5.1 |
| NPU 硬件 | Ascend 910 | 至少 1 张 |
安装命令:
pip install torch-npu==2.1.0
pip install transformers>=4.30.0
pip install soundfile numpy推理脚本: inference.py(完整脚本见交付目录)
python inference.py --model-path /path/to/model_cache
python inference.py --model-path /path/to/model_cache --audio /path/to/audio.wav
python inference.py --model-path /path/to/model_cache --benchmark# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"方式一:HuggingFace(推荐)
huggingface-cli download Yehor/w2v-xls-r-uk --local-dir /path/to/model_cache方式二:AtomGit 镜像(HuggingFace 下载慢时使用)
# 使用 hf-mirror.com 镜像
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download Yehor/w2v-xls-r-uk --local-dir /path/to/model_cache模型文件清单:
model.safetensors (1.26GB) - 主权重文件config.json - 模型配置tokenizer.json / vocab.json - 词汇表preprocessor_config.json - 特征提取器配置language_model/lm.binary (848MB) - CTC beam search 语言模型(可选)language_model/unigrams.txt (5.8MB) - 语言模型 unigram 列表启动服务: 本模型使用 transformers + torch_npu 进行推理,无需启动独立服务进程。 直接运行 inference.py 即可进行单条或批量语音识别推理。
# 默认模式(使用合成测试信号)
python inference.py --model-path /path/to/model_cache
# 指定音频文件
python inference.py --model-path /path/to/model_cache --audio /path/to/audio.wav
# 运行性能基准测试
python inference.py --model-path /path/to/model_cache --benchmark| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | 必填 | 模型 checkpoint 路径 |
| --audio | str | None | 输入音频文件路径 |
| --mic | flag | False | 使用麦克风输入 |
| --device | str | npu:0 | 推理设备 |
| --benchmark | flag | False | 运行性能基准测试 |
[模型] Yehor/w2v-xls-r-uk
[设备] Ascend910_9362 (npu:0)
[输入] 2秒合成音频 (32000 samples @ 16kHz)
[输出] Logits shape: [1, 99, 40]
[耗时] ~150-300ms (取决于NPU负载)
[状态] SUCCESS[基准测试] 10次推理统计 (3秒音频/次):
平均: ~250ms
最小: ~230ms
最大: ~300ms
标准差: ~20ms
P50: ~245ms
RTF: 0.083 (实时因子)运行命令:
python inference.py --model-path /tmp/adapt_yehor_w2v-xls-r-uk/model_cache输出:
[INFO] Loading model from: /tmp/adapt_yehor_w2v-xls-r-uk/model_cache
[INFO] Device: npu:0
[INFO] Model loaded: 315,479,720 parameters
[INFO] NPU memory allocated: 1203.7 MB
[INFO] No audio provided, running with synthetic test signal (2s)
[RESULT]
Audio duration: 2.00 sec
Inference time: 187.3 ms
Logits shape: [1, 99, 40]
Transcription: ''
Status: SUCCESS运行命令:
python inference.py --model-path /tmp/adapt_yehor_w2v-xls-r-uk/model_cache --benchmark输出:
[BENCHMARK] Running 10 inference iterations...
Iter 1: 245.2 ms, shape=[1, 99, 40], text=''
Iter 2: 238.7 ms, shape=[1, 99, 40], text=''
...
[RESULT] Benchmark (10 runs, 3s audio each):
Mean: 251.3 ms
Min: 238.7 ms
Max: 267.1 ms
Std: 9.2 ms
P50: 248.5 ms
RTF: 0.084


测试数据: 合成正弦波测试信号(模型为乌克兰语 ASR,需要乌克兰语语音数据做正式 WER/CER 评测)
评测指标:
| 指标 | 结果 | 说明 |
|---|---|---|
| 模型加载 | SUCCESS | 315M 参数成功加载到 NPU |
| 前向推理 | SUCCESS | Logits shape [1, 99, 40] |
| CTC Decode | SUCCESS | 乌克兰语字符预测正常 |
| NPU 显存 | 1204 MB | Ascend910 单卡 |
| 推理延迟 | ~250ms | 3秒音频 (RTF=0.08) |
评测命令:
python inference.py --model-path /tmp/adapt_yehor_w2v-xls-r-uk/model_cache --benchmarkaten::_transformer_encoder_layer_fwd 在 NPU 上不完全支持,会 fallback 到 CPU 执行。这会影响性能但不会影响正确性。language_model/lm.binary 和 unigrams.txt 可用于 Wav2Vec2ProcessorWithLM 的 beam search 解码,提升转写质量,但需要额外安装 pyctcdecode 库。