From 183d5f583d60976165c4a05674e2ee3868563ced Mon Sep 17 00:00:00 2001 From: remg1997 Date: Thu, 31 Aug 2023 15:29:09 +0000 Subject: [PATCH 1/2] Upload segment script for FA --- scripts/fa/make_manifest_sentence_segments.py | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 scripts/fa/make_manifest_sentence_segments.py diff --git a/scripts/fa/make_manifest_sentence_segments.py b/scripts/fa/make_manifest_sentence_segments.py new file mode 100644 index 00000000..5d210461 --- /dev/null +++ b/scripts/fa/make_manifest_sentence_segments.py @@ -0,0 +1,135 @@ +import json +from pathlib import Path +import os +import glob +import re +import regex +import sox +import tqdm + + +SRC_DATA_DIR = "/home/rafael/supervised_peoples_speech/instructions_for_aligning_peoples_speech_test_set/test_dataset_April_18_2023/data" +TGT_MANIFEST = "manifest.json" + +SEPARATOR = "" + +def is_timestamp_line(line): + TIMESTAMP_REGEX = "^[\d.:,]+ --> [\d.:,]+$" + if re.match(TIMESTAMP_REGEX, line): + return True + return False + +def add_segment_split_to_text(text, segment_separator): + + # remove some symbols for better split into sentences + text = ( + text.replace("\n", " ") + .replace("\t", " ") + .replace("…", "...") + .replace("\\", " ") + .replace("--", " -- ") + .replace(". . .", "...") + ) + + # end of quoted speech - to be able to split sentences by full stop + text = re.sub(r"([\.\?\!])([\"\'])", r"\g<2>\g<1> ", text) + + # remove extra space + text = re.sub(r" +", " ", text) + + # remove normal brackets, square brackets and curly brackets + text = re.sub(r'(\(.*?\))', ' ', text) + text = re.sub(r'(\[.*?\])', ' ', text) + text = re.sub(r'(\{.*?\})', ' ', text) + + # remove space in the middle of the lower case abbreviation to avoid splitting into separate sentences + matches = re.findall(r'[a-z]\.\s[a-z]\.', text) + for match in matches: + text = text.replace(match, match.replace('. ', '.')) + + # find phrases in quotes + with_quotes = re.finditer(r'“[A-Za-z ?]+.*?”', text) + sentences = [] + last_idx = 0 + for m in with_quotes: + match = m.group() + match_idx = m.start() + if last_idx < match_idx: + sentences.append(text[last_idx:match_idx]) + sentences.append(match) + last_idx = m.end() + sentences.append(text[last_idx:]) + sentences = [s.strip() for s in sentences if s.strip()] + + # Read and split text by utterance (roughly, sentences) + split_pattern = f"(? Date: Thu, 31 Aug 2023 15:29:44 +0000 Subject: [PATCH 2/2] fixup: Format Python code with Black --- galvasr2/align/ds_generate_lm.py | 1 - galvasr2/align/generate_lm.py | 1 - galvasr2/align/spark/align_cuda_decoder.py | 1 - galvasr2/align/utils.py | 3 +- galvasr2/utils.py | 1 + galvasr2/yamnet/inference.py | 5 --- galvasr2/yamnet/scripts/histogram.py | 1 - galvasr2/yamnet/yamnet/params.py | 1 + galvasr2/yamnet/yamnet/yamnet.py | 2 +- scripts/fa/make_manifest_sentence_segments.py | 45 ++++++++++--------- .../steps/cleanup/combine_short_segments.py | 2 - .../steps/cleanup/internal/align_ctm_ref.py | 2 +- .../steps/cleanup/make_biased_lms.py | 1 + .../steps/conf/append_prf_to_ctm.py | 2 +- .../steps/conf/prepare_calibration_data.py | 4 +- .../diagnostic/analyze_lattice_depth_stats.py | 1 - .../dict/internal/prune_pron_candidates.py | 2 +- .../steps/dict/internal/sum_arc_info.py | 2 +- .../steps/dict/select_prons_greedy.py | 2 +- .../steps/libs/nnet3/report/log_parse.py | 1 - .../nnet3/train/chain_objf/acoustic_model.py | 1 - .../steps/libs/nnet3/train/common.py | 4 -- .../train/frame_level_objf/acoustic_model.py | 1 - .../nnet3/train/frame_level_objf/common.py | 1 - .../steps/libs/nnet3/xconfig/basic_layers.py | 23 ---------- .../steps/libs/nnet3/xconfig/convolution.py | 1 + .../steps/libs/nnet3/xconfig/gru.py | 14 ++---- .../steps/libs/nnet3/xconfig/lstm.py | 5 +-- .../steps/libs/nnet3/xconfig/parser.py | 1 + .../steps/libs/nnet3/xconfig/utils.py | 1 + .../steps/nnet2/make_multisplice_configs.py | 1 + .../steps/nnet3/chain/e2e/train_e2e.py | 1 - .../steps/nnet3/lstm/make_configs.py | 1 - .../allocate_multilingual_examples.py | 1 - .../steps/nnet3/report/generate_plots.py | 4 +- .../steps/nnet3/tdnn/make_configs.py | 1 - .../data/internal/modify_speaker_info.py | 1 + .../librispeech/utils/lang/bpe/apply_bpe.py | 2 - .../librispeech/utils/lang/bpe/learn_bpe.py | 2 - .../librispeech/utils/lang/make_kn_lm.py | 2 - .../utils/lang/make_lexicon_fst.py | 4 +- .../librispeech/utils/lang/make_phone_lm.py | 1 - ...make_position_dependent_subword_lexicon.py | 2 +- .../utils/lang/make_subword_lexicon_fst.py | 7 +-- .../librispeech/utils/nnet/make_nnet_proto.py | 1 + 45 files changed, 56 insertions(+), 107 deletions(-) diff --git a/galvasr2/align/ds_generate_lm.py b/galvasr2/align/ds_generate_lm.py index 3e6ceea8..934293b1 100644 --- a/galvasr2/align/ds_generate_lm.py +++ b/galvasr2/align/ds_generate_lm.py @@ -18,7 +18,6 @@ def convert_and_filter_topk(args): with io.TextIOWrapper( io.BufferedWriter(gzip.open(data_lower, "w+")), encoding="utf-8" ) as file_out: - # Open the input file either from input.txt or input.txt.gz _, file_extension = os.path.splitext(args.input_txt) if file_extension == ".gz": diff --git a/galvasr2/align/generate_lm.py b/galvasr2/align/generate_lm.py index 85734b60..983bc7ef 100644 --- a/galvasr2/align/generate_lm.py +++ b/galvasr2/align/generate_lm.py @@ -15,7 +15,6 @@ def convert_and_filter_topk(output_dir, input_txt, top_k): with io.TextIOWrapper( io.BufferedWriter(gzip.open(data_lower, "w+")), encoding="utf-8" ) as file_out: - # Open the input file either from input.txt or input.txt.gz _, file_extension = os.path.splitext(input_txt) if file_extension == ".gz": diff --git a/galvasr2/align/spark/align_cuda_decoder.py b/galvasr2/align/spark/align_cuda_decoder.py index a66e8962..ac72c642 100644 --- a/galvasr2/align/spark/align_cuda_decoder.py +++ b/galvasr2/align/spark/align_cuda_decoder.py @@ -259,7 +259,6 @@ def main(argv): ], unmount_cmd=["fusermount", "-u"], ) as temp_dir_name: - posix_ctm_out_dir = re.sub( r"^{0}".format(FLAGS.input_gcs_bucket), temp_dir_name, ctm_out_dir ) diff --git a/galvasr2/align/utils.py b/galvasr2/align/utils.py index 3c74accb..c1cf23e4 100644 --- a/galvasr2/align/utils.py +++ b/galvasr2/align/utils.py @@ -186,7 +186,8 @@ def __len__(self): class LimitingPool: """Limits unbound ahead-processing of multiprocessing.Pool's imap method before items get consumed by the iteration caller. - This prevents OOM issues in situations where items represent larger memory allocations.""" + This prevents OOM issues in situations where items represent larger memory allocations. + """ def __init__(self, processes=None, limit_factor=2, sleeping_for=0.1): self.processes = os.cpu_count() if processes is None else processes diff --git a/galvasr2/utils.py b/galvasr2/utils.py index 59c15b3a..bbca1881 100644 --- a/galvasr2/utils.py +++ b/galvasr2/utils.py @@ -2,6 +2,7 @@ import re import sys + # https://stackoverflow.com/a/45176191 def find_runfiles(): """Find the runfiles tree (useful when _not_ run from a zip file)""" diff --git a/galvasr2/yamnet/inference.py b/galvasr2/yamnet/inference.py index 08f1e55c..a25f741c 100644 --- a/galvasr2/yamnet/inference.py +++ b/galvasr2/yamnet/inference.py @@ -82,7 +82,6 @@ def run_inference(config): def get_dataset(config): - logger.debug("Getting file paths") files, filenames = list_files(config["input_path"], config) @@ -237,9 +236,7 @@ def download(url, path): def run_model_on_dataset(yamnet, classes, params, dataset, filenames, config): - with jsonlines.open(config["output_path"], mode="w") as writer: - for batch, filename in zip(dataset, filenames): logger.debug(filename) items = split_into_items(batch, config) @@ -295,7 +292,6 @@ def print_results(writer, filename, results, yamnet_classes, index, config): def run_model_on_batch(yamnet, classes, params, pair): - batch, sr = pair waveform = batch / 32768.0 # Convert to [-1.0, +1.0] @@ -339,7 +335,6 @@ def config_path(): def setup_logging(arguments): - logging_format = "%(asctime)s - %(levelname)s - %(name)s - %(message)s" if arguments["verbose"]: diff --git a/galvasr2/yamnet/scripts/histogram.py b/galvasr2/yamnet/scripts/histogram.py index 05550ffa..417f9b41 100644 --- a/galvasr2/yamnet/scripts/histogram.py +++ b/galvasr2/yamnet/scripts/histogram.py @@ -127,7 +127,6 @@ def config_path(): def setup_logging(arguments): - logging_format = "%(asctime)s - %(levelname)s - %(name)s - %(message)s" if arguments["verbose"]: diff --git a/galvasr2/yamnet/yamnet/params.py b/galvasr2/yamnet/yamnet/params.py index a4e047d2..c1533fcd 100644 --- a/galvasr2/yamnet/yamnet/params.py +++ b/galvasr2/yamnet/yamnet/params.py @@ -17,6 +17,7 @@ from dataclasses import dataclass + # The following hyperparameters (except patch_hop_seconds) were used to train YAMNet, # so expect some variability in performance if you change these. The patch hop can # be changed arbitrarily: a smaller hop should give you more patches from the same diff --git a/galvasr2/yamnet/yamnet/yamnet.py b/galvasr2/yamnet/yamnet/yamnet.py index 41a8750c..8846bf2c 100644 --- a/galvasr2/yamnet/yamnet/yamnet.py +++ b/galvasr2/yamnet/yamnet/yamnet.py @@ -108,7 +108,7 @@ def yamnet(features, params): (params.patch_frames, params.patch_bands, 1), input_shape=(params.patch_frames, params.patch_bands), )(features) - for (i, (layer_fun, kernel, stride, filters)) in enumerate(_YAMNET_LAYER_DEFS): + for i, (layer_fun, kernel, stride, filters) in enumerate(_YAMNET_LAYER_DEFS): net = layer_fun("layer{}".format(i + 1), kernel, stride, filters, params)(net) embeddings = layers.GlobalAveragePooling2D()(net) logits = layers.Dense(units=params.num_classes, use_bias=True)(embeddings) diff --git a/scripts/fa/make_manifest_sentence_segments.py b/scripts/fa/make_manifest_sentence_segments.py index 5d210461..03fdb8ad 100644 --- a/scripts/fa/make_manifest_sentence_segments.py +++ b/scripts/fa/make_manifest_sentence_segments.py @@ -13,14 +13,15 @@ SEPARATOR = "" + def is_timestamp_line(line): TIMESTAMP_REGEX = "^[\d.:,]+ --> [\d.:,]+$" if re.match(TIMESTAMP_REGEX, line): return True return False -def add_segment_split_to_text(text, segment_separator): +def add_segment_split_to_text(text, segment_separator): # remove some symbols for better split into sentences text = ( text.replace("\n", " ") @@ -38,17 +39,17 @@ def add_segment_split_to_text(text, segment_separator): text = re.sub(r" +", " ", text) # remove normal brackets, square brackets and curly brackets - text = re.sub(r'(\(.*?\))', ' ', text) - text = re.sub(r'(\[.*?\])', ' ', text) - text = re.sub(r'(\{.*?\})', ' ', text) - + text = re.sub(r"(\(.*?\))", " ", text) + text = re.sub(r"(\[.*?\])", " ", text) + text = re.sub(r"(\{.*?\})", " ", text) + # remove space in the middle of the lower case abbreviation to avoid splitting into separate sentences - matches = re.findall(r'[a-z]\.\s[a-z]\.', text) + matches = re.findall(r"[a-z]\.\s[a-z]\.", text) for match in matches: - text = text.replace(match, match.replace('. ', '.')) + text = text.replace(match, match.replace(". ", ".")) # find phrases in quotes - with_quotes = re.finditer(r'“[A-Za-z ?]+.*?”', text) + with_quotes = re.finditer(r"“[A-Za-z ?]+.*?”", text) sentences = [] last_idx = 0 for m in with_quotes: @@ -62,7 +63,9 @@ def add_segment_split_to_text(text, segment_separator): sentences = [s.strip() for s in sentences if s.strip()] # Read and split text by utterance (roughly, sentences) - split_pattern = f"(? 0: - left_utt_dur = 0 if left_index >= 0: left_utt_dur = utt_durs[utts[left_index]] @@ -267,7 +266,6 @@ def CombineSegments(input_dir, output_dir, minimum_duration): speakers = spk2utt.keys() speakers.sort() for speaker in speakers: - utts = spk2utt[speaker] # this is an assignment of the reference # In WriteCombinedDirFiles the values of spk2utt will have the list # of combined utts which will be used as reference diff --git a/scripts/recipes/librispeech/steps/cleanup/internal/align_ctm_ref.py b/scripts/recipes/librispeech/steps/cleanup/internal/align_ctm_ref.py index 39c04f2a..96e82c16 100755 --- a/scripts/recipes/librispeech/steps/cleanup/internal/align_ctm_ref.py +++ b/scripts/recipes/librispeech/steps/cleanup/internal/align_ctm_ref.py @@ -530,7 +530,7 @@ def get_ctm_edits( # current_time is the end of the last ctm segment we processesed. current_time = ctm_array[0][0] if ctm_len > 0 else 0.0 - for (ref_word, hyp_word, ref_prev_i, hyp_prev_i, ref_i, hyp_i) in alignment_output: + for ref_word, hyp_word, ref_prev_i, hyp_prev_i, ref_i, hyp_i in alignment_output: try: ctm_pos = hyp_prev_i # This is true because we cannot have errors at the end because diff --git a/scripts/recipes/librispeech/steps/cleanup/make_biased_lms.py b/scripts/recipes/librispeech/steps/cleanup/make_biased_lms.py index eeceb21a..58820901 100755 --- a/scripts/recipes/librispeech/steps/cleanup/make_biased_lms.py +++ b/scripts/recipes/librispeech/steps/cleanup/make_biased_lms.py @@ -57,6 +57,7 @@ ) ) + # This processes one group of input lines; 'group_of_lines' is # an array of lines of input integerized text, e.g. # [ 'utt1 67 89 432', 'utt2 89 48 62' ] diff --git a/scripts/recipes/librispeech/steps/conf/append_prf_to_ctm.py b/scripts/recipes/librispeech/steps/conf/append_prf_to_ctm.py index 8336246b..330f9e94 100755 --- a/scripts/recipes/librispeech/steps/conf/append_prf_to_ctm.py +++ b/scripts/recipes/librispeech/steps/conf/append_prf_to_ctm.py @@ -41,7 +41,7 @@ # Parse the prf records into dictionary, prf_dict = dict() -for (f, c, t, e) in prf: +for f, c, t, e in prf: t_pos = 0 # position in the 't' string, while t_pos < len(t): t1 = t[t_pos:].split(" ", 1)[0] # get 1st token at 't_pos' diff --git a/scripts/recipes/librispeech/steps/conf/prepare_calibration_data.py b/scripts/recipes/librispeech/steps/conf/prepare_calibration_data.py index cfdab1ef..b9cf0dcd 100755 --- a/scripts/recipes/librispeech/steps/conf/prepare_calibration_data.py +++ b/scripts/recipes/librispeech/steps/conf/prepare_calibration_data.py @@ -85,7 +85,7 @@ # Build the targets, if o.conf_targets != "": with open(o.conf_targets, "w") as f: - for (utt, chan, beg, dur, wrd_id, conf, score_tag) in ctm: + for utt, chan, beg, dur, wrd_id, conf, score_tag in ctm: # Skip the words we don't know if being correct, if score_tag == "U": continue @@ -124,7 +124,7 @@ # Build the input features, with open(o.conf_feats, "w") as f: - for (utt, chan, beg, dur, wrd_id, conf, score_tag) in ctm: + for utt, chan, beg, dur, wrd_id, conf, score_tag in ctm: # Build the key, same as previously, key = "%s^%s^%s^%s^%s,%s,%s" % (utt, chan, beg, dur, wrd_id, conf, score_tag) diff --git a/scripts/recipes/librispeech/steps/diagnostic/analyze_lattice_depth_stats.py b/scripts/recipes/librispeech/steps/diagnostic/analyze_lattice_depth_stats.py index 56c7382b..85cce5ff 100755 --- a/scripts/recipes/librispeech/steps/diagnostic/analyze_lattice_depth_stats.py +++ b/scripts/recipes/librispeech/steps/diagnostic/analyze_lattice_depth_stats.py @@ -169,7 +169,6 @@ def GetMean(depth_to_count): for phone, depths in sorted( phone_depth_counts.items(), key=lambda x: -sum(x[1].values()) ): - frequency_percentage = sum(depths.values()) * 100.0 / total_frames if frequency_percentage < args.frequency_cutoff_percentage: continue diff --git a/scripts/recipes/librispeech/steps/dict/internal/prune_pron_candidates.py b/scripts/recipes/librispeech/steps/dict/internal/prune_pron_candidates.py index e5de3189..679024cc 100755 --- a/scripts/recipes/librispeech/steps/dict/internal/prune_pron_candidates.py +++ b/scripts/recipes/librispeech/steps/dict/internal/prune_pron_candidates.py @@ -146,7 +146,7 @@ def PruneProns( # have stats, we append them to the "stats" dict, with a zero count. for word, entry in stats.iteritems(): prons_with_stats = set() - for (pron, count) in entry: + for pron, count in entry: prons_with_stats.add(pron) for pron in lexicon_g2p[word]: if pron not in prons_with_stats: diff --git a/scripts/recipes/librispeech/steps/dict/internal/sum_arc_info.py b/scripts/recipes/librispeech/steps/dict/internal/sum_arc_info.py index f69f01b6..d11719f2 100755 --- a/scripts/recipes/librispeech/steps/dict/internal/sum_arc_info.py +++ b/scripts/recipes/librispeech/steps/dict/internal/sum_arc_info.py @@ -133,7 +133,7 @@ def Main(): if phones not in prons[word]: prons[word].append(phones) - for (word, utt) in stats: + for word, utt in stats: count_sum = 0.0 counts = dict() for phones in stats[(word, utt)]: diff --git a/scripts/recipes/librispeech/steps/dict/select_prons_greedy.py b/scripts/recipes/librispeech/steps/dict/select_prons_greedy.py index e443a363..01a0abd6 100755 --- a/scripts/recipes/librispeech/steps/dict/select_prons_greedy.py +++ b/scripts/recipes/librispeech/steps/dict/select_prons_greedy.py @@ -237,7 +237,7 @@ def OneEMIter(args, word, stats, prons, pron_probs, debug=False): for i in range(len(pron_probs)): pron_probs[i] = pron_probs[i] / s log_like = 0.0 - for (utt, start_frame) in stats[word]: + for utt, start_frame in stats[word]: prob = [] soft_counts = [] for i in range(len(prons[word])): diff --git a/scripts/recipes/librispeech/steps/libs/nnet3/report/log_parse.py b/scripts/recipes/librispeech/steps/libs/nnet3/report/log_parse.py index 5e31c75f..c9c6d76d 100755 --- a/scripts/recipes/librispeech/steps/libs/nnet3/report/log_parse.py +++ b/scripts/recipes/librispeech/steps/libs/nnet3/report/log_parse.py @@ -218,7 +218,6 @@ def fill_nonlin_stats_table_with_regex_result(groups, gate_index, stats_table): def parse_progress_logs_for_nonlinearity_stats(exp_dir): - """Parse progress logs for mean and std stats for non-linearities. e.g. for a line that is parsed from progress.*.log: exp/nnet3/lstm_self_repair_ld5_sp/log/progress.9.log:component name=Lstm3_i diff --git a/scripts/recipes/librispeech/steps/libs/nnet3/train/chain_objf/acoustic_model.py b/scripts/recipes/librispeech/steps/libs/nnet3/train/chain_objf/acoustic_model.py index eb433894..63ec8e4a 100644 --- a/scripts/recipes/librispeech/steps/libs/nnet3/train/chain_objf/acoustic_model.py +++ b/scripts/recipes/librispeech/steps/libs/nnet3/train/chain_objf/acoustic_model.py @@ -651,7 +651,6 @@ def compute_train_cv_probabilities( def compute_progress(dir, iter, run_opts): - prev_model = "{0}/{1}.mdl".format(dir, iter - 1) model = "{0}/{1}.mdl".format(dir, iter) diff --git a/scripts/recipes/librispeech/steps/libs/nnet3/train/common.py b/scripts/recipes/librispeech/steps/libs/nnet3/train/common.py index 301f8dde..ea29cd17 100644 --- a/scripts/recipes/librispeech/steps/libs/nnet3/train/common.py +++ b/scripts/recipes/librispeech/steps/libs/nnet3/train/common.py @@ -143,7 +143,6 @@ def get_successful_models(num_models, log_file_pattern, difference_threshold=1.0 def get_average_nnet_model(dir, iter, nnets_list, run_opts, get_raw_nnet_from_am=True): - next_iter = iter + 1 if get_raw_nnet_from_am: out_model = """- \| nnet3-am-copy --set-raw-nnet=- \ @@ -169,7 +168,6 @@ def get_average_nnet_model(dir, iter, nnets_list, run_opts, get_raw_nnet_from_am def get_best_nnet_model( dir, iter, best_model_index, run_opts, get_raw_nnet_from_am=True ): - best_model = "{dir}/{next_iter}.{best_model_index}.raw".format( dir=dir, next_iter=iter + 1, best_model_index=best_model_index ) @@ -550,7 +548,6 @@ def verify_egs_dir( def compute_presoftmax_prior_scale( dir, alidir, num_jobs, run_opts, presoftmax_prior_scale_power=-0.25 ): - # getting the raw pdf count common_lib.execute_command( """{command} JOB=1:{num_jobs} {dir}/log/acc_pdf.JOB.log \ @@ -707,7 +704,6 @@ def get_learning_rate( def should_do_shrinkage( iter, model_file, shrink_saturation_threshold, get_raw_nnet_from_am=True ): - if iter == 0: return True diff --git a/scripts/recipes/librispeech/steps/libs/nnet3/train/frame_level_objf/acoustic_model.py b/scripts/recipes/librispeech/steps/libs/nnet3/train/frame_level_objf/acoustic_model.py index 4b3c964c..1f994466 100644 --- a/scripts/recipes/librispeech/steps/libs/nnet3/train/frame_level_objf/acoustic_model.py +++ b/scripts/recipes/librispeech/steps/libs/nnet3/train/frame_level_objf/acoustic_model.py @@ -33,7 +33,6 @@ def generate_egs( egs_opts=None, cmvn_opts=None, ): - """Wrapper for calling steps/nnet3/get_egs.sh Generates targets from alignment directory 'alidir', which contains diff --git a/scripts/recipes/librispeech/steps/libs/nnet3/train/frame_level_objf/common.py b/scripts/recipes/librispeech/steps/libs/nnet3/train/frame_level_objf/common.py index e9796728..39c8665b 100644 --- a/scripts/recipes/librispeech/steps/libs/nnet3/train/frame_level_objf/common.py +++ b/scripts/recipes/librispeech/steps/libs/nnet3/train/frame_level_objf/common.py @@ -703,7 +703,6 @@ def get_realign_iters(realign_times, num_iters, num_jobs_initial, num_jobs_final def align(dir, data, lang, run_opts, iter=None, online_ivector_dir=None): - alidir = "{dir}/ali{ali_suffix}".format( dir=dir, ali_suffix="_iter_{0}".format(iter) if iter is not None else "" ) diff --git a/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/basic_layers.py b/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/basic_layers.py index f07b320f..c12773e9 100644 --- a/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/basic_layers.py +++ b/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/basic_layers.py @@ -335,39 +335,32 @@ class XconfigInputLayer(XconfigLayerBase): """ def __init__(self, first_token, key_to_value, prev_names=None): - assert first_token == "input" XconfigLayerBase.__init__(self, first_token, key_to_value, prev_names) def set_default_configs(self): - self.config = {"dim": -1} def check_configs(self): - if self.config["dim"] <= 0: raise RuntimeError( "Dimension of input-layer '{0}'" "should be positive.".format(self.name) ) def get_input_descriptor_names(self): - return [] # there is no 'input' field in self.config. def output_name(self, auxiliary_outputs=None): - # there are no auxiliary outputs as this layer will just pass the input assert auxiliary_outputs is None return self.name def output_dim(self, auxiliary_outputs=None): - # there are no auxiliary outputs as this layer will just pass the input assert auxiliary_outputs is None return self.config["dim"] def get_full_config(self): - # unlike other layers the input layers need to be printed in # 'init.config' (which initializes the neural network prior to the LDA) ans = [] @@ -399,12 +392,10 @@ class XconfigTrivialOutputLayer(XconfigLayerBase): """ def __init__(self, first_token, key_to_value, prev_names=None): - assert first_token == "output" XconfigLayerBase.__init__(self, first_token, key_to_value, prev_names) def set_default_configs(self): - # note: self.config['input'] is a descriptor, '[-1]' means output # the most recent layer. self.config = { @@ -415,7 +406,6 @@ def set_default_configs(self): } def check_configs(self): - if ( self.config["objective-type"] != "linear" and self.config["objective-type"] != "quadratic" @@ -427,20 +417,17 @@ def check_configs(self): ) def output_name(self, auxiliary_outputs=None): - # there are no auxiliary outputs as this layer will just pass the output # of the previous layer assert auxiliary_outputs is None return self.name def output_dim(self, auxiliary_outputs=None): - assert auxiliary_outputs is None # note: each value of self.descriptors is (descriptor, dim, normalized-string, output-string). return self.descriptors["input"]["dim"] def get_full_config(self): - # the input layers need to be printed in 'init.config' (which # initializes the neural network prior to the LDA), in 'ref.config', # which is a version of the config file used for getting left and right @@ -515,12 +502,10 @@ class XconfigOutputLayer(XconfigLayerBase): """ def __init__(self, first_token, key_to_value, prev_names=None): - assert first_token == "output-layer" XconfigLayerBase.__init__(self, first_token, key_to_value, prev_names) def set_default_configs(self): - # note: self.config['input'] is a descriptor, '[-1]' means output # the most recent layer. self.config = { @@ -551,7 +536,6 @@ def set_default_configs(self): } def check_configs(self): - if self.config["dim"] <= -1: raise RuntimeError( "In output-layer, dim has invalid value {0}" @@ -576,7 +560,6 @@ def check_configs(self): ) def auxiliary_outputs(self): - auxiliary_outputs = ["affine"] if self.config["include-log-softmax"]: auxiliary_outputs.append("log-softmax") @@ -584,7 +567,6 @@ def auxiliary_outputs(self): return auxiliary_outputs def output_name(self, auxiliary_output=None): - if auxiliary_output is None: # Note: nodes of type output-node in nnet3 may not be accessed in # Descriptors, so calling this with auxiliary_outputs=None doesn't @@ -601,7 +583,6 @@ def output_name(self, auxiliary_output=None): ) def output_dim(self, auxiliary_output=None): - if auxiliary_output is None: # Note: nodes of type output-node in nnet3 may not be accessed in # Descriptors, so calling this with auxiliary_outputs=None doesn't @@ -623,7 +604,6 @@ def get_full_config(self): return ans def _generate_config(self): - configs = [] # note: each value of self.descriptors is (descriptor, dim, @@ -776,7 +756,6 @@ def __init__(self, first_token, key_to_value, prev_names=None): XconfigLayerBase.__init__(self, first_token, key_to_value, prev_names) def set_default_configs(self): - # note: self.config['input'] is a descriptor, '[-1]' means output # the most recent layer. self.config = { @@ -1345,7 +1324,6 @@ def get_full_config(self): return ans def _generate_config(self): - # note: each value of self.descriptors is (descriptor, dim, # normalized-string, output-string). # by 'descriptor_final_string' we mean a string that can appear in @@ -1398,7 +1376,6 @@ class XconfigExistingLayer(XconfigLayerBase): """ def __init__(self, first_token, key_to_value, prev_names=None): - assert first_token == "existing" XconfigLayerBase.__init__(self, first_token, key_to_value, prev_names) diff --git a/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/convolution.py b/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/convolution.py index a0ef9dd1..2401c8a7 100644 --- a/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/convolution.py +++ b/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/convolution.py @@ -1411,6 +1411,7 @@ def _generate_bottleneck_resblock_config(self): # An example line using this layer is: # channel-average-layer name=channel-average input=Append(2, 4, 6, 8) dim=64 + # the configuration value 'dim' is the output dimension of this layer. # The input dimension is expected to be a multiple of 'dim'. The output # will be the average of 'dim'-sized blocks of the input. diff --git a/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/gru.py b/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/gru.py index 1cd6ad84..bb5b2ce5 100644 --- a/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/gru.py +++ b/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/gru.py @@ -13,6 +13,7 @@ import sys from libs.nnet3.xconfig.basic_layers import XconfigLayerBase + # This class is for lines like # 'gru-layer name=gru1 input=[-1] delay=-3' # It generates an GRU sub-graph without output projections. @@ -91,7 +92,6 @@ def get_full_config(self): # convenience function to generate the GRU config def generate_gru_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness @@ -397,7 +397,6 @@ def get_full_config(self): # convenience function to generate the PGRU config def generate_pgru_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness @@ -736,7 +735,6 @@ def get_full_config(self): # convenience function to generate the Norm-PGRU config def generate_pgru_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness @@ -1125,7 +1123,6 @@ def get_full_config(self): # convenience function to generate the OPGRU config def generate_pgru_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness @@ -1336,6 +1333,7 @@ def generate_pgru_config(self): # Different from the vanilla OPGRU, the NormOPGRU uses batchnorm in the forward direction # and renorm in the recurrence. + # The output dimension of the layer may be specified via 'cell-dim=xxx', but if not specified, # the dimension defaults to the same as the input. # See other configuration values below. @@ -1475,7 +1473,6 @@ def get_full_config(self): # convenience function to generate the Norm-OPGRU config def generate_pgru_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness @@ -1841,7 +1838,6 @@ def get_full_config(self): # convenience function to generate the GRU config def generate_gru_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness @@ -2123,7 +2119,6 @@ def get_full_config(self): # convenience function to generate the PGRU config def generate_pgru_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness @@ -2299,6 +2294,7 @@ def generate_pgru_config(self): # Different from the vanilla PGRU, the NormPGRU uses batchnorm in the forward direction # and renorm in the recurrence. + # The output dimension of the layer may be specified via 'cell-dim=xxx', but if not specified, # the dimension defaults to the same as the input. # See other configuration values below. @@ -2444,7 +2440,6 @@ def get_full_config(self): # convenience function to generate the Norm-PGRU config def generate_pgru_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness @@ -2824,7 +2819,6 @@ def get_full_config(self): # convenience function to generate the OPGRU config def generate_pgru_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness @@ -3013,6 +3007,7 @@ def generate_pgru_config(self): # Different from the vanilla OPGRU, the NormOPGRU uses batchnorm in the forward direction # and renorm in the recurrence. + # The output dimension of the layer may be specified via 'cell-dim=xxx', but if not specified, # the dimension defaults to the same as the input. # See other configuration values below. @@ -3158,7 +3153,6 @@ def get_full_config(self): # convenience function to generate the Norm-OPGRU config def generate_pgru_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness diff --git a/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/lstm.py b/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/lstm.py index 107a1777..9f9d8676 100644 --- a/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/lstm.py +++ b/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/lstm.py @@ -123,7 +123,6 @@ def get_full_config(self): # convenience function to generate the LSTM config def _generate_lstm_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness @@ -530,7 +529,6 @@ def get_full_config(self): # convenience function to generate the LSTM config def _generate_lstm_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness @@ -995,7 +993,6 @@ def get_full_config(self): # convenience function to generate the LSTM config def _generate_lstm_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness @@ -1138,6 +1135,7 @@ def _generate_lstm_config(self): # And the LSTM is followed by a batchnorm component (this is by default; it's not # part of the layer name, like lstmb-batchnorm-layer). + # # The output dimension of the layer may be specified via 'cell-dim=xxx', but if not specified, # the dimension defaults to the same as the input. @@ -1233,7 +1231,6 @@ def get_full_config(self): # convenience function to generate the LSTM config def _generate_lstm_config(self): - # assign some variables to reduce verbosity name = self.name # in the below code we will just call descriptor_strings as descriptors for conciseness diff --git a/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/parser.py b/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/parser.py index 4c2d0581..d91ac8a1 100644 --- a/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/parser.py +++ b/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/parser.py @@ -89,6 +89,7 @@ "delta-layer": xlayers.XconfigDeltaLayer, } + # Turn a config line and a list of previous layers into # either an object representing that line of the config file; or None # if the line was empty after removing comments. diff --git a/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/utils.py b/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/utils.py index 0a534f4c..455a51ae 100644 --- a/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/utils.py +++ b/scripts/recipes/librispeech/steps/libs/nnet3/xconfig/utils.py @@ -201,6 +201,7 @@ def convert_value_to_type(key, dest_type, string_value): # they are interpreted as Offset(prev_layer, -3) where 'prev_layer' # is the previous layer in the config file. + # Also, in any place a raw input/layer/output name can appear, we accept things # like [-1] meaning the previous input/layer/output's name, or [-2] meaning the # last-but-one input/layer/output, and so on. diff --git a/scripts/recipes/librispeech/steps/nnet2/make_multisplice_configs.py b/scripts/recipes/librispeech/steps/nnet2/make_multisplice_configs.py index 65d1ec8c..20375ec2 100755 --- a/scripts/recipes/librispeech/steps/nnet2/make_multisplice_configs.py +++ b/scripts/recipes/librispeech/steps/nnet2/make_multisplice_configs.py @@ -8,6 +8,7 @@ from __future__ import print_function import re, argparse, sys, math, warnings + # returns the set of frame indices required to perform the convolution # between sequences with frame indices in x and y def get_convolution_index_set(x, y): diff --git a/scripts/recipes/librispeech/steps/nnet3/chain/e2e/train_e2e.py b/scripts/recipes/librispeech/steps/nnet3/chain/e2e/train_e2e.py index fdc6cb63..170de9e4 100755 --- a/scripts/recipes/librispeech/steps/nnet3/chain/e2e/train_e2e.py +++ b/scripts/recipes/librispeech/steps/nnet3/chain/e2e/train_e2e.py @@ -535,7 +535,6 @@ def train(args, run_opts): ) for iter in range(num_iters): - percent = num_archives_processed * 100.0 / num_archives_to_process epoch = num_archives_processed * args.num_epochs / num_archives_to_process diff --git a/scripts/recipes/librispeech/steps/nnet3/lstm/make_configs.py b/scripts/recipes/librispeech/steps/nnet3/lstm/make_configs.py index 3ca5c4f9..1f3fbecd 100755 --- a/scripts/recipes/librispeech/steps/nnet3/lstm/make_configs.py +++ b/scripts/recipes/librispeech/steps/nnet3/lstm/make_configs.py @@ -380,7 +380,6 @@ def MakeConfigs( max_change_per_component, max_change_per_component_final, ): - config_lines = {"components": [], "component-nodes": []} config_files = {} diff --git a/scripts/recipes/librispeech/steps/nnet3/multilingual/allocate_multilingual_examples.py b/scripts/recipes/librispeech/steps/nnet3/multilingual/allocate_multilingual_examples.py index 2a62b469..5ba6a66d 100755 --- a/scripts/recipes/librispeech/steps/nnet3/multilingual/allocate_multilingual_examples.py +++ b/scripts/recipes/librispeech/steps/nnet3/multilingual/allocate_multilingual_examples.py @@ -60,7 +60,6 @@ def get_args(): - parser = argparse.ArgumentParser( description=""" This script generates examples for multilingual training of neural network by producing 3 sets of primary files diff --git a/scripts/recipes/librispeech/steps/nnet3/report/generate_plots.py b/scripts/recipes/librispeech/steps/nnet3/report/generate_plots.py index bc8fc53f..f2da47b0 100755 --- a/scripts/recipes/librispeech/steps/nnet3/report/generate_plots.py +++ b/scripts/recipes/librispeech/steps/nnet3/report/generate_plots.py @@ -217,7 +217,6 @@ def generate_acc_logprob_plots( latex_report=None, output_name="output", ): - assert start_iter >= 1 if plot: @@ -293,6 +292,7 @@ def generate_acc_logprob_plots( (0, 0), 1, 1, facecolor="w", fill=False, edgecolor="none", linewidth=0 ) + # This function is used to insert a column to the legend, the column_index is 1-based def insert_a_column_legend( legend_handle, legend_label, lp, mp, hp, dir, prefix_length, column_index @@ -996,7 +996,7 @@ def generate_plots( else: latex_report = None - for (output_name, objective_type) in output_names: + for output_name, objective_type in output_names: if objective_type == "linear": logger.info("Generating accuracy plots for '%s'", output_name) generate_acc_logprob_plots( diff --git a/scripts/recipes/librispeech/steps/nnet3/tdnn/make_configs.py b/scripts/recipes/librispeech/steps/nnet3/tdnn/make_configs.py index dd5558fc..8efbe929 100755 --- a/scripts/recipes/librispeech/steps/nnet3/tdnn/make_configs.py +++ b/scripts/recipes/librispeech/steps/nnet3/tdnn/make_configs.py @@ -556,7 +556,6 @@ def MakeConfigs( max_change_per_component_final, objective_type, ): - parsed_splice_output = ParseSpliceString(splice_indexes_string.strip()) left_context = parsed_splice_output["left_context"] diff --git a/scripts/recipes/librispeech/utils/data/internal/modify_speaker_info.py b/scripts/recipes/librispeech/utils/data/internal/modify_speaker_info.py index 5f5b2799..58d78764 100755 --- a/scripts/recipes/librispeech/utils/data/internal/modify_speaker_info.py +++ b/scripts/recipes/librispeech/utils/data/internal/modify_speaker_info.py @@ -84,6 +84,7 @@ except Exception as e: sys.exit("modify_speaker_info.py: problem reading utt2dur info: " + str(e)) + # splits a list of utts into a list of lists, based on constraints from the # command line args. Note: the last list will tend to be shorter than the others, # we make no attempt to fix this. diff --git a/scripts/recipes/librispeech/utils/lang/bpe/apply_bpe.py b/scripts/recipes/librispeech/utils/lang/bpe/apply_bpe.py index 3463b7ee..4fbb0980 100755 --- a/scripts/recipes/librispeech/utils/lang/bpe/apply_bpe.py +++ b/scripts/recipes/librispeech/utils/lang/bpe/apply_bpe.py @@ -28,7 +28,6 @@ class BPE(object): def __init__(self, codes, merges=-1, separator="@@", vocab=None, glossaries=None): - codes.seek(0) # check version information @@ -387,7 +386,6 @@ def isolate_glossary(word, glossary): if __name__ == "__main__": - # python 2/3 compatibility if sys.version_info < (3, 0): sys.stderr = codecs.getwriter("UTF-8")(sys.stderr) diff --git a/scripts/recipes/librispeech/utils/lang/bpe/learn_bpe.py b/scripts/recipes/librispeech/utils/lang/bpe/learn_bpe.py index c3588de0..25cc3972 100755 --- a/scripts/recipes/librispeech/utils/lang/bpe/learn_bpe.py +++ b/scripts/recipes/librispeech/utils/lang/bpe/learn_bpe.py @@ -105,7 +105,6 @@ def update_pair_statistics(pair, changed, stats, indices): first, second = pair new_pair = first + second for j, word, old_word, freq in changed: - # find all instances of pair, and update frequency/indices around it i = 0 while True: @@ -266,7 +265,6 @@ def main(infile, outfile, num_symbols, min_frequency=2, verbose=False, is_dict=F if __name__ == "__main__": - # python 2/3 compatibility if sys.version_info < (3, 0): sys.stderr = codecs.getwriter("UTF-8")(sys.stderr) diff --git a/scripts/recipes/librispeech/utils/lang/make_kn_lm.py b/scripts/recipes/librispeech/utils/lang/make_kn_lm.py index c0924913..b76511c5 100755 --- a/scripts/recipes/librispeech/utils/lang/make_kn_lm.py +++ b/scripts/recipes/librispeech/utils/lang/make_kn_lm.py @@ -227,7 +227,6 @@ def cal_f(self): for n in range(0, self.ngram_order - 1): this_order_counts = self.counts[n] for hist, counts_for_hist in this_order_counts.items(): - n_star_star = 0 for w in counts_for_hist.word_to_count.keys(): n_star_star += len(counts_for_hist.word_to_context[w]) @@ -425,7 +424,6 @@ def print_as_arpa( if __name__ == "__main__": - ngram_counts = NgramCounts(args.ngram_order) if args.text is None: diff --git a/scripts/recipes/librispeech/utils/lang/make_lexicon_fst.py b/scripts/recipes/librispeech/utils/lang/make_lexicon_fst.py index bb2d9bda..af8f0d66 100755 --- a/scripts/recipes/librispeech/utils/lang/make_lexicon_fst.py +++ b/scripts/recipes/librispeech/utils/lang/make_lexicon_fst.py @@ -256,7 +256,7 @@ def write_fst_no_silence(lexicon, nonterminals=None, left_context_phones=None): loop_state = 0 next_state = 1 # the next un-allocated state, will be incremented as we go. - for (word, pronprob, pron) in lexicon: + for word, pronprob, pron in lexicon: cost = -math.log(pronprob) cur_state = loop_state for i in range(len(pron) - 1): @@ -367,7 +367,7 @@ def write_fst_with_silence( ) ) - for (word, pronprob, pron) in lexicon: + for word, pronprob, pron in lexicon: pron_cost = -math.log(pronprob) cur_state = loop_state for i in range(len(pron) - 1): diff --git a/scripts/recipes/librispeech/utils/lang/make_phone_lm.py b/scripts/recipes/librispeech/utils/lang/make_phone_lm.py index ed13b40c..9c6ebca3 100755 --- a/scripts/recipes/librispeech/utils/lang/make_phone_lm.py +++ b/scripts/recipes/librispeech/utils/lang/make_phone_lm.py @@ -359,7 +359,6 @@ def EnsureStructurallyNeededNgramsExist(self): if args.verbose >= 1: num_ngrams_initial = self.GetNumNgrams() for n in reversed(list(range(args.no_backoff_ngram_order, args.ngram_order))): - for hist, counts_for_hist in self.counts[n].items(): # This loop ensures that if we have an n-gram like (6, 7, 8) -> 9, # then, say, (7, 8) -> 9 and (8) -> 9 exist. diff --git a/scripts/recipes/librispeech/utils/lang/make_position_dependent_subword_lexicon.py b/scripts/recipes/librispeech/utils/lang/make_position_dependent_subword_lexicon.py index 5ef1c0a8..c8d609f5 100755 --- a/scripts/recipes/librispeech/utils/lang/make_position_dependent_subword_lexicon.py +++ b/scripts/recipes/librispeech/utils/lang/make_position_dependent_subword_lexicon.py @@ -79,7 +79,7 @@ def write_position_dependent_lexicon(lexiconp, separator): So the suffix_list is initialized with all _I and we only replace the first and last phone suffix when dealing with different cases when necessary. """ - for (word, prob, phones) in lexiconp: + for word, prob, phones in lexiconp: phones_length = len(phones) # suffix_list is initialized by all "_I"s. diff --git a/scripts/recipes/librispeech/utils/lang/make_subword_lexicon_fst.py b/scripts/recipes/librispeech/utils/lang/make_subword_lexicon_fst.py index 662f6fc7..4f6b921a 100755 --- a/scripts/recipes/librispeech/utils/lang/make_subword_lexicon_fst.py +++ b/scripts/recipes/librispeech/utils/lang/make_subword_lexicon_fst.py @@ -8,6 +8,7 @@ import math import sys + # see get_args() below for usage mesage def get_args(): parser = argparse.ArgumentParser( @@ -150,7 +151,7 @@ def write_fst_no_silence(lexicon, position_dependent, separator): word_internal_state = next_state next_state += 1 - for (word, pron_prob, phones) in lexicon: + for word, pron_prob, phones in lexicon: pron_cost = 0.0 # do not support pron_prob phones_len = len(phones) @@ -269,7 +270,7 @@ def write_fst_with_silence( word_internal_state = next_state next_state += 1 - for (word, pron_prob, phones) in lexicon: + for word, pron_prob, phones in lexicon: pron_cost = 0.0 # do not support pron_prob phones_len = len(phones) @@ -318,7 +319,7 @@ def write_fst_with_silence( phone = phones[i] if i >= 0 else "" word = word if i <= 0 else "" cost = pron_cost if i <= 0 else 0.0 - for (end_state, end_cost) in zip(end_state_list, end_cost_list): + for end_state, end_cost in zip(end_state_list, end_cost_list): print_arc(current_state, end_state, phone, word, cost + end_cost) # set the final state diff --git a/scripts/recipes/librispeech/utils/nnet/make_nnet_proto.py b/scripts/recipes/librispeech/utils/nnet/make_nnet_proto.py index 5bc98a1f..23e8eb37 100755 --- a/scripts/recipes/librispeech/utils/nnet/make_nnet_proto.py +++ b/scripts/recipes/librispeech/utils/nnet/make_nnet_proto.py @@ -164,6 +164,7 @@ sum(map(int, re.split("[,:]", o.block_softmax_dims))) == num_leaves ) # posible separators : ',' ':' + # Optionaly scale def Glorot(dim1, dim2): if o.with_glorot: