Skip to content

Commit

Permalink
update usage instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoyang1998 committed Mar 19, 2024
1 parent 885dd53 commit 862ccd7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
6 changes: 4 additions & 2 deletions egs/librispeech/ASR/zipformer_adapter/export-onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@

2. Export the model to ONNX

./zipformer/export-onnx.py \
./zipformer_adapter/export-onnx.py \
--tokens $repo/data/lang_bpe_500/tokens.txt \
--use-averaged-model 0 \
--epoch 99 \
--avg 1 \
--use-adapters 1 \
--adapter-dim 32 \
--exp-dir $repo/exp \
--num-encoder-layers "2,2,3,4,3,2" \
--downsampling-factor "1,2,4,8,4,2" \
Expand Down Expand Up @@ -131,7 +133,7 @@ def get_parser():
parser.add_argument(
"--exp-dir",
type=str,
default="zipformer/exp",
default="zipformer_adapter/exp",
help="""It specifies the directory where all training related
files, e.g., checkpoints, log, etc, are saved
""",
Expand Down
63 changes: 29 additions & 34 deletions egs/librispeech/ASR/zipformer_adapter/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@

- For non-streaming model:

./zipformer/export.py \
--exp-dir ./zipformer/exp \
./zipformer_adapter/export.py \
--exp-dir ./zipformer_adapter/exp \
--tokens data/lang_bpe_500/tokens.txt \
--epoch 30 \
--use-adapters 1 \
--adapter-dim 16 \
--avg 9 \
--jit 1

Expand All @@ -49,12 +51,14 @@

- For streaming model:

./zipformer/export.py \
--exp-dir ./zipformer/exp \
./zipformer_adapter/export.py \
--exp-dir ./zipformer_adapter/exp \
--causal 1 \
--chunk-size 16 \
--left-context-frames 128 \
--tokens data/lang_bpe_500/tokens.txt \
--use-adapters 1 \
--adapter-dim 16 \
--epoch 30 \
--avg 9 \
--jit 1
Expand All @@ -71,18 +75,22 @@

- For non-streaming model:

./zipformer/export.py \
--exp-dir ./zipformer/exp \
./zipformer_adapter/export.py \
--exp-dir ./zipformer_adapter/exp \
--tokens data/lang_bpe_500/tokens.txt \
--epoch 30 \
--use-adapters 1 \
--adapter-dim 16 \
--avg 9

- For streaming model:

./zipformer/export.py \
--exp-dir ./zipformer/exp \
./zipformer_adapter/export.py \
--exp-dir ./zipformer_adapter/exp \
--causal 1 \
--tokens data/lang_bpe_500/tokens.txt \
--use-adapters 1 \
--adapter-dim 16 \
--epoch 30 \
--avg 9

Expand All @@ -91,33 +99,35 @@

- For non-streaming model:

To use the generated file with `zipformer/decode.py`,
To use the generated file with `zipformer_adapter/decode.py`,
you can do:

cd /path/to/exp_dir
ln -s pretrained.pt epoch-9999.pt

cd /path/to/egs/librispeech/ASR
./zipformer/decode.py \
--exp-dir ./zipformer/exp \
./zipformer_adapter/decode_gigaspeech.py \
--exp-dir ./zipformer_adapter/exp \
--epoch 9999 \
--avg 1 \
--max-duration 600 \
--use-adapters 1 \
--adapter-dim 16 \
--decoding-method greedy_search \
--bpe-model data/lang_bpe_500/bpe.model

- For streaming model:

To use the generated file with `zipformer/decode.py` and `zipformer/streaming_decode.py`, you can do:
To use the generated file with `zipformer_adapter/decode.py` and `zipformer_adapter/streaming_decode.py`, you can do:

cd /path/to/exp_dir
ln -s pretrained.pt epoch-9999.pt

cd /path/to/egs/librispeech/ASR

# simulated streaming decoding
./zipformer/decode.py \
--exp-dir ./zipformer/exp \
./zipformer_adapter/decode_gigaspeech.py \
--exp-dir ./zipformer_adapter/exp \
--epoch 9999 \
--avg 1 \
--max-duration 600 \
Expand All @@ -128,8 +138,8 @@
--bpe-model data/lang_bpe_500/bpe.model

# chunk-wise streaming decoding
./zipformer/streaming_decode.py \
--exp-dir ./zipformer/exp \
./zipformer_adapter/streaming_decode.py \
--exp-dir ./zipformer_adapter/exp \
--epoch 9999 \
--avg 1 \
--max-duration 600 \
Expand All @@ -141,22 +151,6 @@

Check ./pretrained.py for its usage.

Note: If you don't want to train a model from scratch, we have
provided one for you. You can get it at

- non-streaming model:
https://huggingface.co/Zengwei/icefall-asr-librispeech-zipformer-2023-05-15

- streaming model:
https://huggingface.co/Zengwei/icefall-asr-librispeech-streaming-zipformer-2023-05-17

with the following commands:

sudo apt-get install git-lfs
git lfs install
git clone https://huggingface.co/Zengwei/icefall-asr-librispeech-zipformer-2023-05-15
git clone https://huggingface.co/Zengwei/icefall-asr-librispeech-streaming-zipformer-2023-05-17
# You will find the pre-trained models in exp dir
"""

import argparse
Expand All @@ -168,7 +162,7 @@
import torch
from scaling_converter import convert_scaled_to_non_scaled
from torch import Tensor, nn
from train import add_model_arguments, get_model, get_params
from train import add_finetune_arguments, add_model_arguments, get_model, get_params

from icefall.checkpoint import (
average_checkpoints,
Expand Down Expand Up @@ -226,7 +220,7 @@ def get_parser():
parser.add_argument(
"--exp-dir",
type=str,
default="zipformer/exp",
default="zipformer_adapter/exp",
help="""It specifies the directory where all training related
files, e.g., checkpoints, log, etc, are saved
""",
Expand Down Expand Up @@ -257,6 +251,7 @@ def get_parser():
)

add_model_arguments(parser)
add_finetune_arguments(parser)

return parser

Expand Down

0 comments on commit 862ccd7

Please sign in to comment.