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

Add Base Task Class #671

Merged
merged 7 commits into from
Jan 18, 2023
Merged

Add Base Task Class #671

merged 7 commits into from
Jan 18, 2023

Conversation

abheesht17
Copy link
Collaborator

@abheesht17 abheesht17 commented Jan 17, 2023

Resolves #635

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.

Looks amazing @abheesht17 I think we mainly need to beef up the class-level docstrings to include examples with and without preprocessing. Put these up top since it is primary usage!

{
"num_classes": self.num_classes,
"dropout": self.dropout,
"name": self.name,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could "name" and "trainable" be added to the Task get_config? I guess it would be awkward to look for them in kwargs to pass to super().get_config()?

Copy link
Member

Choose a reason for hiding this comment

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

We should make this change. I was going to do the same for backbones.

Having name and trainable handle in a base class is actually the norm, so it will improve readability here.

keras_nlp/models/bert/bert_classifier.py Show resolved Hide resolved
Copy link
Member

@mattdangerw mattdangerw left a comment

Choose a reason for hiding this comment

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

Looks great! A few comments

{
"num_classes": self.num_classes,
"dropout": self.dropout,
"name": self.name,
Copy link
Member

Choose a reason for hiding this comment

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

We should make this change. I was going to do the same for backbones.

Having name and trainable handle in a base class is actually the norm, so it will improve readability here.


model.load_weights(weights)
return model
BertClassifier.from_preset.__func__.__doc__ = Task.from_preset.__doc__
Copy link
Member

Choose a reason for hiding this comment

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

We can switch to the approach in #654 now


@property
def backbone(self):
"""A `keras_nlp.models.backbone.Backbone` instance providing the encoder submodel."""
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this shorter, not include the "encoder" language (which will not apply to t5, bart, gpt), and not refer to the keras_nlp.models.backbone.Backbone symbol, which we will not expose.

A keras.Model instance providing the backbone submodel.


@property
def preprocessor(self):
"""A `keras_nlp.models.preprocessor.Preprocessor` instance for preprocessing inputs."""
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

A keras.layers.Layer instance used to preprocess raw inputs.

In general trying to fit in the 80 char limit is a good constraint for the docstring one liner.

@mattdangerw
Copy link
Member

/gcbrun

Copy link
Member

@mattdangerw mattdangerw left a comment

Choose a reason for hiding this comment

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

This looks really nice! Thank you!

I think as a follow up, I would love to take stock of the full set of code examples we have for classifiers and shorten/rearrange them. Mainly, I want to see from_preset() flows at the top, they are how the vast majority of people will use the class. But let's do that separately!

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.

Looking great!

@jbischof jbischof merged commit 1cb93f2 into keras-team:master Jan 18, 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.

Create Task base class
3 participants