fix(asr): collect whole labels in FeatureLabel.uniq_labels - #16107
Open
udsy19 wants to merge 2 commits into
Open
fix(asr): collect whole labels in FeatureLabel.uniq_labels#16107udsy19 wants to merge 2 commits into
udsy19 wants to merge 2 commits into
Conversation
`FeatureLabel.__init__` accumulated `self.uniq_labels |= set(label)`. `label` is the manifest's label string, so `set()` yielded its characters: a corpus labelled `speech`/`background` produced a 14-entry vocabulary of single letters instead of `['background', 'speech']`. `uniq_labels` is the label-vocabulary fallback for `FeatureToLabelDataset` (`self.labels = labels if labels else self.collection.uniq_labels`), so the documented `labels=None` behaviour was unusable in two further ways: the result was a bare `set` while every other producer yields a list, making `self.labels[:5]` raise `TypeError: 'set' object is not subscriptable`; and on the regression path `label` is a `float`, so `set(label)` raised `TypeError: 'float' object is not iterable` before `labels` was ever consulted. Compute it after the loop, exactly as the audio-side sibling `SpeechLabel` already does, which fixes all three at once. Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
The filtered-duration log line divided seconds by 2600; the total-duration line immediately below it, and every other collection in this module, divide by 3600. Log output only. Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do ?
Makes
FeatureLabelcollect whole labels instead of the characters of each label string.Collection: ASR
Fixes #16106.
Changelog
FeatureLabel.__init__accumulatedself.uniq_labels |= set(label).labelis the manifest's labelstring, so
set()yielded its characters: a corpus labelledspeech/backgroundproduced a14-entry vocabulary of single letters instead of
['background', 'speech'].uniq_labelsis the label-vocabulary fallback forFeatureToLabelDataset(
self.labels = labels if labels else self.collection.uniq_labels), so three failures follow from thatone line:
TypeError: 'set' object is not subscriptableatfeature_to_label.py:358(self.labels[:5]),because
uniq_labelsis a baresetwhile every other producer ofself.labelsyields a list —so the documented
labels=Nonefallback cannot work at all;TypeError: 'float' object is not iterableon the regression path, whereASRFeatureLabelsetslabel = float(item['label']). This raises insideASRFeatureLabel.__init__, beforelabelsisconsulted, so passing an explicit label list does not avoid it.
The fix computes
uniq_labelsafter the loop, exactly the way the audio-side siblingSpeechLabelalready does in the same module:
That single line fixes all three, and makes
FeatureLabelagree with bothSpeechLabelandFeatureToMultiLabelDataset._get_label_set().A second, separate commit fixes the adjacent log line in the same function, which divided the filtered
duration by
2600instead of3600— the line immediately below it, and every other collection inthis module, use
3600. It is log output only and is kept as its own commit so it can be droppedindependently if preferred.
Testing
Extended the existing
tests/collections/asr/test_label_datasets.py::TestASRDatasets(which alreadyhas a
tempfile-basedtest_feat_label_dataset) with 5 unit tests:uniq_labelsholds whole labels, not characters;ASRSpeechLabel.uniq_labelson an equivalent manifest (sibling control);FeatureToLabelDataset(labels=None)buildslabels/num_classes/label2idand yields theright label tensor;
FeatureToMultiLabelDataset(labels=None)on the same manifest (siblingcontrol);
ASRFeatureLabel(..., is_regression_task=True)constructs and returns[0.5, 1.5].Results on this branch:
assert {'a','b','c',...} == ['background','speech'];TypeError: 'set' object is not subscriptable;TypeError: 'float' object is not iterable)The test that passes in both states is the pre-existing
test_feat_label_dataset, which passes anexplicit
labels=list — included to show the existing behaviour is preserved.Whole file:
10 passed. Wider run on this branch —tests/collections/asr/test_asr_classification_model.pyandtests/collections/asr/test_asr_regression_model.py: 19 passed.Style:
black24.10.0 andisort5.13.2 (repo settings, line length 119) report no changes;flake8 --config .flake8.otherexits 0;pylint --rcfile .pylintrc.otherratescollections.py10.00/10;
pre-commit run --from-ref main --to-ref HEADpasses.No documentation change: this restores the behaviour the
FeatureToLabelDatasetdocstring alreadydescribes ("if None then automatically picks from the collection") rather than changing an API.
GitHub Actions CI
Trusted PRs run automatically through copy-pr-bot. For an untrusted PR, a maintainer can trigger CI by commenting
/ok to test <head-sha>; repeat this after a new push if the PR remains untrusted.Before your PR is "Ready for review"
Pre checks:
PR Type: