rwer
English | 简体中文
A modern Rust crate for Word Error Rate (WER), Character Error Rate (CER), and related ASR evaluation metrics.
Features
- WER (Word Error Rate):
(S + D + I) / N - CER (Character Error Rate): Same formula at Unicode grapheme cluster level
- MER (Match Error Rate):
(S + D + I) / (H + S + D + I) - WIP (Word Information Preserved):
(H/N) * (H/(H+S+D+I)) - WIL (Word Information Lost):
1 - WIP - Transform pipeline for text preprocessing (lowercase, remove punctuation, etc.)
- Alignment visualization with error frequency analysis
Quick Start
use ;
let reference = "the cat sat on the mat";
let hypothesis = "the cat sat on a mat";
println!;
println!;
All Metrics at Once
use ;
let output = process_words;
println!;
println!;
Output:
WER: 16.67%
MER: 16.67%
WIP: 0.7778
WIL: 0.2222
Hits: 4 Sub: 1 Del: 0 Ins: 0
REF: the cat sat
HYP: the dog sat
Transform Pipeline
use ;
let pipeline: = Boxnew;
let ref_text = pipeline.transform;
let hyp_text = pipeline.transform;
assert!;
Available Transforms
| Transform | Description |
|---|---|
ToLower |
Convert to lowercase |
ToUpper |
Convert to uppercase |
Strip |
Strip leading/trailing whitespace |
RemovePunctuation |
Remove Unicode punctuation |
NormalizeSpaces |
Collapse consecutive spaces + remove spaces between CJK characters |
RemoveWhitespace |
Remove all whitespace |
SubstituteWords |
Replace whole words via a map |
RemoveSpecificWords |
Remove specified words |
ExpandCommonEnglishContractions |
Expand contractions (e.g., "don't" -> "do not") |
ToSimplified |
Convert Traditional Chinese to Simplified Chinese (chinese-variant feature) |
ToTraditional |
Convert Simplified Chinese to Traditional Chinese (chinese-variant feature) |
Chinese Variant Normalization
When comparing ASR outputs that may use different Chinese scripts (Traditional vs Simplified), enable the chinese-variant feature:
[]
= { = "0.1", = ["chinese-variant"] }
use ;
// Normalize both texts to Simplified before comparison
let pipeline = new;
let ref_text = pipeline.transform;
let hyp_text = pipeline.transform;
assert_eq!;
CLI usage:
CLI
Enable the cli feature:
[]
= { = "0.1", = ["cli"] }
# Install
# Basic WER with text arguments
# Read from files
# Mix text and file input
# Read from stdin
|
# CER mode
# Show alignment
# All metrics
# With normalization
Error Analysis
use ;
let output = process_words;
let errors = collect_error_counts;
println!;
println!;
println!;
Feature Flags
| Feature | Description | Dependencies |
|---|---|---|
chinese-variant |
Traditional/Simplified Chinese conversion | zhconv |
cli |
CLI binary | clap, serde, serde_json |
JavaScript / WebAssembly
rwer is also available as a WebAssembly package for browser and Node.js:
import * as rwer from "@ryaningli/rwer";
// Browser
await rwer.;
// Node.js
import from "node:fs";
rwer.;
console.log; // 0.333...
console.log; // 0.2
const output = rwer.;
console.log; // 0.333...
console.log; // 2
console.log; // 1
console.log; // [{kind:"equal",...}, {kind:"substitute",...}]
console.log; // REF: the cat sat\nHYP: the dog sat
Build from source
# Install wasm-pack
# Build
&&
# Or manually
Run JS tests
&&
Benchmarks
Acknowledgments
- jiwer — API design and architecture reference for WER/CER metrics
- zhconv — Traditional/Simplified Chinese conversion
License
Licensed under MIT.