Repository: speechbrain/speechbrain

Issue:
Error when yaml contains `!ref` reference to object created by `!new:` without parameters
**Summary of the issue:**

The `!ref` system works fine when `!new:` objects are created with parameters (since they can use an alias) but doesn't work when `!new:` objects are created without parameters (since the reference system just copies an empty value).

**Temporary workaround:**

Add empty mapping or sequence, e.g.

```yaml
model: !new:speechbrain.lobes.models.CRDNN.CRDNN []
```

**An example of this issue in the wild:**

I noticed a weird thing during my latest experiments: In the yaml file, if you instantiate the model without hyperparameters like this:
`model: !new:speechbrain.lobes.models.CRDNN.CRDNN ` 
The code raises an error during the checkpoint:
```
  File "experiment.py", line 99, in <module>
    asr_brain.fit(params.epoch_counter, train_set, valid_set)
  File "/network/tmp1/ravanelm/speechbrain_github/speechbrain/speechbrain/core.py", line 409, in fit
    self.on_epoch_end(epoch, train_stats, valid_stats)
  File "experiment.py", line 73, in on_epoch_end
    importance_keys=[ckpt_recency, lambda c: -c.meta["PER"]],
  File "/network/tmp1/ravanelm/speechbrain_github/speechbrain/speechbrain/utils/checkpoints.py", line 579, in save_and_keep_only
    self.save_checkpoint(meta=meta, end_of_epoch=end_of_epoch, name=name)
  File "/network/tmp1/ravanelm/speechbrain_github/speechbrain/speechbrain/utils/checkpoints.py", line 523, in save_checkpoint
    raise RuntimeError(MSG)
RuntimeError: Don't know how to load <class 'str'>. Register default hook                     or add custom hook for this object.
```
When I add even a single parameter like:
```
model: !new:speechbrain.lobes.models.CRDNN.CRDNN
    activation: !ref <activation>
```
everything works properly.


Discussion:
I tried to reproduce (see attached zip), but at least this MWE seems not to produce that behaviour. 
Could you try this on your installation and see if it happens on yours? Otherwise, could you make a minimum runnable example that does reproduce this?

[mwe.zip](https://github.com/speechbrain/speechbrain/files/4707043/mwe.zip)

Well whaddya know, I could reproduce this on the TIMIT recipe. Like @pplantinga suspected, the `!ref <model>` behaves differently when `model` has no parameters. It can be temporarily fixed by changing the model definition itself: `model: !new:speechbrain.lobes.models.CRDNN.CRDNN []`

Peter, any thoughts on how to fix this?
Its actually a pretty thorny issue... Taking a look, I don't immediately see how to fix it. I think I may update this issue to more accurately reflect the deeper issue.

Resolving patch:
diff --git a/speechbrain/yaml.py b/speechbrain/yaml.py
--- a/speechbrain/yaml.py
+++ b/speechbrain/yaml.py
@@ -345,16 +345,10 @@ def deref(ref, full_tree, copy_mode=False):
             raise ValueError('The reference "%s" is not valid' % ref)
         branch = branch[part]
 
-    # For ruamel.yaml classes, the value is in the tag attribute
-    try:
-        branch = branch.value
-    except AttributeError:
-        pass
-
     if copy_mode:
         return copy.deepcopy(branch)
-    else:
-        return branch
+
+    return branch
 
 
 def recursive_resolve(reference, reference_list, full_tree, copy_mode=False):


Test patch: