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

Feature: RecursiveDict.compress() to shorten paths to steps and their hyperparams #486

Closed
guillaume-chevalier opened this issue May 16, 2021 · 6 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested

Comments

@guillaume-chevalier
Copy link
Member

Is your feature request related to a problem? Please describe.
Hyperparam names are too long in nested steps

Describe the solution you'd like
A way to compress the names so as to make them shorter. More specifically, I think that an automated algorithm for all existing ML pipelines could be built. That would be to do something like:

all_hps = pipeline.get_hyperparams()
all_hps_shortened = all_hps.compress()
pprint(all_hps_shortened)

Then we'd see something like this in the pprint:

{
    "*__MetaStep__*__SKLearnWrapper_LinearRegression__C": 1000,
    "*__SomeStep__hyperparam3": value,
    "*__SKLearnWrapper_BoostedTrees__count": 10
}

That is, the unique paths to some steps were compressed using the star (*) operator. The Star operator means "one or more steps between". But the way the paths are compressed would be lossless, in the sense that the original names could ALWAYS be retrieved given the original pipeline's tree structure.

Describe alternatives you've considered
Using custom ways to flush words and compress them. That seems good, but it doesn't seem to generalize to all pipelines that could exist.

Additional context
Hyperparameter names were said to be too long as well in #478

Additional idea
For hyperparameters, given the fact that in the future every model may need to name its expected hyperparams, then it may be possible to use their name only and directly if there is no other step with the same hyperparams. If another step uses the same hyperparam names, then compression with the "*" could go up in the tree to find the first non-common parent name or something.

More ideas are needed to be sure we do this the right way.

@guillaume-chevalier guillaume-chevalier added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers question Further information is requested labels May 16, 2021
@Rohith295
Copy link

I would like to work on this issue.

@guillaume-chevalier
Copy link
Member Author

guillaume-chevalier commented Jun 26, 2021

Idea 1:

List of dicts containing step name and/or hyperparameter(s) and the parent list. Possible to remove parents for printing. It keeps the good order:

  • def compresed(self: HyperparameterSamples) -> CompressedHyperparameterSamples
  • class CompressedHyperparameterSamples(List[Dict[str, Any]])
  • def CompressedHyperparameterSamples.remove_parents()

Idea 2:

  • def CompressedHyperparameterSamples.to_wildcards() :
Before: 
pipeline__a__predictor1__IncrementalFitCausalityModel__hp1
pipeline__a__predictor2__IncrementalFitCausalityModel__hp1
pipeline__b__predictor1__IncrementalFitCausalityModel__hp1

After: 
*a__predictor1*hp1: 435
*a__predictor2*hp1: 435
*b*hp1: 234

Or this Alternative version of After for instance: 
*a*predictor1*hp1: 435
*predictor2*hp1: 435
*b*hp1: 234

@Rohith295
Copy link

One type of compressed format

all_hps_shortened = all_hps.compress()
print(all_hps_shortened)
[
    {

        "step_name": "step1",
        "hp": {

        },
        "parents": [""] or "_"
    },
    {

        "step_name": "step1",
        "hp": {

        },
        "parents": [""] or "_"
    },

]

**if trim parents is True**
all_hps_shortened = all_hps.compress(trim_parents = True)
print(all_hps_shortened)
[
    {

        "step_name": "step1",
        "hp": {

        },
    },
    {

        "step_name": "step1",
        "hp": {

        },
    },

]

@guillaume-chevalier
Copy link
Member Author

@Rohith295 perfect ! I like compress(trim_parents = True) that would call remove_parents instantly as in Idea 1 😃

@guillaume-chevalier
Copy link
Member Author

Would be interesting to have this as well: CompressedHyperparameterSamples.restore() -> HyperparameterSamples

@guillaume-chevalier guillaume-chevalier added this to the 0.6.1 milestone Jun 29, 2021
@guillaume-chevalier guillaume-chevalier removed this from the 0.6.1 milestone Oct 17, 2021
@guillaume-chevalier
Copy link
Member Author

Completed using the "use_wildcards" argument such as in RecursiveDict.to_flat_dict(use_wildcards=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants