Skip to content

Commit 5be94bb

Browse files
author
mirco
committed
fixed typos in docstrings
1 parent 46b1d4e commit 5be94bb

61 files changed

Lines changed: 373 additions & 395 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

speechbrain/alignment/aligner.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class HMMAligner(torch.nn.Module):
3838
What kind of batch-level reduction to apply to the loss calculated
3939
in the forward method
4040
input_len_norm: bool
41-
Whether to normalise the loss in the forward method by the length of
41+
Whether to normalize the loss in the forward method by the length of
4242
the inputs.
4343
target_len_norm: bool
44-
Whether to normalise the loss in the forward method by the length of
44+
Whether to normalize the loss in the forward method by the length of
4545
the targets.
4646
lexicon_path: string
4747
The location of the lexicon.
@@ -139,7 +139,7 @@ def __init__(
139139
def _use_lexicon(self, words, interword_sils, sample_pron):
140140
"""
141141
Do processing using the lexicon to return a sequence of the possible
142-
phonemes, the transition/pi probabilities and the possible final states
142+
phonemes, the transition/pi probabilities, and the possible final states
143143
Inputs correspond to a single utterance, not a whole batch
144144
145145
Arguments
@@ -298,7 +298,7 @@ def use_lexicon(
298298
):
299299
"""
300300
Do processing using the lexicon to return a sequence of the possible
301-
phonemes, the transition/pi probabilities and the possible final
301+
phonemes, the transition/pi probabilities, and the possible final
302302
states.
303303
Does processing on an utterance-by-utterance basis. Each utterance
304304
in the batch is processed by a helper method `_use_lexicon`.
@@ -456,7 +456,7 @@ def use_lexicon(
456456
def _make_pi_prob(self, phn_lens_abs):
457457
"""
458458
Creates tensor of initial (log) probabilities (known as 'pi').
459-
Assigns all probability mass to first phoneme in the sequence.
459+
Assigns all probability mass to the first phoneme in the sequence.
460460
461461
Arguments
462462
---------
@@ -548,7 +548,7 @@ def _make_emiss_pred_useful(
548548
):
549549
"""
550550
Creates a 'useful' form of the posterior probabilities, rearranged
551-
into order of phoneme appearance in phns.
551+
into the order of phoneme appearance in phns.
552552
553553
Arguments
554554
---------
@@ -623,7 +623,7 @@ def _dp_forward(
623623
624624
emiss_pred_useful: torch.Tensor (batch, phoneme in phn sequence, time)
625625
A 'useful' form of the posterior probabilities, rearranged
626-
into order of phoneme appearance in phns.
626+
into the order of phoneme appearance in phns.
627627
628628
lens_abs: torch.Tensor (batch)
629629
The absolute length of each input to the acoustic model,
@@ -633,7 +633,7 @@ def _dp_forward(
633633
The absolute length of each phoneme sequence in the batch.
634634
635635
phns: torch.Tensor (batch, phoneme in phn sequence)
636-
The phonemes that are known/thought to be to be in each utterance.
636+
The phonemes that are known/thought to be in each utterance.
637637
638638
Returns
639639
-------
@@ -702,7 +702,7 @@ def _dp_viterbi(
702702
703703
emiss_pred_useful: torch.Tensor (batch, phoneme in phn sequence, time)
704704
A 'useful' form of the posterior probabilities, rearranged
705-
into order of phoneme appearance in phns.
705+
into the order of phoneme appearance in phns.
706706
707707
lens_abs: torch.Tensor (batch)
708708
The absolute length of each input to the acoustic model,
@@ -712,7 +712,7 @@ def _dp_viterbi(
712712
The absolute length of each phoneme sequence in the batch.
713713
714714
phns: torch.Tensor (batch, phoneme in phn sequence)
715-
The phonemes that are known/thought to be to be in each utterance.
715+
The phonemes that are known/thought to be in each utterance.
716716
717717
Returns
718718
-------
@@ -801,7 +801,7 @@ def _dp_viterbi(
801801

802802
def _loss_reduction(self, loss, input_lens, target_lens):
803803
"""
804-
Applies reduction to loss as specified during object initialisation.
804+
Applies reduction to loss as specified during object initialization.
805805
806806
Arguments
807807
---------
@@ -849,7 +849,7 @@ def forward(
849849
"""
850850
Prepares relevant (log) probability tensors and does dynamic
851851
programming: either the forward or the Viterbi algorithm. Applies
852-
reduction as specified during object initialisation.
852+
reduction as specified during object initialization.
853853
854854
Arguments
855855
---------
@@ -1037,9 +1037,9 @@ def _get_flat_start_batch(self, lens_abs, phn_lens_abs, phns):
10371037
"""
10381038
Prepares flat start alignments (with zero padding) for every utterance
10391039
in the batch.
1040-
Every phoneme will have equal duration, except for the final phoneme
1040+
Every phoneme will have an equal duration, except for the final phoneme
10411041
potentially. E.g. if 104 frames and 10 phonemes, 9 phonemes will have
1042-
duration of 10 frames, and one phoneme will have duration of 14 frames.
1042+
duration of 10 frames, and one phoneme will have a duration of 14 frames.
10431043
10441044
Arguments
10451045
---------
@@ -1093,7 +1093,7 @@ def _get_flat_start_batch(self, lens_abs, phn_lens_abs, phns):
10931093
def _get_viterbi_batch(self, ids, lens_abs):
10941094
"""
10951095
Retrieves Viterbi alignments stored in `self.align_dict` and
1096-
creates batch of them, with zero padding.
1096+
creates a batch of them, with zero padding.
10971097
10981098
Arguments
10991099
---------
@@ -1128,7 +1128,7 @@ def get_prev_alignments(self, ids, emission_pred, lens, phns, phn_lens):
11281128
"""
11291129
Fetches previously recorded Viterbi alignments if they are available.
11301130
If not, fetches flat start alignments.
1131-
Currently, assumes that if a Viterbi alignment is not availble for the
1131+
Currently, assumes that if a Viterbi alignment is not available for the
11321132
first utterance in the batch, it will not be available for the rest of
11331133
the utterances.
11341134

speechbrain/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class and override any methods for which the default behavior does not
352352
Arguments
353353
---------
354354
modules : dict of str:torch.nn.Module pairs
355-
These modules are passed to the optimizier by default if they have
355+
These modules are passed to the optimizer by default if they have
356356
trainable parameters, and will have train()/eval() called on them.
357357
opt_class : torch.optim class
358358
A torch optimizer constructor that has takes only the list of
@@ -628,7 +628,7 @@ def make_dataloader(
628628
629629
The Stage.TRAIN DataLoader is handled specially. It has extra args for
630630
shuffle and drop_last. In DDP a DistributedSampler is created (unless
631-
dataset is an IterableDataset).
631+
the dataset is an IterableDataset).
632632
633633
NOTE
634634
----

speechbrain/dataio/batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
class PaddedBatch:
21-
"""Collate_fn when examples are dicts and have variable length sequences.
21+
"""Collate_fn when examples are dicts and have variable-length sequences.
2222
2323
Different elements in the examples get matched by key.
2424
All numpy tensors get converted to Torch (PyTorch default_convert)

speechbrain/dataio/dataio.py

Lines changed: 35 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Data reading and writing
2+
Data reading and writing.
33
44
Authors
55
* Mirco Ravanelli 2020
@@ -25,27 +25,6 @@
2525
logger = logging.getLogger(__name__)
2626

2727

28-
def _recursive_format(data, replacements):
29-
# Data: dict or list, replacements : dict
30-
# Replaces string keys in replacements by their values
31-
# at all levels of data (in str values)
32-
# Works in-place.
33-
if isinstance(data, dict):
34-
for key, item in data.items():
35-
if isinstance(item, dict) or isinstance(item, list):
36-
_recursive_format(item, replacements)
37-
elif isinstance(item, str):
38-
data[key] = item.format_map(replacements)
39-
# If not dict, list or str, do nothing
40-
if isinstance(data, list):
41-
for i, item in enumerate(data):
42-
if isinstance(item, dict) or isinstance(item, list):
43-
_recursive_format(item, replacements)
44-
elif isinstance(item, str):
45-
data[i] = item.format_map(replacements)
46-
# If not dict, list or str, do nothing
47-
48-
4928
def load_data_json(json_path, replacements={}):
5029
"""Loads JSON and recursively formats string values
5130
@@ -80,13 +59,33 @@ def load_data_json(json_path, replacements={}):
8059
'/home/ex2.wav'
8160
8261
"""
83-
# TODO: Example / unittest
8462
with open(json_path, "r") as f:
8563
out_json = json.load(f)
8664
_recursive_format(out_json, replacements)
8765
return out_json
8866

8967

68+
def _recursive_format(data, replacements):
69+
# Data: dict or list, replacements : dict
70+
# Replaces string keys in replacements by their values
71+
# at all levels of data (in str values)
72+
# Works in-place.
73+
if isinstance(data, dict):
74+
for key, item in data.items():
75+
if isinstance(item, dict) or isinstance(item, list):
76+
_recursive_format(item, replacements)
77+
elif isinstance(item, str):
78+
data[key] = item.format_map(replacements)
79+
# If not dict, list or str, do nothing
80+
if isinstance(data, list):
81+
for i, item in enumerate(data):
82+
if isinstance(item, dict) or isinstance(item, list):
83+
_recursive_format(item, replacements)
84+
elif isinstance(item, str):
85+
data[i] = item.format_map(replacements)
86+
# If not dict, list or str, do nothing
87+
88+
9089
def load_data_csv(csv_path, replacements={}):
9190
"""Loads CSV and formats string values
9291
@@ -162,9 +161,9 @@ def load_data_csv(csv_path, replacements={}):
162161

163162

164163
def read_audio(waveforms_obj):
165-
"""General audio loading, based on custom notation
164+
"""General audio loading, based on a custom notation
166165
167-
Expected use case is specifically in conjunction with Datasets
166+
Expected use case is in conjunction with Datasets
168167
specified by JSON.
169168
170169
The custom notation:
@@ -215,9 +214,9 @@ def read_audio(waveforms_obj):
215214

216215

217216
def read_audio_multichannel(waveforms_obj):
218-
"""General audio loading, based on custom notation
217+
"""General audio loading, based on a custom notation
219218
220-
Expected use case is specifically in conjunction with Datasets
219+
Expected use case is in conjunction with Datasets
221220
specified by JSON.
222221
223222
The custom notation:
@@ -233,7 +232,7 @@ def read_audio_multichannel(waveforms_obj):
233232
]
234233
}
235234
236-
Or you can specify a single file more succintly:
235+
Or you can specify a single file more succinctly:
237236
{"files": "/path/to/wav2.wav"}
238237
239238
Offset number samples and stop number samples also can be specified to read
@@ -432,19 +431,19 @@ def convert_index_to_lab(batch, ind2lab):
432431

433432
def relative_time_to_absolute(batch, relative_lens, rate):
434433
"""
435-
Converts SpeechBrain style relative length to absolute duration
434+
Converts SpeechBrain style relative length to the absolute duration
436435
437436
Operates on batch level.
438437
439438
Arguments
440439
---------
441440
batch : torch.tensor
442-
Sequences to determine duration for.
441+
Sequences to determine the duration for.
443442
relative_lens : torch.tensor
444443
The relative length of each sequence in batch. The longest sequence in
445444
the batch needs to have relative length 1.0.
446445
rate : float
447-
The rate at which sequence elements occur in real world time. Sample
446+
The rate at which sequence elements occur in real-world time. Sample
448447
rate, if batch is raw wavs (recommended) or 1/frame_shift if batch is
449448
features. This has to have 1/s as the unit.
450449
@@ -594,58 +593,6 @@ def _expand_data_fields(data_fields):
594593
return expanded
595594

596595

597-
def read_kaldi_lab(kaldi_ali, kaldi_lab_opts):
598-
"""
599-
Read labels in kaldi format
600-
601-
Uses kaldi IO
602-
603-
Arguments
604-
---------
605-
kaldi_ali : str
606-
Path to directory where kaldi alignents are stored.
607-
kaldi_lab_opts : str
608-
A string that contains the options for reading the kaldi alignments.
609-
610-
Returns
611-
-------
612-
dict
613-
A dictionary contaning the labels
614-
615-
Note
616-
----
617-
This depends on kaldi-io-for-python. Install it separately.
618-
See: https://github.com/vesis84/kaldi-io-for-python
619-
620-
Example
621-
-------
622-
This example requires kaldi files
623-
```
624-
lab_folder = '/home/kaldi/egs/TIMIT/s5/exp/dnn4_pretrain-dbn_dnn_ali'
625-
read_kaldi_lab(lab_folder, 'ali-to-pdf')
626-
```
627-
"""
628-
# EXTRA TOOLS
629-
try:
630-
import kaldi_io
631-
except ImportError:
632-
raise ImportError("Could not import kaldi_io. Install it to use this.")
633-
# Reading the Kaldi labels
634-
lab = {
635-
k: v
636-
for k, v in kaldi_io.read_vec_int_ark(
637-
"gunzip -c "
638-
+ kaldi_ali
639-
+ "/ali*.gz | "
640-
+ kaldi_lab_opts
641-
+ " "
642-
+ kaldi_ali
643-
+ "/final.mdl ark:- ark:-|",
644-
)
645-
}
646-
return lab
647-
648-
649596
def write_txt_file(data, filename, sampling_rate=None):
650597
"""
651598
Write data in text format
@@ -732,7 +679,7 @@ def length_to_mask(length, max_len=None, dtype=None, device=None):
732679
length : torch.LongTensor
733680
Containing the length of each sequence in the batch. Must be 1D.
734681
max_len : int
735-
Max length for the mask, also the size of second dimension.
682+
Max length for the mask, also the size of the second dimension.
736683
dtype : torch.dtype, default: None
737684
The dtype of the generated mask.
738685
device: torch.device, default: None
@@ -958,13 +905,13 @@ def merge_char(sequences, space="_"):
958905
Arguments
959906
---------
960907
sequences : list
961-
Each item contains a list, and this list contains character sequence.
908+
Each item contains a list, and this list contains a character sequence.
962909
space : string
963910
The token represents space. Default: _
964911
965912
Returns
966913
-------
967-
The list contain word sequences for each sentence.
914+
The list contains word sequences for each sentence.
968915
969916
Example:
970917
>>> sequences = [["a", "b", "_", "c", "_", "d", "e"], ["e", "f", "g", "_", "h", "i"]]
@@ -1028,13 +975,13 @@ def split_word(sequences, space="_"):
1028975
Arguments
1029976
---------
1030977
sequences : list
1031-
Each item contains a list, and this list contains words sequence.
978+
Each item contains a list, and this list contains a words sequence.
1032979
space : string
1033980
The token represents space. Default: _
1034981
1035982
Returns
1036983
-------
1037-
The list contain word sequences for each sentence.
984+
The list contains word sequences for each sentence.
1038985
1039986
Example:
1040987
>>> sequences = [['ab', 'c', 'de'], ['efg', 'hi']]

0 commit comments

Comments
 (0)