-
Notifications
You must be signed in to change notification settings - Fork 46
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 fittable #140
base: main
Are you sure you want to change the base?
Add fittable #140
Conversation
Codecov ReportAttention: Patch coverage is
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Some minor comments and suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks super useful. left some comments. Also, perhaps we can add some reference to multi-label usage somewhere?
"""Save the model to a folder.""" | ||
save_pipeline(self, path) | ||
|
||
def push_to_hub(self, repo_id: str, token: str | None = None, private: bool = False) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a modelcard and perhaps tags or a library reference, this helps a lot with visibility, usability and findability.
https://huggingface.co/docs/hub/model-cards#specifying-a-library
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually already happens because we push the underlying static model to the hub, which has a model card. This model card template is specified in the root of the code.
self.head = head | ||
|
||
@classmethod | ||
def from_pretrained( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we load it from the Hub? perhaps we should align the arguments a bit with the transformers
naming given you've also adopted from_pretrained
?
For example using pretrained_model_name_or_path
. https://huggingface.co/docs/transformers/v4.48.0/en/model_doc/auto#transformers.AutoTokenizer.from_pretrained
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from_pretrained loads from the hub. The arguments mimic the ones from StaticModel
and, although they don't match transformers exactly, we're wary of introducing breaking changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of comments and suggestions
|
||
# Usage | ||
|
||
Let's assume you're using our `potion-edu classifier`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's assume you're using our `potion-edu classifier`. | |
Let's assume you're using our [potion-edu classifier](https://huggingface.co/minishlab/potion-8m-edu-classifier). |
Also small todo, don't forget to make this model public
```python | ||
from model2vec.inference import StaticModelPipeline | ||
|
||
s = StaticModelPipeline.from_pretrained("minishlab/potion-8m-edu-classifier") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s = StaticModelPipeline.from_pretrained("minishlab/potion-8m-edu-classifier") | |
classifier = StaticModelPipeline.from_pretrained("minishlab/potion-8m-edu-classifier") |
from model2vec.inference import StaticModelPipeline | ||
|
||
s = StaticModelPipeline.from_pretrained("minishlab/potion-8m-edu-classifier") | ||
label = s.predict("Attitudes towards cattle in the Alps: a study in letting go.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label = s.predict("Attitudes towards cattle in the Alps: a study in letting go.") | |
label = classifier.predict("Attitudes towards cattle in the Alps: a study in letting go.") |
|
||
@classmethod | ||
def from_pretrained( | ||
cls: type[StaticModelPipeline], path: PathLike, token: str | None = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also accept trust_remote_code, and pass it to _load_pipeline I think
|
||
def _predict_and_coerce_to_2d(self, X: list[str] | str) -> np.ndarray: | ||
"""Predict the labels of the input and coerce the output to a matrix.""" | ||
encoded = self.model.encode(X) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no control over encode since this is in a private function, I'm not sure if we want to give any control here? E.g batch size, multiprocessing, etc?
|
||
def configure_optimizers(self) -> OptimizerLRScheduler: | ||
"""Simple Adam optimizer.""" | ||
optimizer = torch.optim.Adam(self.model.parameters(), lr=1e-3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think learning rate is now ignored, this should be:
optimizer = torch.optim.Adam(self.model.parameters(), lr=1e-3) | |
optimizer = torch.optim.Adam(self.model.parameters(), lr=self.learning_rate) |
@@ -0,0 +1,248 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prints in the notebook are not saved/pushed I think. This is a bit weird, for example when you have:
"Pretty good! We outperform the tf-idf pipeline by a wide margin.", it doesn't actually show it in the notebook (see https://github.com/MinishLab/model2vec/blob/add-fittable/tutorials/train_classifier.ipynb).
No description provided.