g
gcw_AVRCax4T/sherpa-mnn-streaming-zipformer-bilingual-zh-en-2023-02-20
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Sherpa-ONNX Streaming Zipformer Bilingual (ZH-EN) ASR — Ascend NPU Adaptation

Model Card

FieldValue
Modelsherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20
TaskAutomatic Speech Recognition (ASR)
ArchitectureStreaming Zipformer Transducer (Encoder + Decoder + Joiner)
LanguagesChinese (ZH) + English (EN)
FrameworkONNX Runtime + torch_npu
HardwareAscend NPU (CANN 8.5.1)
PrecisionFP32 (ONNX models)
Sample Rate16000 Hz
Vocab Size6257 BPE tokens

Tags

#NPU #Hardware/NPU #Ascend #CANN #ASR #Speech-Recognition #Zipformer #Streaming #Bilingual #Chinese #English #torch_npu #ONNX-Runtime

Description

This is the Ascend NPU adaptation of the sherpa-onnx streaming Zipformer bilingual (Chinese-English) ASR model.

NPU Adaptation Strategy:

  • Feature Extraction (FFT, mel filterbank): Accelerated on Ascend NPU via torch_npu
  • Model Inference (Encoder/Decoder/Joiner): ONNX Runtime on CPU
  • Heterogeneous Pipeline: NPU (feature extraction) + CPU (model inference)

The streaming Zipformer transducer processes audio in 39-frame chunks with cache-based state management across 5 encoder layers.

Quick Start

Requirements

  • Ascend NPU (e.g., Ascend 910)
  • CANN 8.5.1+
  • Python 3.11+
  • torch_npu, onnxruntime

Installation

pip install torch_npu onnxruntime soundfile numpy

Inference

# NPU-accelerated feature extraction (default)
python inference.py --audio input.wav

# CPU-only mode
python inference.py --audio input.wav --cpu

# Save results as JSON
python inference.py --audio input.wav --output result.json

# Benchmark mode (feature extraction only)
python inference.py

Python API

from inference import SherpaASR

asr = SherpaASR(use_npu=True)
result = asr.transcribe("audio.wav")
print(result["text"])
print(f"RTF: {result['rtf']}")

Evaluation

Run the evaluation suite:

python evaluate.py

The evaluation generates:

  • eval_results/evaluation_report.md — Markdown report
  • eval_results/evaluation_results.json — Full results JSON

Results Summary

MetricValue
Feature Extraction (NPU)~11ms for 3s audio
Feature Precision (NPU vs CPU)< 1% relative error
Encoder Latency (CPU)~3.7s for 3s audio
Decoder Latency (CPU)~0.2s for 3s audio
RTF~1.3x realtime

Model Architecture

  • Encoder: Streaming Zipformer with stride-2 subsampling
    • 5 layers with multi-head self-attention, convolution caches
    • Input: 80-dim log-mel features (chunk size = 39 frames)
    • Output: 512-dim, T/2 temporal resolution
    • 8 parallel paths (averaged for final output)
  • Decoder: Stateless transducer decoder
    • Token embedding → Conv1D(groups=128, kernel=2) → Linear projection
    • Input: 2 context token indices (INT64)
    • Output: 512-dim vector
  • Joiner: Linear projection + log-softmax
    • Input: Encoder output (512) + Decoder output (512)
    • Output: 6257-class logits

Files

FileDescription
inference.pyMain inference script with NPU acceleration
evaluate.pyPrecision and performance evaluation suite
README.mdThis document

Environment

ComponentVersion
CANN8.5.1
NPUAscend 910_9362
torch_npu2.9.0.post1
torch2.9.0+cpu
onnxruntime1.26.0
onnxruntime-cann1.24.4
sherpa-onnx1.13.2
Python3.11.14
PlatformLinux aarch64

License

This adaptation follows the license of the original model. See the original HuggingFace repo for details.