Skip to content

Commit 967e231

Browse files
committed
Documentation formatting updates
1 parent ecbfeb5 commit 967e231

8 files changed

Lines changed: 117 additions & 106 deletions

File tree

speechbrain/decoders/ctc.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class CTCPrefixScorer:
1717
reference: https://www.merl.com/publications/docs/TR2017-190.pdf.
1818
Official implementation: https://github.com/espnet/espnet/blob/master/espnet/nets/ctc_prefix_score.py
1919
20-
Parameters
21-
----------
20+
Arguments
21+
---------
2222
x : torch.Tensor
2323
The encoder states.
2424
enc_lens : torch.Tensor
@@ -300,17 +300,17 @@ def filter_ctc_output(string_pred, blank_id=-1):
300300
the id of the blank
301301
302302
Returns
303-
------
303+
-------
304304
list
305305
The output predicted by CTC without the blank symbol and
306306
the repetitions
307307
308308
Example
309309
-------
310-
>>> string_pred = ['a','a','blank','b','b','blank','c']
311-
>>> string_out = filter_ctc_output(string_pred, blank_id='blank')
312-
>>> print(string_out)
313-
['a', 'b', 'c']
310+
>>> string_pred = ['a','a','blank','b','b','blank','c']
311+
>>> string_out = filter_ctc_output(string_pred, blank_id='blank')
312+
>>> print(string_out)
313+
['a', 'b', 'c']
314314
"""
315315

316316
if isinstance(string_pred, list):
@@ -357,13 +357,13 @@ def ctc_greedy_decode(probabilities, seq_lens, blank_id=-1):
357357
358358
Example
359359
-------
360-
>>> import torch
361-
>>> probs = torch.tensor([[[0.3, 0.7], [0.0, 0.0]],
362-
... [[0.2, 0.8], [0.9, 0.1]]])
363-
>>> lens = torch.tensor([0.51, 1.0])
364-
>>> blank_id = 0
365-
>>> ctc_greedy_decode(probs, lens, blank_id)
366-
[[1], [1]]
360+
>>> import torch
361+
>>> probs = torch.tensor([[[0.3, 0.7], [0.0, 0.0]],
362+
... [[0.2, 0.8], [0.9, 0.1]]])
363+
>>> lens = torch.tensor([0.51, 1.0])
364+
>>> blank_id = 0
365+
>>> ctc_greedy_decode(probs, lens, blank_id)
366+
[[1], [1]]
367367
"""
368368
if isinstance(blank_id, int) and blank_id < 0:
369369
blank_id = probabilities.shape[-1] + blank_id

