Skip to content

Commit

Permalink
fix: use enum field serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
roedoejet committed May 22, 2024
1 parent ebd9266 commit a9c86a8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion dfaligner/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from everyvoice.config.type_definitions import TargetTrainingTextRepresentationLevel
from everyvoice.config.utils import load_partials
from everyvoice.utils import load_config_from_json_or_yaml_path
from pydantic import Field, FilePath, ValidationInfo, model_validator
from pydantic import Field, FilePath, ValidationInfo, field_serializer, model_validator


class DFAlignerExtractionMethod(Enum):
Expand All @@ -34,6 +34,12 @@ class DFAlignerModelConfig(ConfigModel):
512, description="The number of dimensions in the convolutional layers."
)

@field_serializer("target_text_representation_level")
def convert_training_enum(
self, target_text_representation_level: TargetTrainingTextRepresentationLevel
):
return target_text_representation_level.value


class DFAlignerTrainingConfig(BaseTrainingConfig):
optimizer: AdamOptimizer | AdamWOptimizer = Field(
Expand All @@ -47,6 +53,12 @@ class DFAlignerTrainingConfig(BaseTrainingConfig):
description="The alignment extraction algorithm to use. 'beam' will be quicker but possibly less accurate than 'dijkstra'",
)

@field_serializer("extraction_method")
def convert_extraction_method_enum(
self, extraction_method: DFAlignerExtractionMethod
):
return extraction_method.value


class DFAlignerConfig(BaseModelWithContact):
# TODO FastSpeech2Config and DFAlignerConfig are almost identical.
Expand Down

0 comments on commit a9c86a8

Please sign in to comment.