Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix label models restoring issue from weighted cross entropy #4968

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions nemo/collections/asr/models/label_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ def __init__(self, cfg: DictConfig, trainer: Trainer = None):
self.cal_labels_occurrence_train = False
self.labels_occurrence = None

if 'num_classes' in cfg.decoder:
num_classes = cfg.decoder.num_classes
else:
num_classes = cfg.decoder.params.num_classes # to pass test
Comment on lines +92 to +95
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if 'num_classes' in cfg.decoder:
num_classes = cfg.decoder.num_classes
else:
num_classes = cfg.decoder.params.num_classes # to pass test
num_classes = cfg.decoder.num_classes if 'num_classes' in cfg.decoder else cfg.decoder.params.num_classes

Could probably one line this if preferred. Did the parameter move from decoder.params.num_classes to decoder.num_classes? If so maybe adding a message # check for backward compatibility or something

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am looking to remove it and revert the test, since this was done long back. Will address this in another PR.


if 'loss' in cfg:
if 'weight' in cfg.loss:
if cfg.loss.weight == 'auto':
weight = num_classes * [1]
self.cal_labels_occurrence_train = True
else:
weight = cfg.loss.weight
Expand Down Expand Up @@ -142,17 +148,12 @@ def __init__(self, cfg: DictConfig, trainer: Trainer = None):
tmp_loss_cfg = OmegaConf.create(
{"_target_": "nemo.collections.common.losses.cross_entropy.CrossEntropyLoss"}
)

self.loss = instantiate(tmp_loss_cfg)
self.eval_loss = instantiate(tmp_loss_cfg)

self.task = None
self._accuracy = TopKClassificationAccuracy(top_k=[1])

if 'num_classes' in cfg.decoder:
num_classes = cfg.decoder.num_classes
else:
num_classes = cfg.decoder.params.num_classes # to pass test

self.preprocessor = EncDecSpeakerLabelModel.from_config_dict(cfg.preprocessor)
self.encoder = EncDecSpeakerLabelModel.from_config_dict(cfg.encoder)
self.decoder = EncDecSpeakerLabelModel.from_config_dict(cfg.decoder)
Expand Down