speechbrain/decoders/seq2seq.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class S2SBaseSearcher(torch.nn.Module):
3232
3333
Returns
3434
-------
35-
predictions:
35+
predictions
3636
Outputs as Python list of lists, with "ragged" dimensions; padding
3737
has been removed.
38-
scores:
38+
scores
3939
The sum of log probabilities (and possibly
4040
additional heuristic scores) for each prediction.
4141
@@ -864,8 +864,9 @@ class S2SRNNBeamSearcher(S2SBeamSearcher):
864864
This class implements the beam search decoding
865865
for AttentionalRNNDecoder (speechbrain/nnet/RNN.py).
866866
See also S2SBaseSearcher(), S2SBeamSearcher().
867-
Parameters
868-
----------
867+
868+
Arguments
869+
---------
869870
embedding : torch.nn.Module
870871
An embedding layer
871872
decoder : torch.nn.Module
@@ -877,6 +878,7 @@ class S2SRNNBeamSearcher(S2SBeamSearcher):
877878
distribution, being softer when T>1 and sharper with T<1.
878879
**kwargs
879880
see S2SBeamSearcher, arguments are directly passed
881+
880882
Example
881883
-------
882884
>>> emb = torch.nn.Embedding(5, 3)
@@ -967,8 +969,9 @@ class S2SRNNBeamSearchLM(S2SRNNBeamSearcher):
967969
This class implements the beam search decoding
968970
for AttentionalRNNDecoder (speechbrain/nnet/RNN.py) with LM.
969971
See also S2SBaseSearcher(), S2SBeamSearcher(), S2SRNNBeamSearcher().
970-
Parameters
971-
----------
972+
973+
Arguments
974+
---------
972975
embedding : torch.nn.Module
973976
An embedding layer
974977
decoder : torch.nn.Module
@@ -982,6 +985,7 @@ class S2SRNNBeamSearchLM(S2SRNNBeamSearcher):
982985
distribution, being softer when T>1 and sharper with T<1.
983986
**kwargs
984987
Arguments to pass to S2SBeamSearcher
988+
985989
Example
986990
-------
987991
>>> from speechbrain.lobes.models.RNNLM import RNNLM
@@ -1060,8 +1064,9 @@ class S2SRNNBeamSearchTransformerLM(S2SRNNBeamSearcher):
10601064
This class implements the beam search decoding
10611065
for AttentionalRNNDecoder (speechbrain/nnet/RNN.py) with LM.
10621066
See also S2SBaseSearcher(), S2SBeamSearcher(), S2SRNNBeamSearcher().
1063-
Parameters
1064-
----------
1067+
1068+
Arguments
1069+
---------
10651070
embedding : torch.nn.Module
10661071
An embedding layer
10671072
decoder : torch.nn.Module
@@ -1075,6 +1080,7 @@ class S2SRNNBeamSearchTransformerLM(S2SRNNBeamSearcher):
10751080
distribution, being softer when T>1 and sharper with T<1.
10761081
**kwargs
10771082
Arguments to pass to S2SBeamSearcher
1083+
10781084
Example
10791085
-------
10801086
>>> from speechbrain.lobes.models.transformer.TransformerLM import TransformerLM
@@ -1142,8 +1148,8 @@ def inflate_tensor(tensor, times, dim):
11421148
"""
11431149
This function inflates the tensor for times along dim.
11441150
1145-
Parameters
1146-
----------
1151+
Arguments
1152+
---------
11471153
tensor : torch.Tensor
11481154
The tensor to be inflated.
11491155
times : int
@@ -1173,8 +1179,8 @@ def mask_by_condition(tensor, cond, fill_value):
11731179
"""
11741180
This function will mask some element in the tensor with fill_value, if condition=False.
11751181
1176-
Parameters
1177-
----------
1182+
Arguments
1183+
---------
11781184
tensor : torch.Tensor
11791185
The tensor to be masked.
11801186
cond : torch.BoolTensor
@@ -1283,8 +1289,8 @@ def lm_forward_step(self, inp_tokens, memory):
12831289
def batch_filter_seq2seq_output(prediction, eos_id=-1):
12841290
"""Calling batch_size times of filter_seq2seq_output.
12851291
1286-
Parameters
1287-
----------
1292+
Arguments
1293+
---------
12881294
prediction : list of torch.Tensor
12891295
a list containing the output ints predicted by the seq2seq system.
12901296
eos_id : int, string
@@ -1297,10 +1303,10 @@ def batch_filter_seq2seq_output(prediction, eos_id=-1):
12971303
12981304
Example
12991305
-------
1300-
>>> predictions = [torch.IntTensor([1,2,3,4]), torch.IntTensor([2,3,4,5,6])]
1301-
>>> predictions = batch_filter_seq2seq_output(predictions, eos_id=4)
1302-
>>> predictions
1303-
[[1, 2, 3], [2, 3]]
1306+
>>> predictions = [torch.IntTensor([1,2,3,4]), torch.IntTensor([2,3,4,5,6])]
1307+
>>> predictions = batch_filter_seq2seq_output(predictions, eos_id=4)
1308+
>>> predictions
1309+
[[1, 2, 3], [2, 3]]
13041310
"""
13051311
outputs = []
13061312
for p in prediction:
@@ -1312,8 +1318,8 @@ def batch_filter_seq2seq_output(prediction, eos_id=-1):
13121318
def filter_seq2seq_output(string_pred, eos_id=-1):
13131319
"""Filter the output until the first eos occurs (exclusive).
13141320
1315-
Parameters
1316-
----------
1321+
Arguments
1322+
---------
13171323
string_pred : list
13181324
a list containing the output strings/ints predicted by the seq2seq system.
13191325
eos_id : int, string
@@ -1326,10 +1332,10 @@ def filter_seq2seq_output(string_pred, eos_id=-1):
13261332
13271333
Example
13281334
-------
1329-
>>> string_pred = ['a','b','c','d','eos','e']
1330-
>>> string_out = filter_seq2seq_output(string_pred, eos_id='eos')
1331-
>>> string_out
1332-
['a', 'b', 'c', 'd']
1335+
>>> string_pred = ['a','b','c','d','eos','e']
1336+
>>> string_out = filter_seq2seq_output(string_pred, eos_id='eos')
1337+
>>> string_out
1338+
['a', 'b', 'c', 'd']
13331339
"""
13341340
if isinstance(string_pred, list):
13351341
try:

