Skip to content
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
faf9e37
[skip ci] [WIP] Alternative Card implementation
BenjaminBossan Oct 25, 2022
cc229a2
[WIP] Further align new model card design
BenjaminBossan Oct 31, 2022
166e33d
Make tests pass
BenjaminBossan Nov 1, 2022
a90e3a5
Add tests for new functionalities and docstrings
BenjaminBossan Nov 1, 2022
fcbd0df
Adjust tests to work with older sklearn versions
BenjaminBossan Nov 2, 2022
4f10f80
Adjust examples to new card, more docs
BenjaminBossan Nov 2, 2022
0f5df2e
Continue fixing tests
BenjaminBossan Nov 2, 2022
6212d67
Try fixing Windows error by specifying encoding
BenjaminBossan Nov 2, 2022
80d218d
Adjust doctest: confusion matrix not stored in cwd
BenjaminBossan Nov 2, 2022
c6c8042
Increase test coverage
BenjaminBossan Nov 2, 2022
e7a2ae3
Try fixing test failure on Windows
BenjaminBossan Nov 3, 2022
2a6aab0
Replace old by new Card implementation
BenjaminBossan Nov 10, 2022
ce16019
Merge branch 'main' into alternative-model-card-implementation
BenjaminBossan Nov 10, 2022
00b7665
Address reviewer comments
BenjaminBossan Nov 21, 2022
8558f26
Add TODO notes for when Python 3.7 is dropped
BenjaminBossan Nov 25, 2022
fdb7674
Add Hub model card template, add template arg
BenjaminBossan Nov 25, 2022
772a659
Make _add_single return the Section
BenjaminBossan Nov 30, 2022
7cfddf9
Allow tables without rows to be added
BenjaminBossan Nov 30, 2022
50b0d39
Parser that allows to load dumped model cards
BenjaminBossan Nov 30, 2022
26892d6
Error when calling add_metric w/ invalid template
BenjaminBossan Dec 1, 2022
9646103
Merge branch 'alternative-model-card-implementation' into parse-model…
BenjaminBossan Dec 1, 2022
80a4ae3
Support model cards with yaml header
BenjaminBossan Dec 2, 2022
9744998
Add a bunch of more markup support
BenjaminBossan Dec 2, 2022
d864941
Add more test cases for model card parser
BenjaminBossan Dec 5, 2022
5e5c1a3
Rename Markdown class's methods, make private
BenjaminBossan Dec 6, 2022
1ff15be
Merge branch 'main' into parse-model-cards-pandoc
BenjaminBossan Dec 16, 2022
8979751
Add version check for pandoc
BenjaminBossan Dec 16, 2022
e8d6f61
New table parsing code
BenjaminBossan Dec 16, 2022
d0e07bc
Fix "bug" with metainfo order
BenjaminBossan Dec 16, 2022
5a9f826
Clean up noise created from merge conflict
BenjaminBossan Dec 16, 2022
5bc5909
Fix TypedDict import for Py<3.9, doctest
BenjaminBossan Dec 16, 2022
3c3ff89
Add future annotations import to _markup.py
BenjaminBossan Dec 16, 2022
c2ccfcc
Add more documentation, refactor parser class
BenjaminBossan Dec 19, 2022
a2f90a4
Skip parts of parse_modelcard docstring test
BenjaminBossan Jan 2, 2023
de454cc
Merge branch 'main' into parse-model-cards-pandoc
BenjaminBossan Jan 2, 2023
7ececc1
Increase test coverage, add a few features
BenjaminBossan Jan 3, 2023
08505f9
Install pandoc on linux CI to test parser
BenjaminBossan Jan 5, 2023
d0aa9df
Add documentation about parsing model cards
BenjaminBossan Jan 17, 2023
5da3397
Fix incorrect link in docs
BenjaminBossan Jan 17, 2023
2cb998e
Clean up test_parser.py
BenjaminBossan Jan 17, 2023
1922bc1
Move changes entry to v0.5
BenjaminBossan Jan 18, 2023
e684c78
Merge branch 'main' into parse-model-cards-pandoc
BenjaminBossan Jan 20, 2023
709e079
Reviewer comments: wording, period in err msg
BenjaminBossan Jan 20, 2023
08f44c4
Use packaging Version for version comparison
BenjaminBossan Jan 20, 2023
7c416c4
Install pandoc with apt in CI
BenjaminBossan Jan 20, 2023
b855e50
Investigate pandoc version issue
BenjaminBossan Jan 20, 2023
2da5ea6
Lower min required pandoc version to 2.9.0
BenjaminBossan Jan 20, 2023
6d1f288
Revert pandoc install to use gh + deb
BenjaminBossan Jan 23, 2023
d6d8e0a
Merge branch 'main' into parse-model-cards-pandoc
BenjaminBossan Jan 23, 2023
fb46a76
Add Figure type to parsing
BenjaminBossan Jan 23, 2023
04c5756
Merge branch 'main' into parse-model-cards-pandoc
BenjaminBossan Jan 23, 2023
30d3e5c
Add pragmas for lines that are covered
BenjaminBossan Jan 24, 2023
de1837e
Add more unit tests, get to 100% coverage
BenjaminBossan Jan 24, 2023
6472ebf
Fix incorrect docstring
BenjaminBossan Jan 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ jobs:
then pip install --pre --extra-index https://pypi.anaconda.org/scipy-wheels-nightly/simple scikit-learn;
else pip install "scikit-learn~=${{ matrix.sklearn_version }}";
fi
if [ ${{ matrix.os }} == "ubuntu-latest" ];
then wget -q https://github.com/jgm/pandoc/releases/download/2.19.2/pandoc-2.19.2-1-amd64.deb && sudo dpkg -i pandoc-2.19.2-1-amd64.deb;
fi
python --version
pip --version
pip list
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ repos:
exclude: .github/conda/meta.yaml
- id: end-of-file-fixer
- id: trailing-whitespace
exclude: skops/card/tests/examples
- id: check-case-conflict
- id: check-merge-conflict
- repo: https://github.com/psf/black
Expand Down
13 changes: 8 additions & 5 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ skops Changelog
:depth: 1
:local:

v0.5
----
- :class:`.card.Card` now allows to add content to existing sections, using a
``/`` to separate the subsections. E.g. use ``card.add(**{"Existing
section/New section": "content"})`` to add "content" a new subsection called
"New section" to an existing section called "Existing section". :pr:`203` by
`Benjamin Bossan`_.

v0.4
----
- :func:`.io.dump` and :func:`.io.load` now work with file like objects,
Expand All @@ -21,11 +29,6 @@ v0.4
:pr:`242` by `Merve Noyan`_.
- Persistence now supports bytes and bytearrays, added tests to verify that
LightGBM, XGBoost, and CatBoost work now. :pr:`244` by `Benjamin Bossan`_.
- :class:`.card.Card` now allows to add content to existing sections, using a
``/`` to separate the subsections. E.g. use ``card.add(**{"Existing
section/New section": "content"})`` to add "content" a new subsection called
"New section" to an existing section called "Existing section". :pr:`203` by
`Benjamin Bossan`_.

v0.3
----
Expand Down
50 changes: 48 additions & 2 deletions docs/model_card.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ beginning of it, following with the content of the model card in markdown
format. The metadata section is used to make models searchable on the Hub, and
get the inference API and the widgets on the website working.

Metadata
--------

The metadata part of the file needs to follow the specifications `here
<https://huggingface.co/docs/hub/models-cards#model-card-metadata>`__. It
includes simple attributes of your models such as the task you're solving,
Expand Down Expand Up @@ -40,6 +43,9 @@ Here's an example of the metadata section of the ``README.md`` file:
``skops`` creates this section of the file for you, and you almost never need
to touch it yourself.

Model Card Content
------------------

The markdown part does not necessarily need to follow any specification in
terms of information passed, which gives the user a lot of flexibility. The
markdown part of the ``README.md`` file comes with a couple of defaults provided
Expand Down Expand Up @@ -90,8 +96,8 @@ as well as adding some subsections with plots below that, you can call the
})

Furthermore, you can select existing sections (as well as their subsections)
using :meth:`Card.select`, and you can delete sections using
:meth:`Card.delete`:
using :meth:`.Card.select`, and you can delete sections using
:meth:`.Card.delete`:

.. code-block:: python

Expand All @@ -103,3 +109,43 @@ using :meth:`Card.select`, and you can delete sections using

To see how you can use the API in ``skops`` to create a model card, please
refer to :ref:`sphx_glr_auto_examples_plot_model_card.py`.

Saving and Loading Model Cards
------------------------------

Once you have finished creating and modifying the model card, you can save it
using the :meth:`.Card.save` method:

.. code-block:: python

card.save("README.md")

This renders the content of the model card to markdown format and stores it in
the indicated file. It is now ready to be uploaded to Hugging Face Hub.

If you have a finished model card but want to load to make some modifications,
you can use the function :func:`skops.card.parse_modelcard`. This function
parses the model card back into a :class:`.Card` instance that you can work on
further:

.. code-block:: python

from skops import card
model_card = card.parse_modelcard("README.md")
model_card.add(**{"A new section": "Some new content"})
model_card.save("README.md")

When the card is parsed, some minor details of the model card can change, e.g.
if you used different column alignment than the default, this could change, as
well as removing excess empty lines or trailing whitespace. However, the content
itself should be exactly the same. All known deviations are documented in the
`parse_modelcard docs
<https://skops.readthedocs.io/en/stable/modules/classes.html#skops.card.parse_modelcard>`_

For the parsing part, we rely on `pandoc <https://pandoc.org/>`_. If you haven't
installed it, please follow `these instructions
<https://pandoc.org/installing.html>`_. The advantage of using pandoc is that
it's a very mature library and that it supports many different document formats.
Therefore, it should be possible to parse model cards even if they use a format
that's not markdown, for instance reStructuredText, org, or asciidoc. For
saving, we only support markdown, though.
3 changes: 2 additions & 1 deletion skops/card/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ._model_card import Card, metadata_from_config
from ._parser import parse_modelcard

__all__ = ["Card", "metadata_from_config"]
__all__ = ["Card", "metadata_from_config", "parse_modelcard"]
Loading