Skip to content

Commit

Permalink
Add number of labels calculator functions to DenseLabelInfo (#526)
Browse files Browse the repository at this point in the history
* Add number of labels calculator functions to DenseLabelInfo

* add assertion around correct flag usage

* correctly set braces
  • Loading branch information
NeoLegends authored Jul 8, 2024
1 parent 394a9a9 commit a729a41
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions mm/context_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,39 @@ class DenseLabelInfo:
use_boundary_classes: bool
num_hmm_states_per_phon: int

def num_center_labels(self) -> int:
"""
:return: number of center labels
"""
return self.n_contexts * self.num_hmm_states_per_phon * self._factor()

def num_diphone_labels(self) -> int:
"""
:return: number of diphone labels
"""
return self.num_center_labels() * self.n_contexts

def num_triphone_labels(self) -> int:
"""
:return: number of triphone labels
"""
return self.num_center_labels() * (self.n_contexts**2)

def _factor(self) -> int:
"""
:return: num labels factor introduced by word-end/word-boundary augmentation
"""
assert not (
self.use_word_end_classes and self.use_boundary_classes
), "can only set either word-end or boundary classes"

if self.use_word_end_classes:
return 2
elif self.use_boundary_classes:
return 4
else:
return 1


class GetPhonemeLabelsFromNoTyingDense(Job):
def __init__(
Expand Down

0 comments on commit a729a41

Please sign in to comment.