speechbrain/nnet/schedulers.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ def __call__(self, opt):
294294
---------
295295
opt : optimizer
296296
The optimizer to update using this scheduler.
297+
297298
Returns
298299
-------
299300
float
@@ -390,6 +391,7 @@ def __call__(self, opt):
390391
Number of times the dataset has been iterated.
391392
current_loss : int
392393
A number for determining whether to change the learning rate.
394+
393395
Returns
394396
-------
395397
float
@@ -488,6 +490,7 @@ def __call__(self, optim_list, current_epoch, current_loss):
488490
Number of times the dataset has been iterated.
489491
current_loss : int
490492
A number for determining whether to change the learning rate.
493+
491494
Returns
492495
-------
493496
float
@@ -548,6 +551,7 @@ class CyclicLRScheduler:
548551
some constant frequency, as detailed in this paper (https://arxiv.org/abs/1506.01186).
549552
The amplitude of the cycle can be scaled on a per-iteration or
550553
per-cycle basis.
554+
551555
This class has three built-in policies, as put forth in the paper.
552556
"triangular":
553557
A basic triangular cycle w/ no amplitude scaling.
@@ -557,33 +561,35 @@ class CyclicLRScheduler:
557561
A cycle that scales initial amplitude by gamma**(cycle iterations) at each
558562
cycle iteration.
559563
For more detail, please see the reference paper.
564+
560565
Arguments
561-
-------
562-
base_lr: initial learning rate which is the
563-
lower boundary in the cycle.
564-
max_lr: upper boundary in the cycle. Functionally,
565-
it defines the cycle amplitude (max_lr - base_lr).
566-
The lr at any cycle is the sum of base_lr
567-
and some scaling of the amplitude; therefore
568-
max_lr may not actually be reached depending on
569-
scalling function.
570-
step_size: number of training iterations per
571-
half cycle. The authors suggest setting step_size
572-
2-8 x training iterations in epoch.
573-
mode: one of {triangular, triangular2, exp_range}.
574-
Default 'triangular'.
575-
Values correspond to policies detailed above.
576-
If scale_fn is not None, this argument is ignored.
577-
gamma: constant in 'exp_range' scaling function:
578-
gamma**(cycle iterations)
579-
scale_fn: Custom scaling policy defined by a single
580-
argument lambda function, where
581-
0 <= scale_fn(x) <= 1 for all x >= 0.
582-
mode paramater is ignored
583-
scale_mode: {'cycle', 'iterations'}.
584-
Defines whether scale_fn is evaluated on
585-
cycle number or cycle iterations (training
586-
iterations since start of cycle). Default is 'cycle'.
566+
---------
567+
base_lr: initial learning rate which is the
568+
lower boundary in the cycle.
569+
max_lr: upper boundary in the cycle. Functionally,
570+
it defines the cycle amplitude (max_lr - base_lr).
571+
The lr at any cycle is the sum of base_lr
572+
and some scaling of the amplitude; therefore
573+
max_lr may not actually be reached depending on
574+
scalling function.
575+
step_size: number of training iterations per
576+
half cycle. The authors suggest setting step_size
577+
2-8 x training iterations in epoch.
578+
mode: one of {triangular, triangular2, exp_range}.
579+
Default 'triangular'.
580+
Values correspond to policies detailed above.
581+
If scale_fn is not None, this argument is ignored.
582+
gamma: constant in 'exp_range' scaling function:
583+
gamma**(cycle iterations)
584+
scale_fn: Custom scaling policy defined by a single
585+
argument lambda function, where
586+
0 <= scale_fn(x) <= 1 for all x >= 0.
587+
mode paramater is ignored
588+
scale_mode: {'cycle', 'iterations'}.
589+
Defines whether scale_fn is evaluated on
590+
cycle number or cycle iterations (training
591+
iterations since start of cycle). Default is 'cycle'.
592+
587593
Example
588594
-------
589595
>>> from speechbrain.nnet.linear import Linear

speechbrain/processing/decomposition.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ def svdl(a):
127127
128128
Arguments:
129129
----------
130-
a : tensor
131-
A complex input matrix to work with. The tensor must have
132-
the following format: (*,2,C+P).
130+
a : tensor
131+
A complex input matrix to work with. The tensor must have
132+
the following format: (*,2,C+P).
133133
134134
Example:
135135
--------
@@ -365,9 +365,9 @@ def inv(x):
365365
366366
Arguments
367367
---------
368-
x : tensor
369-
An input matrix to work with. The tensor must have the
370-
following format: (*, 2, C+P)
368+
x : tensor
369+
An input matrix to work with. The tensor must have the
370+
following format: (*, 2, C+P)
371371
372372
Example
373373
-------

speechbrain/processing/diarization.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
https://github.com/scikit-learn/scikit-learn/blob/0fb307bf3/sklearn/cluster/_spectral.py
1313
1414
Authors
15-
-------
1615
* Nauman Dawalatabad 2020
1716
"""
1817

@@ -356,7 +355,8 @@ def _graph_connected_component(graph, node_id):
356355
357356
Returns
358357
-------
359-
connected_components_matrix : array-like, shape: (n_samples,)
358+
connected_components_matrix : array-like
359+
shape - (n_samples,)
360360
An array of bool value indicating the indexes of the nodes belonging
361361
to the largest connected components of the given query node.
362362
"""
@@ -548,7 +548,8 @@ def spectral_embedding_sb(
548548
549549
Arguments
550550
---------
551-
adjacency : array-like or sparse graph, shape: (n_samples, n_samples)
551+
adjacency : array-like or sparse graph
552+
shape - (n_samples, n_samples)
552553
The adjacency matrix of the graph to embed.
553554
n_components : int
554555
The dimension of the projection subspace.

0 commit comments

Comments
 (0)