Skip to content

Conversation

@jegork
Copy link
Contributor

@jegork jegork commented Dec 7, 2022

Fixes #124

I have added a SetFitModelConfig and setter/getter functions for SetFitModel to be able to change the configuration of the underlying transformer body model.

This gives ability to provide e.g. id2label via

from setfit import SetFitModel
model = SetFitModel.from_pretrained(model_name)
model.config.model_body.idx2label = {0: "neg", 1: "pos"}

One disadvantage of this approach is that the provided code has to access protected members of model_body, but I don't think there is any other way to access the PretrainedConfig for the model_body.

Additionally, in the config setter, I have currently left the possibility to change model_body config only (because there is currently no single config for model head). In getter I return SetFitHead.get_config_dict as the model_head config.

Maybe we can come up with a way to have a similar config for the torch model head and think of something with the sklearn model head?

Welcome to any suggestions!

@tomaarsen tomaarsen added the enhancement New feature or request label Dec 20, 2022
Copy link
Member

@lewtun lewtun left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this contribution @jegork ! It's something I've also noticed would be quite useful when pushing models to the Hub and being able to store the label mappings for inference.

I think for now I'd like us to come up with a better API for handling the distinction between model bodies and heads before accepting this PR (because it could quickly become obsolete)

The issue in question is this one: #238

I'll come back to this PR once we have a clearer vision for how the API will look moving forward

@tomaarsen
Copy link
Member

Hello!

Apologies for the delay. #439 is a large refactor, and it includes some configuration options. In particular, you can now provide the model with labels corresponding to integer labels from the training data. This PR also introduces label2id and id2label dictionaries. These can be defined on load-time, and will be saved in the model configuration as well, e.g. here.

It will supersede this PR, so I will close it. However, I do want to thank you for the inspiration and your work on this.

  • Tom Aarsen

@tomaarsen tomaarsen closed this Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id2label and label2id setup for inference

3 participants