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

Make tokenizer, backbone, preprocessor properties settable on base class #700

Merged
merged 1 commit into from
Feb 1, 2023

Conversation

mattdangerw
Copy link
Member

This improves the readability of our subclasses, instead of writing to a hidden property self.backbone and reading from self._backbone, we can use a consistent style everywhere.

@mattdangerw
Copy link
Member Author

mattdangerw commented Jan 28, 2023

Curious what everyone thinks of this. IMO the base classes have overall been great, but one inscrutable and overly magical eyesore is we are writing self._backbone in our task constructors, then self.backbone in call. It's totally confusing and not at all clear this is part of the contract with our base class.

The settable property pattern is something we do in core Keras, so it seems consistent to pick up here. See this line for example.

You could make an argument that we don't want these settable at all (we should protect users from themselves), but I'm not sure that's really that consistent with the rest of our model offering. After all preprocessor.sequence_length, and backbone.hidden_dim are totally settable, we just aren't recommending it.

So anyway tl;dr, I think we should focus on our task model readability here, and I think this is an improvement!

Copy link
Contributor

@jbischof jbischof left a comment

Choose a reason for hiding this comment

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

Seems reasonable, but I think initially we weren't sure we wanted them to be settable to minimize user confusion. For example on Task models you could set model.preprocessor but not understand that unless you also set model.include_preprocessing = True it won't work. It seems like our designs need a higher standard to fulfill the user expectations no?

@mattdangerw
Copy link
Member Author

mattdangerw commented Jan 28, 2023

For example on Task models you could set model.preprocessor but not understand that unless you also set model.include_preprocessing = True it won't work.

This is actually a one liner fix, and seems reasonable to add. Just put it in.

Though overall, I'm not saying we should ever advertise that this property is settable (just like we don't advertise that you can do preprocessor.sequence_lenth = 64). Mainly want the focus on consistent and readable task modeling code.

If not this, maybe we should override our property definitions similar to what we do for the recently added backbone.embedding_layer, so we don't leak private data across class boundaries wherever possible.

This improves the readability of our subclasses, instead of writing
to a hidden property `self.backbone` and reading from `self._backbone`,
we can use a consistent style everywhere.
Copy link
Contributor

@jbischof jbischof left a comment

Choose a reason for hiding this comment

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

Great, as long as we do the work to ensure that these properties can be manipulated intuitively it seems like a better experience. I thought of one bug but there might be others.

@mattdangerw mattdangerw merged commit e8be57c into keras-team:master Feb 1, 2023
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.

2 participants