Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fd70bc9
LODR support via n-gram FSTs
Mar 19, 2025
ae740e2
fix typo
Mar 19, 2025
b9a812b
Merge branch 'master' into lodr_support
Mar 19, 2025
c807461
fixed python API
Mar 21, 2025
85c528d
python constructor fix
Mar 24, 2025
12421a3
fix typo
Mar 24, 2025
89969e2
missing backoff param in python api
Mar 24, 2025
7fa9e1f
skip shared_ptr initialization
vsd-vector Apr 8, 2025
71ee975
refactor naming and comments
Apr 8, 2025
31f5840
Refactor pointers
Apr 8, 2025
b030e72
integrate suggestions from review
Apr 24, 2025
8d44deb
infer backoff_id automatically from fst
Apr 25, 2025
b29dd8d
style fix
Apr 25, 2025
1bdaa19
style fix
Apr 25, 2025
59ab7e9
Merge branch 'master' into lodr_support
May 7, 2025
21a7b25
CI/CD for LODR
May 7, 2025
6dc0dea
modify lm_log_prob not log_prob
May 7, 2025
511f069
Merge remote-tracking branch 'origin/master' into lodr_support
May 7, 2025
7f6a736
Python examples extended with LODR support
May 8, 2025
83d298b
unified LODR FST traversing implementaton
May 8, 2025
5cf9dbd
added LODR to python CI/CD test
May 8, 2025
d000166
fix decoding method in comment
May 8, 2025
6dd585b
add missing decoding-method to CI/CD tests
Jun 10, 2025
256dfb2
Merge branch 'master' into lodr_support
vsd-vector Jul 8, 2025
d327aa1
remove explicit string initialization
vsd-vector Jul 8, 2025
3dbd6d9
fix tostring() output formatting
vsd-vector Jul 8, 2025
fa3cadb
commit PR suggestions
Jul 9, 2025
c2eb969
style fix
Jul 9, 2025
5dc574a
fix python API constructor for offline LM config
Jul 9, 2025
c761a7d
remove exception throw
Jul 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion .github/scripts/test-offline-transducer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,39 @@ time $EXE \
$repo/test_wavs/1.wav \
$repo/test_wavs/8k.wav

rm -rf $repo
lm_repo_url=https://huggingface.co/ezerhouni/icefall-librispeech-rnn-lm
log "Download pre-trained RNN-LM model from ${lm_repo_url}"
GIT_LFS_SKIP_SMUDGE=1 git clone $lm_repo_url
lm_repo=$(basename $lm_repo_url)
pushd $lm_repo
git lfs pull --include "exp/no-state-epoch-99-avg-1.onnx"
popd

bigram_repo_url=https://huggingface.co/vsd-vector/librispeech_bigram_sherpa-onnx-zipformer-large-en-2023-06-26
log "Download bi-gram LM from ${bigram_repo_url}"
GIT_LFS_SKIP_SMUDGE=1 git clone $bigram_repo_url
bigramlm_repo=$(basename $bigram_repo_url)
pushd $bigramlm_repo
git lfs pull --include "2gram.fst"
popd

log "Start testing with LM and bi-gram LODR"
# TODO: find test examples that change with the LODR
time $EXE \
--tokens=$repo/tokens.txt \
--encoder=$repo/encoder-epoch-99-avg-1.onnx \
--decoder=$repo/decoder-epoch-99-avg-1.onnx \
--joiner=$repo/joiner-epoch-99-avg-1.onnx \
--num-threads=2 \
--decoding_method="modified_beam_search" \
--lm=$lm_repo/exp/no-state-epoch-99-avg-1.onnx \
--lodr-fst=$bigramlm_repo/2gram.fst \
--lodr-scale=-0.5 \
$repo/test_wavs/0.wav \
$repo/test_wavs/1.wav \
$repo/test_wavs/8k.wav

rm -rf $repo $lm_repo $bigramlm_repo

log "------------------------------------------------------------"
log "Run Paraformer (Chinese)"
Expand Down
55 changes: 54 additions & 1 deletion .github/scripts/test-online-transducer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,60 @@ for wave in ${waves[@]}; do
$wave
done

rm -rf $repo
lm_repo_url=https://huggingface.co/vsd-vector/icefall-librispeech-rnn-lm
log "Download pre-trained RNN-LM model from ${lm_repo_url}"
GIT_LFS_SKIP_SMUDGE=1 git clone $lm_repo_url
lm_repo=$(basename $lm_repo_url)
pushd $lm_repo
git lfs pull --include "with-state-epoch-99-avg-1.onnx"
popd

bigram_repo_url=https://huggingface.co/vsd-vector/librispeech_bigram_sherpa-onnx-zipformer-large-en-2023-06-26
log "Download bi-gram LM from ${bigram_repo_url}"
GIT_LFS_SKIP_SMUDGE=1 git clone $bigram_repo_url
bigramlm_repo=$(basename $bigram_repo_url)
pushd $bigramlm_repo
git lfs pull --include "2gram.fst"
popd

log "Start testing LODR"

waves=(
$repo/test_wavs/0.wav
$repo/test_wavs/1.wav
$repo/test_wavs/8k.wav
)
Comment thread
vsd-vector marked this conversation as resolved.

for wave in ${waves[@]}; do
time $EXE \
--tokens=$repo/tokens.txt \
--encoder=$repo/encoder-epoch-99-avg-1.onnx \
--decoder=$repo/decoder-epoch-99-avg-1.onnx \
--joiner=$repo/joiner-epoch-99-avg-1.onnx \
--num-threads=2 \
--decoding_method="modified_beam_search" \
--lm=$lm_repo/with-state-epoch-99-avg-1.onnx \
--lodr-fst=$bigramlm_repo/2gram.fst \
--lodr-scale=-0.5 \
$wave
done
Comment thread
vsd-vector marked this conversation as resolved.

for wave in ${waves[@]}; do
time $EXE \
--tokens=$repo/tokens.txt \
--encoder=$repo/encoder-epoch-99-avg-1.onnx \
--decoder=$repo/decoder-epoch-99-avg-1.onnx \
--joiner=$repo/joiner-epoch-99-avg-1.onnx \
--num-threads=2 \
--decoding_method="modified_beam_search" \
--lm=$lm_repo/with-state-epoch-99-avg-1.onnx \
--lodr-fst=$bigramlm_repo/2gram.fst \
--lodr-scale=-0.5 \
--lm-shallow-fusion=true \
$wave
done

rm -rf $repo $bigramlm_repo $lm_repo

log "------------------------------------------------------------"
log "Run streaming Zipformer transducer (Bilingual, Chinese + English)"
Expand Down
32 changes: 31 additions & 1 deletion .github/scripts/test-python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,39 @@ python3 ./python-api-examples/offline-decode-files.py \
$repo/test_wavs/1.wav \
$repo/test_wavs/8k.wav

lm_repo_url=https://huggingface.co/ezerhouni/icefall-librispeech-rnn-lm
log "Download pre-trained RNN-LM model from ${lm_repo_url}"
GIT_LFS_SKIP_SMUDGE=1 git clone $lm_repo_url
lm_repo=$(basename $lm_repo_url)
pushd $lm_repo
git lfs pull --include "exp/no-state-epoch-99-avg-1.onnx"
popd

bigram_repo_url=https://huggingface.co/vsd-vector/librispeech_bigram_sherpa-onnx-zipformer-large-en-2023-06-26
log "Download bi-gram LM from ${bigram_repo_url}"
GIT_LFS_SKIP_SMUDGE=1 git clone $bigram_repo_url
bigramlm_repo=$(basename $bigram_repo_url)
pushd $bigramlm_repo
git lfs pull --include "2gram.fst"
popd

log "Perform offline decoding with RNN-LM and LODR"
python3 ./python-api-examples/offline-decode-files.py \
--tokens=$repo/tokens.txt \
--encoder=$repo/encoder-epoch-99-avg-1.onnx \
--decoder=$repo/decoder-epoch-99-avg-1.onnx \
--joiner=$repo/joiner-epoch-99-avg-1.onnx \
--decoding-method=modified_beam_search \
--lm=$lm_repo/exp/no-state-epoch-99-avg-1.onnx \
--lodr-fst=$bigramlm_repo/2gram.fst \
--lodr-scale=-0.5 \
$repo/test_wavs/0.wav \
$repo/test_wavs/1.wav \
$repo/test_wavs/8k.wav

python3 sherpa-onnx/python/tests/test_offline_recognizer.py --verbose

rm -rf $repo
rm -rf $repo $lm_repo $bigramlm_repo

log "Test non-streaming paraformer models"

Expand Down
56 changes: 56 additions & 0 deletions python-api-examples/offline-decode-files.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@
/path/to/0.wav \
/path/to/1.wav

also with RNN LM rescoring and LODR (optional):

./python-api-examples/offline-decode-files.py \
--tokens=/path/to/tokens.txt \
--encoder=/path/to/encoder.onnx \
--decoder=/path/to/decoder.onnx \
--joiner=/path/to/joiner.onnx \
--num-threads=2 \
--decoding-method=modified_beam_search \
--debug=false \
--sample-rate=16000 \
--feature-dim=80 \
--lm=/path/to/lm.onnx \
--lm-scale=0.1 \
--lodr-fst=/path/to/lodr.fst \
--lodr-scale=-0.1 \
/path/to/0.wav \
/path/to/1.wav

(3) For CTC models from NeMo

python3 ./python-api-examples/offline-decode-files.py \
Expand Down Expand Up @@ -269,6 +288,39 @@ def get_args():
default="greedy_search",
help="Valid values are greedy_search and modified_beam_search",
)

parser.add_argument(
"--lm",
metavar="file",
type=str,
default="",
help="Path to RNN LM model",
)

parser.add_argument(
"--lm-scale",
metavar="lm_scale",
type=float,
default=0.1,
help="LM model scale for rescoring",
)

parser.add_argument(
"--lodr-fst",
metavar="file",
type=str,
default="",
help="Path to LODR FST model. Used only when --lm is given.",
)

parser.add_argument(
"--lodr-scale",
metavar="lodr_scale",
type=float,
default=-0.1,
help="LODR scale for rescoring.Used only when --lodr_fst is given.",
)

parser.add_argument(
"--debug",
type=bool,
Expand Down Expand Up @@ -364,6 +416,10 @@ def main():
num_threads=args.num_threads,
sample_rate=args.sample_rate,
feature_dim=args.feature_dim,
lm=args.lm,
lm_scale=args.lm_scale,
lodr_fst=args.lodr_fst,
lodr_scale=args.lodr_scale,
decoding_method=args.decoding_method,
hotwords_file=args.hotwords_file,
hotwords_score=args.hotwords_score,
Expand Down
34 changes: 34 additions & 0 deletions python-api-examples/online-decode-files.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@
./sherpa-onnx-streaming-zipformer-en-2023-06-26/test_wavs/1.wav \
./sherpa-onnx-streaming-zipformer-en-2023-06-26/test_wavs/8k.wav

or with RNN LM rescoring and LODR:

./python-api-examples/online-decode-files.py \
--tokens=./sherpa-onnx-streaming-zipformer-en-2023-06-26/tokens.txt \
--encoder=./sherpa-onnx-streaming-zipformer-en-2023-06-26/encoder-epoch-99-avg-1-chunk-16-left-64.onnx \
--decoder=./sherpa-onnx-streaming-zipformer-en-2023-06-26/decoder-epoch-99-avg-1-chunk-16-left-64.onnx \
--joiner=./sherpa-onnx-streaming-zipformer-en-2023-06-26/joiner-epoch-99-avg-1-chunk-16-left-64.onnx \
--decoding-method=modified_beam_search \
--lm=/path/to/lm.onnx \
--lm-scale=0.1 \
--lodr-fst=/path/to/lodr.fst \
--lodr-scale=-0.1 \
./sherpa-onnx-streaming-zipformer-en-2023-06-26/test_wavs/0.wav \
./sherpa-onnx-streaming-zipformer-en-2023-06-26/test_wavs/1.wav \
./sherpa-onnx-streaming-zipformer-en-2023-06-26/test_wavs/8k.wav

(2) Streaming paraformer

curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-paraformer-bilingual-zh-en.tar.bz2
Expand Down Expand Up @@ -186,6 +202,22 @@ def get_args():
""",
)

parser.add_argument(
"--lodr-fst",
metavar="file",
type=str,
default="",
help="Path to LODR FST model. Used only when --lm is given.",
)

parser.add_argument(
"--lodr-scale",
metavar="lodr_scale",
type=float,
default=-0.1,
help="LODR scale for rescoring.Used only when --lodr_fst is given.",
)

parser.add_argument(
"--provider",
type=str,
Expand Down Expand Up @@ -320,6 +352,8 @@ def main():
max_active_paths=args.max_active_paths,
lm=args.lm,
lm_scale=args.lm_scale,
lodr_fst=args.lodr_fst,
lodr_scale=args.lodr_scale,
hotwords_file=args.hotwords_file,
hotwords_score=args.hotwords_score,
modeling_unit=args.modeling_unit,
Expand Down
1 change: 1 addition & 0 deletions sherpa-onnx/csrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(sources
jieba.cc
keyword-spotter-impl.cc
keyword-spotter.cc
lodr-fst.cc
offline-canary-model-config.cc
offline-canary-model.cc
offline-ctc-fst-decoder-config.cc
Expand Down
5 changes: 5 additions & 0 deletions sherpa-onnx/csrc/hypothesis.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
#include <unordered_map>
#include <utility>
#include <vector>
#include <memory>

#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/context-graph.h"
#include "sherpa-onnx/csrc/lodr-fst.h"
#include "sherpa-onnx/csrc/math.h"
#include "sherpa-onnx/csrc/onnx-utils.h"

Expand Down Expand Up @@ -61,6 +63,9 @@ struct Hypothesis {
// the nn lm states
std::vector<CopyableOrtValue> nn_lm_states;

// the LODR states
std::shared_ptr<LodrStateCost> lodr_state;

const ContextState *context_state;

// TODO(fangjun): Make it configurable
Expand Down
Loading
Loading