Skip to content

Commit

Permalink
formatted the entire LibriSpeech recipe (#1270)
Browse files Browse the repository at this point in the history
* formatted the entire librispeech recipe

* minor updates
  • Loading branch information
JinZr authored Sep 24, 2023
1 parent ef658d6 commit ef5da48
Show file tree
Hide file tree
Showing 26 changed files with 144 additions and 171 deletions.
1 change: 0 additions & 1 deletion egs/librispeech/ASR/conformer_ctc/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ def train_one_epoch(
)

if batch_idx % params.log_interval == 0:

if tb_writer is not None:
loss_info.write_summary(
tb_writer, "train/current_", params.batch_idx_train
Expand Down
1 change: 1 addition & 0 deletions egs/librispeech/ASR/local/download_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

from tqdm.auto import tqdm


# This function is copied from lhotse
def tqdm_urlretrieve_hook(t):
"""Wraps tqdm instance.
Expand Down
4 changes: 2 additions & 2 deletions egs/librispeech/ASR/long_file_recog/beam_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def greedy_search_batch(
encoder_out = model.joiner.encoder_proj(packed_encoder_out.data)

offset = 0
for (t, batch_size) in enumerate(batch_size_list):
for t, batch_size in enumerate(batch_size_list):
start = offset
end = offset + batch_size
current_encoder_out = encoder_out.data[start:end]
Expand Down Expand Up @@ -507,7 +507,7 @@ def modified_beam_search(

offset = 0
finalized_B = []
for (t, batch_size) in enumerate(batch_size_list):
for t, batch_size in enumerate(batch_size_list):
start = offset
end = offset + batch_size
current_encoder_out = encoder_out.data[start:end]
Expand Down
1 change: 0 additions & 1 deletion egs/librispeech/ASR/long_file_recog/merge_chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def _merge(cut_list: List[Cut], rec_id: str, utt_idx: int):

futures = []
with ThreadPoolExecutor(max_workers=1) as executor:

for cut in cuts_chunk:
cur_rec_id = cut.recording.id
if len(cut_list) == 0:
Expand Down
1 change: 1 addition & 0 deletions egs/librispeech/ASR/long_file_recog/recognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def decode_dataset(
- timestamps of reference transcript
- timestamps of predicted result
"""

# Background worker to add alignemnt and save cuts to disk.
def _save_worker(
cuts: List[Cut],
Expand Down
1 change: 0 additions & 1 deletion egs/librispeech/ASR/pruned2_knowledge/optim.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def __init__(
weight_decay=1e-3,
target_rms=0.1,
):

if not 0.0 <= lr:
raise ValueError("Invalid learning rate: {}".format(lr))
if not 0.0 <= eps:
Expand Down
12 changes: 5 additions & 7 deletions egs/librispeech/ASR/pruned_transducer_stateless2/beam_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def greedy_search_batch(
encoder_out = model.joiner.encoder_proj(packed_encoder_out.data)

offset = 0
for (t, batch_size) in enumerate(batch_size_list):
for t, batch_size in enumerate(batch_size_list):
start = offset
end = offset + batch_size
current_encoder_out = encoder_out.data[start:end]
Expand Down Expand Up @@ -1019,7 +1019,7 @@ def modified_beam_search(

offset = 0
finalized_B = []
for (t, batch_size) in enumerate(batch_size_list):
for t, batch_size in enumerate(batch_size_list):
start = offset
end = offset + batch_size
current_encoder_out = encoder_out.data[start:end]
Expand Down Expand Up @@ -1227,7 +1227,7 @@ def modified_beam_search_lm_rescore(

offset = 0
finalized_B = []
for (t, batch_size) in enumerate(batch_size_list):
for t, batch_size in enumerate(batch_size_list):
start = offset
end = offset + batch_size
current_encoder_out = encoder_out.data[start:end]
Expand Down Expand Up @@ -1427,7 +1427,7 @@ def modified_beam_search_lm_rescore_LODR(

offset = 0
finalized_B = []
for (t, batch_size) in enumerate(batch_size_list):
for t, batch_size in enumerate(batch_size_list):
start = offset
end = offset + batch_size
current_encoder_out = encoder_out.data[start:end]
Expand Down Expand Up @@ -2608,7 +2608,6 @@ def modified_beam_search_LODR(
context_score = 0
new_context_state = None if context_graph is None else hyp.context_state
if new_token not in (blank_id, unk_id):

if context_graph is not None:
(
context_score,
Expand Down Expand Up @@ -2758,7 +2757,7 @@ def modified_beam_search_lm_shallow_fusion(

offset = 0
finalized_B = []
for (t, batch_size) in enumerate(batch_size_list):
for t, batch_size in enumerate(batch_size_list):
start = offset
end = offset + batch_size
current_encoder_out = encoder_out.data[start:end] # get batch
Expand Down Expand Up @@ -2900,7 +2899,6 @@ def modified_beam_search_lm_shallow_fusion(
new_token = topk_token_indexes[k]
new_timestamp = hyp.timestamp[:]
if new_token not in (blank_id, unk_id):

ys.append(new_token)
new_timestamp.append(t)

Expand Down
1 change: 0 additions & 1 deletion egs/librispeech/ASR/pruned_transducer_stateless2/optim.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def __init__(
weight_decay=1e-3,
target_rms=0.1,
):

if not 0.0 <= lr:
raise ValueError("Invalid learning rate: {}".format(lr))
if not 0.0 <= eps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ def _flatten_parameters(self, flat_weights) -> None:
return

with torch.cuda.device_of(first_fw):

# Note: no_grad() is necessary since _cudnn_rnn_flatten_weight is
# an inplace operation on self._flat_weights
with torch.no_grad():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class CodebookIndexExtractor:
"""

def __init__(self, params: AttributeDict):

self.params = params
params.subsets = ["clean-100"]
if self.params.full_libri:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def batch_force_alignment(

offset = 0
finalized_B = []
for (t, batch_size) in enumerate(batch_size_list):
for t, batch_size in enumerate(batch_size_list):
start = offset
end = offset + batch_size
current_encoder_out = encoder_out.data[start:end]
Expand Down
1 change: 0 additions & 1 deletion egs/librispeech/ASR/streaming_conformer_ctc/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ def train_one_epoch(
)

if batch_idx % params.log_interval == 0:

if tb_writer is not None:
loss_info.write_summary(
tb_writer, "train/current_", params.batch_idx_train
Expand Down
1 change: 0 additions & 1 deletion egs/librispeech/ASR/tdnn_lstm_ctc/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ def train_one_epoch(
f"tot_loss[{tot_loss}], batch size: {batch_size}"
)
if batch_idx % params.log_interval == 0:

if tb_writer is not None:
loss_info.write_summary(
tb_writer, "train/current_", params.batch_idx_train
Expand Down
1 change: 0 additions & 1 deletion egs/librispeech/ASR/transducer/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ def train_one_epoch(
)

if batch_idx % params.log_interval == 0:

if tb_writer is not None:
loss_info.write_summary(
tb_writer, "train/current_", params.batch_idx_train
Expand Down
1 change: 0 additions & 1 deletion egs/librispeech/ASR/transducer_lstm/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ def train_one_epoch(
)

if batch_idx % params.log_interval == 0:

if tb_writer is not None:
loss_info.write_summary(
tb_writer, "train/current_", params.batch_idx_train
Expand Down
2 changes: 1 addition & 1 deletion egs/librispeech/ASR/zipformer/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, *args):
self.pairs = list(args[0].pairs)
else:
self.pairs = [(float(x), float(y)) for x, y in args]
for (x, y) in self.pairs:
for x, y in self.pairs:
assert isinstance(x, (float, int)), type(x)
assert isinstance(y, (float, int)), type(y)

Expand Down
8 changes: 1 addition & 7 deletions icefall/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# isort:skip_file

from . import (
checkpoint,
decode,
dist,
env,
utils
)
from . import checkpoint, decode, dist, env, utils

from .byte_utils import (
byte_decode,
Expand Down
1 change: 0 additions & 1 deletion icefall/context_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ def draw(
filename: Optional[str] = "",
symbol_table: Optional[Dict[int, str]] = None,
) -> "Digraph": # noqa

"""Visualize a ContextGraph via graphviz.
Render ContextGraph as an image via graphviz, and return the Digraph object;
Expand Down
Loading

0 comments on commit ef5da48

Please sign in to comment.