-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathhparams.py
More file actions
37 lines (31 loc) · 989 Bytes
/
hparams.py
File metadata and controls
37 lines (31 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Utilities for hparams files
Authors
* Artem Ploujnikov 2021
"""
def choice(value, choices, default=None):
"""
The equivalent of a "switch statement" for hparams files. The typical use case
is where different options/modules are available, and a top-level flag decides
which one to use
Arguments
---------
value: any
the value to be used as a flag
choices: dict
a dictionary maps the possible values of the value parameter
to the corresponding return values
default: any
the default value
Returns
-------
The selected option out of the choices
Example
-------
model: !new:speechbrain.lobes.models.g2p.model.TransformerG2P
encoder_emb: !apply:speechbrain.utils.hparams.choice
value: !ref <embedding_type>
choices:
regular: !ref <encoder_emb>
normalized: !ref <encoder_emb_norm>
"""
return choices.get(value, default)