Describe the bug
hparams from load_hyperpyyaml returns a Python dict, yet internally Brain converts it into a SimpleNamespace, which only allows attributes to be accessed via dot notation and no longer from their names.
|
# Make hyperparams available with dot notation too |
|
if hparams is not None: |
|
self.hparams = SimpleNamespace(**hparams) |
When trying to access Brain.hparams by name, you get the following exception: TypeError: 'types.SimpleNamespace' object is not subscriptable
This makes scripting access to hparams -- in particular for parameter transfer applications -- a bit annoying and not at all idiomatic.
Expected behaviour
The described behaviour is unintuitive since I expected to be able to access the parameters in the same way as the hparams I passed originally, that is, by name.
So I would expect
import speechbrain as sb
model = sb.Brain(...)
assert model.hparams["foo"] is model.hparams.foo
To Reproduce
model = EncoderDecoderASR.from_hparams(source="speechbrain/asr-crdnn-rnnlm-librispeech")
model.hparams["asr"]
Environment Details
Python==3.10.16
speechbrain==1.0.3
(other environment details shouldn't be relevant)
Relevant Log Output
Additional Context
An obvious workaround is using getattr (in my example, getattr(model, "asr"). I'm raising the issue mainly as a feature request for native support, but understand if it's not a use case you'd like to support.
Describe the bug
hparamsfromload_hyperpyyamlreturns a Pythondict, yet internallyBrainconverts it into aSimpleNamespace, which only allows attributes to be accessed via dot notation and no longer from their names.speechbrain/speechbrain/core.py
Lines 706 to 708 in 9e068c4
When trying to access
Brain.hparamsby name, you get the following exception:TypeError: 'types.SimpleNamespace' object is not subscriptableThis makes scripting access to
hparams-- in particular for parameter transfer applications -- a bit annoying and not at all idiomatic.Expected behaviour
The described behaviour is unintuitive since I expected to be able to access the parameters in the same way as the
hparamsI passed originally, that is, by name.So I would expect
To Reproduce
Environment Details
Python==3.10.16
speechbrain==1.0.3(other environment details shouldn't be relevant)
Relevant Log Output
Additional Context
An obvious workaround is using
getattr(in my example,getattr(model, "asr"). I'm raising the issue mainly as a feature request for native support, but understand if it's not a use case you'd like to support.