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

feat: Hyperopt schema v0, part 1: Move output feature metrics from feature classes to feature configs. #2759

Conversation

ksbrar
Copy link
Collaborator

@ksbrar ksbrar commented Nov 14, 2022

This is part 1 of the broken up hyperopt schema PR (#2346).

It moves the definition of a feature's metric function definitions from that feature's class to its config. This seems to make more sense overall and it is necessary to populate the JSON schema for the output feature metric section of the hyperopt config.

@ksbrar ksbrar changed the title feat: Add basic hyperopt schema (Part 1): Move output feature metrics from feature classes to feature configs. feat: Hyperopt schema v1, part 1: Move output feature metrics from feature classes to feature configs. Nov 14, 2022
@ksbrar ksbrar changed the title feat: Hyperopt schema v1, part 1: Move output feature metrics from feature classes to feature configs. feat: Hyperopt schema v0, part 1: Move output feature metrics from feature classes to feature configs. Nov 14, 2022
@ksbrar ksbrar mentioned this pull request Nov 14, 2022
14 tasks
@github-actions
Copy link

github-actions bot commented Nov 14, 2022

Unit Test Results

         6 files  ±0           6 suites  ±0   3h 48m 38s ⏱️ + 3m 51s
  3 516 tests ±0    3 435 ✔️ ±0    81 💤 ±0  0 ±0 
10 548 runs  ±0  10 287 ✔️ ±0  261 💤 ±0  0 ±0 

Results for commit acd13f2. ± Comparison against base commit a981caf.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@connor-mccorm connor-mccorm left a comment

Choose a reason for hiding this comment

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

LTGM except it seems like you still need to add the get_output_metric_functions() call to the binary feature. Great job mate!

ludwig/features/binary_feature.py Show resolved Hide resolved
Copy link
Contributor

@dantreiman dantreiman left a comment

Choose a reason for hiding this comment

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

Had a few code style edits, let me know what you think of those. Otherwise looks good so approved.

@@ -240,7 +237,7 @@ def create_preproc_module(metadata: Dict[str, Any]) -> torch.nn.Module:


class CategoryOutputFeature(CategoryFeatureMixin, OutputFeature):
metric_functions = {LOSS: None, ACCURACY: None, HITS_AT_K: None}
metric_functions = CategoryOutputFeatureConfig.get_output_metric_functions()
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about refactoring this into a static accessor instead of a static variable? It could be defined once at OutputFeature level, like:

  @staticmethod
    def metric_functions():
        return self.get_schema_cls().get_output_metric_functions()

Not necessary, just an idea.

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 like this much better!

Copy link
Contributor

Choose a reason for hiding this comment

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

This would be cleaner, but there might be some complexity with how OutputFeature base class shadows the class attribute, with def _setup_metrics(self).

IMO, probably worth refactoring/cleaning this up separately.


@staticmethod
def get_output_metric_functions():
return {LOSS: None, ACCURACY: None, ROC_AUC: None}
Copy link
Contributor

Choose a reason for hiding this comment

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

I just realized that these are sets, since every key is mapped to None. How about making these set literals?

Code style suggestion, not necessary...

Suggested change
return {LOSS: None, ACCURACY: None, ROC_AUC: None}
return {LOSS, ACCURACY, ROC_AUC}

Copy link
Contributor

@justinxzhao justinxzhao left a comment

Choose a reason for hiding this comment

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

Hi Kabir, happy to go with this PR as is. There's some additional cleanup that @dantreiman suggested, but this PR as is is still cleaner than what we have today, and we could defer the additional refactoring to later, as to continue with checking in the rest of the hyperopt schema changes, WDYT?

@@ -240,7 +237,7 @@ def create_preproc_module(metadata: Dict[str, Any]) -> torch.nn.Module:


class CategoryOutputFeature(CategoryFeatureMixin, OutputFeature):
metric_functions = {LOSS: None, ACCURACY: None, HITS_AT_K: None}
metric_functions = CategoryOutputFeatureConfig.get_output_metric_functions()
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be cleaner, but there might be some complexity with how OutputFeature base class shadows the class attribute, with def _setup_metrics(self).

IMO, probably worth refactoring/cleaning this up separately.

@ksbrar
Copy link
Collaborator Author

ksbrar commented Nov 18, 2022

@justinxzhao Sounds good, I will proceed with the other changes first and put the set change in a separate refactor!

@ksbrar ksbrar merged commit 007a6a4 into ludwig-ai:master Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants