Skip to content

Commit

Permalink
add corrected applicator to linear alignment (#407)
Browse files Browse the repository at this point in the history
* add corrected applicator to linear alignment

* add sis hash exclude

* revert

* change import and rerevert

* more detailed import

* exclude test

* possible fix

* black

* more

* add doc string

* removed -> py3.8
  • Loading branch information
christophmluscher authored May 11, 2023
1 parent f8142ae commit 0ae7ebe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
13 changes: 7 additions & 6 deletions am/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
__all__ = ["acoustic_model_config", "get_align_config_and_crp_for_corrected_applicator"]

import copy
from dataclasses import dataclass
from typing import List, Literal, Tuple, Union, Optional

import i6_core.rasr as rasr

from sisyphus import tk

import i6_core.rasr as rasr

TdpType = Union[float, Literal["infinity"]]
TyingType = Literal["global", "global-and-nonword"]


@dataclass
Expand All @@ -28,7 +28,7 @@ def acoustic_model_config(
tdp_scale: float = 1.0,
tdp_transition: Union[TdpValues, Tuple[TdpType, ...]] = (3.0, 0.0, 3.0, 2.0),
tdp_silence: Union[TdpValues, Tuple[TdpType, ...]] = (0.0, 3.0, "infinity", 6.0),
tying_type: Literal["global", "global-and-nonword"] = "global",
tying_type: TyingType = "global",
nonword_phones: Union[str, List[str]] = "",
tdp_nonword: Union[TdpValues, Tuple[TdpType, ...]] = (0.0, 3.0, "infinity", 6.0),
state_tying_file: Optional[tk.Path] = None,
Expand Down Expand Up @@ -111,9 +111,10 @@ def get_align_config_and_crp_for_corrected_applicator(
crp: rasr.CommonRasrParameters, exit_penalty: float = 0.0
) -> [rasr.CommonRasrParameters, rasr.RasrConfig]:
"""
Set the correct type of applicator, default is "legacy". Moreover, set exit penalities to zero
Set the correct type of applicator, default is "legacy". Moreover, set exit penalties to zero
For a given word sequence the exit penalty is constant with respect to the max/sum
:param config:
:param crp: common rasr parameters
:param exit_penalty: exit penalty for speech phonemes, silence, and non word phonemes
:return:
"""

Expand Down
15 changes: 15 additions & 0 deletions mm/mixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import i6_core.rasr as rasr
import i6_core.util as util

from i6_core.am.config import get_align_config_and_crp_for_corrected_applicator


class MergeMixturesJob(rasr.RasrCommand, Job):
def __init__(
Expand Down Expand Up @@ -147,6 +149,8 @@ def hash(cls, kwargs):


class LinearAlignmentJob(MergeMixturesJob):
__sis_hash_exclude__ = {"use_corrected_applicator": False}

def __init__(
self,
crp,
Expand All @@ -158,6 +162,8 @@ def __init__(
minimum_speech_proportion=0.7,
save_alignment=False,
keep_accumulators=False,
use_corrected_applicator: bool = False,
exit_penalty_for_corrected_applicator: float = 0.0,
extra_merge_args=None,
extra_config=None,
extra_post_config=None,
Expand Down Expand Up @@ -247,10 +253,19 @@ def create_config(
penalty,
minimum_speech_proportion,
save_alignment,
use_corrected_applicator,
exit_penalty_for_corrected_applicator,
extra_config,
extra_post_config,
**kwargs,
):
if use_corrected_applicator:
crp, _extra_config = get_align_config_and_crp_for_corrected_applicator(
crp=crp,
exit_penalty=exit_penalty_for_corrected_applicator,
)
extra_config._update(_extra_config)

segmentation_flow = cls.create_flow(feature_energy_flow, save_alignment)
mapping = {
"corpus": "acoustic-model-trainer.corpus",
Expand Down

0 comments on commit 0ae7ebe

Please sign in to comment.