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

ENH populate model card metadata with info from config.json #71

Merged
merged 5 commits into from
Aug 5, 2022

Conversation

adrinjalali
Copy link
Member

This PR adds a convenience function to populate the metadata section of model cards from the info available in config.json.

I'll be adding tests, but I'm wondering what you think of the API @merveenoyan @BenjaminBossan ?

@adrinjalali adrinjalali changed the title ENH populate model card metadata with info from config.json [WIP] ENH populate model card metadata with info from config.json Aug 3, 2022
@adrinjalali adrinjalali added this to the 0.1 milestone Aug 3, 2022
@merveenoyan merveenoyan mentioned this pull request Aug 3, 2022
@BenjaminBossan
Copy link
Collaborator

I think we can proceed in this direction. It makes sense to use what's already there in the config.json.

@adrinjalali
Copy link
Member Author

This finally makes the model work out of the box, example: https://huggingface.co/skops/hf_hub_example-bdc26c1f-7e82-42eb-9657-0318315f2df0

Note: the output is actually not reliable yet, for the model to get the right input, huggingface/api-inference-community#79 needs to be merged first.

@osanseviero you might like this one ;)

Running plot_hf_hub.py (w/o the delete repo at the end) gives a nice example repo.

@adrinjalali
Copy link
Member Author

adrinjalali commented Aug 4, 2022

(There are some issues with the widget in linux, both Firefox and Chrome, and I've already told Mishig about them).

Edit: fixed upstream: huggingface/hub-docs#276

@adrinjalali adrinjalali changed the title [WIP] ENH populate model card metadata with info from config.json ENH populate model card metadata with info from config.json Aug 4, 2022
@osanseviero
Copy link
Contributor

Indeed I like this one, very cool! 🔥

Copy link
Collaborator

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

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

Overall, this looks good to me, it's a nice convenience for the user. I have a few nits, please take a look at the comments.

API-wise, there could be a little bit of dissonance now. To add non-metadata to the card, users use a method: card.add(foo=bar). To add metadata, they set attributes: card.metadata.foo = bar. I believe it's good that the distinction between non-metadata and metadata is not hidden from the user (as it was before), but it's still a bit strange to set them so differently.

As a proposal (could be added later), what do you think about providing a new method, add_metadata, which for users works exactly the same as add (i.e. works with **kwargs and returns self) and under the hood sets attributes on the metadata?

# We will now create a model card and save it. For more information about how
# to create a good model card, refer to the :ref:`model card example
# <sphx_glr_auto_examples_plot_model_card.py>`
model_card = card.Card(model, metadata=card.metadata_from_config(Path(local_repo)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

As a user, I might be confused about where the config comes from. How about adding a comment above the init call that mentions that a config.json is created for the user, similar to the comment in plot_model_card.py?

Copy link
Member Author

Choose a reason for hiding this comment

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

clarified!

skops/card/_model_card.py Outdated Show resolved Hide resolved
skops/card/_model_card.py Outdated Show resolved Hide resolved
Copy link
Member Author

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

I'm not sure about the idea of add_metadata, let's see how this goes I'd say.

# We will now create a model card and save it. For more information about how
# to create a good model card, refer to the :ref:`model card example
# <sphx_glr_auto_examples_plot_model_card.py>`
model_card = card.Card(model, metadata=card.metadata_from_config(Path(local_repo)))
Copy link
Member Author

Choose a reason for hiding this comment

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

clarified!

Copy link
Collaborator

@merveenoyan merveenoyan left a comment

Choose a reason for hiding this comment

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

LGTM

examples/plot_model_card.py Show resolved Hide resolved
skops/card/_model_card.py Show resolved Hide resolved
@@ -76,14 +140,18 @@ class Card:
>>> model_card.add_plot(confusion_matrix="confusion_matrix.png") # doctest: +ELLIPSIS
Card(
model=LogisticRegression(random_state=0),
license='mit',
Copy link
Member Author

Choose a reason for hiding this comment

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

Opened a separate issue to fix repr to include metadata here: #75

@BenjaminBossan BenjaminBossan merged commit 4b9dcfe into skops-dev:main Aug 5, 2022
@adrinjalali adrinjalali deleted the config-modelcard branch August 5, 2022 15:04
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.

4 participants