Repository Cards
The huggingface_hub library provides a Python interface to create, share, and update Model/Dataset Cards. Visit the dedicated documentation page for a deeper view of what Model Cards on the Hub are, and how they work under the hood. You can also check out our Model Cards guide to get a feel for how you would use these utilities in your own projects.
Repo Card
The RepoCard
object is the parent class of ModelCard, DatasetCard and SpaceCard
.
__init__
< source >( content: strignore_metadata_errors: bool = False )
Initialize a RepoCard from string content. The content should be a Markdown file with a YAML block at the beginning and a Markdown body.
Example:
>>> from huggingface_hub.repocard import RepoCard
>>> text = '''
... ---
... language: en
... license: mit
... ---
...
... # My repo
... '''
>>> card = RepoCard(text)
>>> card.data.to_dict()
{'language': 'en', 'license': 'mit'}
>>> card.text
'\n# My repo\n'
ValueError
when the content of the repo card metadata is not a dictionary.
from_template
< source >( card_data: CardDatatemplate_path: Optional = Nonetemplate_str: Optional = None**template_kwargs ) β huggingface_hub.repocard.RepoCard
Parameters
- card_data (
huggingface_hub.CardData
) β A huggingface_hub.CardData instance containing the metadata you want to include in the YAML header of the repo card on the Hugging Face Hub. - template_path (
str
, optional) β A path to a markdown file with optional Jinja template variables that can be filled in withtemplate_kwargs
. Defaults to the default template.
A RepoCard instance with the specified card data and content from the template.
Initialize a RepoCard from a template. By default, it uses the default template.
Templates are Jinja2 templates that can be customized by passing keyword arguments.
load
< source >( repo_id_or_path: Unionrepo_type: Optional = Nonetoken: Optional = Noneignore_metadata_errors: bool = False ) β huggingface_hub.repocard.RepoCard
Parameters
- repo_id_or_path (
Union[str, Path]
) β The repo ID associated with a Hugging Face Hub repo or a local filepath. - repo_type (
str
, optional) β The type of Hugging Face repo to push to. Defaults to None, which will use use βmodelβ. Other options are βdatasetβ and βspaceβ. Not used when loading from a local filepath. If this is called from a child class, the default value will be the child classβsrepo_type
. - token (
str
, optional) β Authentication token, obtained withhuggingface_hub.HfApi.login
method. Will default to the stored token. - ignore_metadata_errors (
str
) β If True, errors while parsing the metadata section will be ignored. Some information might be lost during the process. Use it at your own risk.
The RepoCard (or subclass) initialized from the repoβs README.md file or filepath.
Initialize a RepoCard from a Hugging Face Hub repoβs README.md or a local filepath.
push_to_hub
< source >( repo_id: strtoken: Optional = Nonerepo_type: Optional = Nonecommit_message: Optional = Nonecommit_description: Optional = Nonerevision: Optional = Nonecreate_pr: Optional = Noneparent_commit: Optional = None ) β str
Parameters
- repo_id (
str
) β The repo ID of the Hugging Face Hub repo to push to. Example: βnateraw/foodβ. - token (
str
, optional) β Authentication token, obtained withhuggingface_hub.HfApi.login
method. Will default to the stored token. - repo_type (
str
, optional, defaults to βmodelβ) β The type of Hugging Face repo to push to. Options are βmodelβ, βdatasetβ, and βspaceβ. If this function is called by a child class, it will default to the child classβsrepo_type
. - commit_message (
str
, optional) β The summary / title / first line of the generated commit. - commit_description (
str
, optional) β The description of the generated commit. - revision (
str
, optional) β The git revision to commit from. Defaults to the head of the"main"
branch. - create_pr (
bool
, optional) β Whether or not to create a Pull Request with this commit. Defaults toFalse
. - parent_commit (
str
, optional) β The OID / SHA of the parent commit, as a hexadecimal string. Shorthands (7 first characters) are also supported. If specified andcreate_pr
isFalse
, the commit will fail ifrevision
does not point toparent_commit
. If specified andcreate_pr
isTrue
, the pull request will be created fromparent_commit
. Specifyingparent_commit
ensures the repo has not changed before committing the changes, and can be especially useful if the repo is updated / committed to concurrently.
Returns
str
URL of the commit which updated the card metadata.
Push a RepoCard to a Hugging Face Hub repo.
save
< source >( filepath: Union )
Save a RepoCard to a file.
validate
< source >( repo_type: Optional = None )
Validates card against Hugging Face Hubβs card validation logic. Using this function requires access to the internet, so it is only called internally by huggingface_hub.repocard.RepoCard.push_to_hub().
ValueError
if the card fails validation checks.HTTPError
if the request to the Hub API fails for any other reason.
Card Data
The CardData object is the parent class of ModelCardData and DatasetCardData.
Structure containing metadata from a RepoCard.
CardData is the parent class of ModelCardData and DatasetCardData.
Metadata can be exported as a dictionary or YAML. Export can be customized to alter the representation of the data
(example: flatten evaluation results). CardData
behaves as a dictionary (can get, pop, set values) but do not
inherit from dict
to allow this export step.
Get value for a given metadata key.
Pop value for a given metadata key.
to_dict
< source >( ) β dict
Returns
dict
CardData represented as a dictionary ready to be dumped to a YAML block for inclusion in a README.md file.
Converts CardData to a dict.
to_yaml
< source >( line_break = None ) β str
Dumps CardData to a YAML block for inclusion in a README.md file.
Model Cards
ModelCard
from_template
< source >( card_data: ModelCardDatatemplate_path: Optional = Nonetemplate_str: Optional = None**template_kwargs ) β huggingface_hub.ModelCard
Parameters
- card_data (
huggingface_hub.ModelCardData
) β A huggingface_hub.ModelCardData instance containing the metadata you want to include in the YAML header of the model card on the Hugging Face Hub. - template_path (
str
, optional) β A path to a markdown file with optional Jinja template variables that can be filled in withtemplate_kwargs
. Defaults to the default template.
Returns
A ModelCard instance with the specified card data and content from the template.
Initialize a ModelCard from a template. By default, it uses the default template, which can be found here: https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md
Templates are Jinja2 templates that can be customized by passing keyword arguments.
Example:
>>> from huggingface_hub import ModelCard, ModelCardData, EvalResult
>>> # Using the Default Template
>>> card_data = ModelCardData(
... language='en',
... license='mit',
... library_name='timm',
... tags=['image-classification', 'resnet'],
... datasets=['beans'],
... metrics=['accuracy'],
... )
>>> card = ModelCard.from_template(
... card_data,
... model_description='This model does x + y...'
... )
>>> # Including Evaluation Results
>>> card_data = ModelCardData(
... language='en',
... tags=['image-classification', 'resnet'],
... eval_results=[
... EvalResult(
... task_type='image-classification',
... dataset_type='beans',
... dataset_name='Beans',
... metric_type='accuracy',
... metric_value=0.9,
... ),
... ],
... model_name='my-cool-model',
... )
>>> card = ModelCard.from_template(card_data)
>>> # Using a Custom Template
>>> card_data = ModelCardData(
... language='en',
... tags=['image-classification', 'resnet']
... )
>>> card = ModelCard.from_template(
... card_data=card_data,
... template_path='./src/huggingface_hub/templates/modelcard_template.md',
... custom_template_var='custom value', # will be replaced in template if it exists
... )
ModelCardData
class huggingface_hub.ModelCardData
< source >( base_model: Union = Nonedatasets: Optional = Noneeval_results: Optional = Nonelanguage: Union = Nonelibrary_name: Optional = Nonelicense: Optional = Nonelicense_name: Optional = Nonelicense_link: Optional = Nonemetrics: Optional = Nonemodel_name: Optional = Nonepipeline_tag: Optional = Nonetags: Optional = Noneignore_metadata_errors: bool = False**kwargs )
Parameters
- base_model (
str
orList[str]
, optional) β The identifier of the base model from which the model derives. This is applicable for example if your model is a fine-tune or adapter of an existing model. The value must be the ID of a model on the Hub (or a list of IDs if your model derives from multiple models). Defaults to None. - datasets (
List[str]
, optional) β List of datasets that were used to train this model. Should be a dataset ID found on https://hf.co/datasets. Defaults to None. - eval_results (
Union[List[EvalResult], EvalResult]
, optional) β List ofhuggingface_hub.EvalResult
that define evaluation results of the model. If provided,model_name
is used to as a name on PapersWithCodeβs leaderboards. Defaults toNone
. - language (
Union[str, List[str]]
, optional) β Language of modelβs training data or metadata. It must be an ISO 639-1, 639-2 or 639-3 code (two/three letters), or a special value like βcodeβ, βmultilingualβ. Defaults toNone
. - library_name (
str
, optional) β Name of library used by this model. Example: keras or any library from https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/src/model-libraries.ts. Defaults to None. - license (
str
, optional) β License of this model. Example: apache-2.0 or any license from https://huggingface.co/docs/hub/repositories-licenses. Defaults to None. - license_name (
str
, optional) β Name of the license of this model. Defaults to None. To be used in conjunction withlicense_link
. Common licenses (Apache-2.0, MIT, CC-BY-SA-4.0) do not need a name. In that case, uselicense
instead. - license_link (
str
, optional) β Link to the license of this model. Defaults to None. To be used in conjunction withlicense_name
. Common licenses (Apache-2.0, MIT, CC-BY-SA-4.0) do not need a link. In that case, uselicense
instead. - metrics (
List[str]
, optional) β List of metrics used to evaluate this model. Should be a metric name that can be found at https://hf.co/metrics. Example: βaccuracyβ. Defaults to None. - model_name (
str
, optional) β A name for this model. It is used along witheval_results
to construct themodel-index
within the cardβs metadata. The name you supply here is what will be used on PapersWithCodeβs leaderboards. If None is provided then the repo name is used as a default. Defaults to None. - tags (
List[str]
, optional) β List of tags to add to your model that can be used when filtering on the Hugging Face Hub. Defaults to None. - ignore_metadata_errors (
str
) β If True, errors while parsing the metadata section will be ignored. Some information might be lost during the process. Use it at your own risk. - kwargs (
dict
, optional) β Additional metadata that will be added to the model card. Defaults to None.
Model Card Metadata that is used by Hugging Face Hub when included at the top of your README.md
Example:
>>> from huggingface_hub import ModelCardData
>>> card_data = ModelCardData(
... language="en",
... license="mit",
... library_name="timm",
... tags=['image-classification', 'resnet'],
... )
>>> card_data.to_dict()
{'language': 'en', 'license': 'mit', 'library_name': 'timm', 'tags': ['image-classification', 'resnet']}
Dataset Cards
Dataset cards are also known as Data Cards in the ML Community.
DatasetCard
from_template
< source >( card_data: DatasetCardDatatemplate_path: Optional = Nonetemplate_str: Optional = None**template_kwargs ) β huggingface_hub.DatasetCard
Parameters
- card_data (
huggingface_hub.DatasetCardData
) β A huggingface_hub.DatasetCardData instance containing the metadata you want to include in the YAML header of the dataset card on the Hugging Face Hub. - template_path (
str
, optional) β A path to a markdown file with optional Jinja template variables that can be filled in withtemplate_kwargs
. Defaults to the default template.
Returns
A DatasetCard instance with the specified card data and content from the template.
Initialize a DatasetCard from a template. By default, it uses the default template, which can be found here: https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/datasetcard_template.md
Templates are Jinja2 templates that can be customized by passing keyword arguments.
Example:
>>> from huggingface_hub import DatasetCard, DatasetCardData
>>> # Using the Default Template
>>> card_data = DatasetCardData(
... language='en',
... license='mit',
... annotations_creators='crowdsourced',
... task_categories=['text-classification'],
... task_ids=['sentiment-classification', 'text-scoring'],
... multilinguality='monolingual',
... pretty_name='My Text Classification Dataset',
... )
>>> card = DatasetCard.from_template(
... card_data,
... pretty_name=card_data.pretty_name,
... )
>>> # Using a Custom Template
>>> card_data = DatasetCardData(
... language='en',
... license='mit',
... )
>>> card = DatasetCard.from_template(
... card_data=card_data,
... template_path='./src/huggingface_hub/templates/datasetcard_template.md',
... custom_template_var='custom value', # will be replaced in template if it exists
... )
DatasetCardData
class huggingface_hub.DatasetCardData
< source >( language: Union = Nonelicense: Union = Noneannotations_creators: Union = Nonelanguage_creators: Union = Nonemultilinguality: Union = Nonesize_categories: Union = Nonesource_datasets: Optional = Nonetask_categories: Union = Nonetask_ids: Union = Nonepaperswithcode_id: Optional = Nonepretty_name: Optional = Nonetrain_eval_index: Optional = Noneconfig_names: Union = Noneignore_metadata_errors: bool = False**kwargs )
Parameters
- language (
List[str]
, optional) β Language of datasetβs data or metadata. It must be an ISO 639-1, 639-2 or 639-3 code (two/three letters), or a special value like βcodeβ, βmultilingualβ. - license (
Union[str, List[str]]
, optional) β License(s) of this dataset. Example: apache-2.0 or any license from https://huggingface.co/docs/hub/repositories-licenses. - annotations_creators (
Union[str, List[str]]
, optional) β How the annotations for the dataset were created. Options are: βfoundβ, βcrowdsourcedβ, βexpert-generatedβ, βmachine-generatedβ, βno-annotationβ, βotherβ. - language_creators (
Union[str, List[str]]
, optional) β How the text-based data in the dataset was created. Options are: βfoundβ, βcrowdsourcedβ, βexpert-generatedβ, βmachine-generatedβ, βotherβ - multilinguality (
Union[str, List[str]]
, optional) β Whether the dataset is multilingual. Options are: βmonolingualβ, βmultilingualβ, βtranslationβ, βotherβ. - size_categories (
Union[str, List[str]]
, optional) β The number of examples in the dataset. Options are: βn<1Kβ, β1K1Tβ, and βotherβ. - source_datasets (
List[str]]
, optional) β Indicates whether the dataset is an original dataset or extended from another existing dataset. Options are: βoriginalβ and βextendedβ. - task_categories (
Union[str, List[str]]
, optional) β What categories of task does the dataset support? - task_ids (
Union[str, List[str]]
, optional) β What specific tasks does the dataset support? - paperswithcode_id (
str
, optional) β ID of the dataset on PapersWithCode. - pretty_name (
str
, optional) β A more human-readable name for the dataset. (ex. βCats vs. Dogsβ) - train_eval_index (
Dict
, optional) β A dictionary that describes the necessary spec for doing evaluation on the Hub. If not provided, it will be gathered from the βtrain-eval-indexβ key of the kwargs. - config_names (
Union[str, List[str]]
, optional) β A list of the available dataset configs for the dataset.
Dataset Card Metadata that is used by Hugging Face Hub when included at the top of your README.md
Space Cards
SpaceCard
SpaceCardData
class huggingface_hub.SpaceCardData
< source >( title: Optional = Nonesdk: Optional = Nonesdk_version: Optional = Nonepython_version: Optional = Noneapp_file: Optional = Noneapp_port: Optional = Nonelicense: Optional = Noneduplicated_from: Optional = Nonemodels: Optional = Nonedatasets: Optional = Nonetags: Optional = Noneignore_metadata_errors: bool = False**kwargs )
Parameters
- title (
str
, optional) β Title of the Space. - sdk (
str
, optional) β SDK of the Space (one ofgradio
,streamlit
,docker
, orstatic
). - sdk_version (
str
, optional) β Version of the used SDK (if Gradio/Streamlit sdk). - python_version (
str
, optional) β Python version used in the Space (if Gradio/Streamlit sdk). - app_file (
str
, optional) β Path to your main application file (which contains either gradio or streamlit Python code, or static html code). Path is relative to the root of the repository. - app_port (
str
, optional) β Port on which your application is running. Used only if sdk isdocker
. - license (
str
, optional) β License of this model. Example: apache-2.0 or any license from https://huggingface.co/docs/hub/repositories-licenses. - duplicated_from (
str
, optional) β ID of the original Space if this is a duplicated Space. - models (List
str
, optional) β List of models related to this Space. Should be a dataset ID found on https://hf.co/models. - datasets (
List[str]
, optional) β List of datasets related to this Space. Should be a dataset ID found on https://hf.co/datasets. - tags (
List[str]
, optional) β List of tags to add to your Space that can be used when filtering on the Hub. - ignore_metadata_errors (
str
) β If True, errors while parsing the metadata section will be ignored. Some information might be lost during the process. Use it at your own risk. - kwargs (
dict
, optional) β Additional metadata that will be added to the space card.
Space Card Metadata that is used by Hugging Face Hub when included at the top of your README.md
To get an exhaustive reference of Spaces configuration, please visit https://huggingface.co/docs/hub/spaces-config-reference#spaces-configuration-reference.
Example:
>>> from huggingface_hub import SpaceCardData
>>> card_data = SpaceCardData(
... title="Dreambooth Training",
... license="mit",
... sdk="gradio",
... duplicated_from="multimodalart/dreambooth-training"
... )
>>> card_data.to_dict()
{'title': 'Dreambooth Training', 'sdk': 'gradio', 'license': 'mit', 'duplicated_from': 'multimodalart/dreambooth-training'}
Utilities
EvalResult
class huggingface_hub.EvalResult
< source >( task_type: strdataset_type: strdataset_name: strmetric_type: strmetric_value: Anytask_name: Optional = Nonedataset_config: Optional = Nonedataset_split: Optional = Nonedataset_revision: Optional = Nonedataset_args: Optional = Nonemetric_name: Optional = Nonemetric_config: Optional = Nonemetric_args: Optional = Noneverified: Optional = Noneverify_token: Optional = Nonesource_name: Optional = Nonesource_url: Optional = None )
Parameters
- task_type (
str
) β The task identifier. Example: βimage-classificationβ. - dataset_type (
str
) β The dataset identifier. Example: βcommon_voiceβ. Use dataset id from https://hf.co/datasets. - dataset_name (
str
) β A pretty name for the dataset. Example: βCommon Voice (French)β. - metric_type (
str
) β The metric identifier. Example: βwerβ. Use metric id from https://hf.co/metrics. - metric_value (
Any
) β The metric value. Example: 0.9 or β20.0 Β± 1.2β. - task_name (
str
, optional) β A pretty name for the task. Example: βSpeech Recognitionβ. - dataset_config (
str
, optional) β The name of the dataset configuration used inload_dataset()
. Example: fr inload_dataset("common_voice", "fr")
. See thedatasets
docs for more info: https://hf.co/docs/datasets/package_reference/loading_methods#datasets.load_dataset.name - dataset_split (
str
, optional) β The split used inload_dataset()
. Example: βtestβ. - dataset_revision (
str
, optional) β The revision (AKA Git Sha) of the dataset used inload_dataset()
. Example: 5503434ddd753f426f4b38109466949a1217c2bb - dataset_args (
Dict[str, Any]
, optional) β The arguments passed duringMetric.compute()
. Example forbleu
:{"max_order": 4}
- metric_name (
str
, optional) β A pretty name for the metric. Example: βTest WERβ. - metric_config (
str
, optional) β The name of the metric configuration used inload_metric()
. Example: bleurt-large-512 inload_metric("bleurt", "bleurt-large-512")
. See thedatasets
docs for more info: https://huggingface.co/docs/datasets/v2.1.0/en/loading#load-configurations - metric_args (
Dict[str, Any]
, optional) β The arguments passed duringMetric.compute()
. Example forbleu
: max_order: 4 - verified (
bool
, optional) β Indicates whether the metrics originate from Hugging Faceβs evaluation service or not. Automatically computed by Hugging Face, do not set. - verify_token (
str
, optional) β A JSON Web Token that is used to verify whether the metrics originate from Hugging Faceβs evaluation service or not. - source_name (
str
, optional) β The name of the source of the evaluation result. Example: βOpen LLM Leaderboardβ. - source_url (
str
, optional) β The URL of the source of the evaluation result. Example: βhttps://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboardβ.
Flattened representation of individual evaluation results found in model-index of Model Cards.
For more information on the model-index spec, see https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1.
Return True if self
and other
describe exactly the same metric but with a
different value.
model_index_to_eval_results
huggingface_hub.repocard_data.model_index_to_eval_results
< source >( model_index: List ) β model_name (str
)
Parameters
- model_index (
List[Dict[str, Any]]
) β A model index data structure, likely coming from a README.md file on the Hugging Face Hub.
Returns
model_name (str
)
The name of the model as found in the model index. This is used as the
identifier for the model on leaderboards like PapersWithCode.
eval_results (List[EvalResult]
):
A list of huggingface_hub.EvalResult
objects containing the metrics
reported in the provided model_index.
Takes in a model index and returns the model name and a list of huggingface_hub.EvalResult
objects.
A detailed spec of the model index can be found here: https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1
Example:
>>> from huggingface_hub.repocard_data import model_index_to_eval_results
>>> # Define a minimal model index
>>> model_index = [
... {
... "name": "my-cool-model",
... "results": [
... {
... "task": {
... "type": "image-classification"
... },
... "dataset": {
... "type": "beans",
... "name": "Beans"
... },
... "metrics": [
... {
... "type": "accuracy",
... "value": 0.9
... }
... ]
... }
... ]
... }
... ]
>>> model_name, eval_results = model_index_to_eval_results(model_index)
>>> model_name
'my-cool-model'
>>> eval_results[0].task_type
'image-classification'
>>> eval_results[0].metric_type
'accuracy'
eval_results_to_model_index
huggingface_hub.repocard_data.eval_results_to_model_index
< source >( model_name: streval_results: List ) β model_index (List[Dict[str, Any]]
)
Parameters
- model_name (
str
) β Name of the model (ex. βmy-cool-modelβ). This is used as the identifier for the model on leaderboards like PapersWithCode. - eval_results (
List[EvalResult]
) β List ofhuggingface_hub.EvalResult
objects containing the metrics to be reported in the model-index.
Returns
model_index (List[Dict[str, Any]]
)
The eval_results converted to a model-index.
Takes in given model name and list of huggingface_hub.EvalResult
and returns a
valid model-index that will be compatible with the format expected by the
Hugging Face Hub.
Example:
>>> from huggingface_hub.repocard_data import eval_results_to_model_index, EvalResult
>>> # Define minimal eval_results
>>> eval_results = [
... EvalResult(
... task_type="image-classification", # Required
... dataset_type="beans", # Required
... dataset_name="Beans", # Required
... metric_type="accuracy", # Required
... metric_value=0.9, # Required
... )
... ]
>>> eval_results_to_model_index("my-cool-model", eval_results)
[{'name': 'my-cool-model', 'results': [{'task': {'type': 'image-classification'}, 'dataset': {'name': 'Beans', 'type': 'beans'}, 'metrics': [{'type': 'accuracy', 'value': 0.9}]}]}]
metadata_eval_result
huggingface_hub.metadata_eval_result
< source >( model_pretty_name: strtask_pretty_name: strtask_id: strmetrics_pretty_name: strmetrics_id: strmetrics_value: Anydataset_pretty_name: strdataset_id: strmetrics_config: Optional = Nonemetrics_verified: bool = Falsedataset_config: Optional = Nonedataset_split: Optional = Nonedataset_revision: Optional = Nonemetrics_verification_token: Optional = None ) β dict
Parameters
- model_pretty_name (
str
) β The name of the model in natural language. - task_pretty_name (
str
) β The name of a task in natural language. - task_id (
str
) β Example: automatic-speech-recognition. A task id. - metrics_pretty_name (
str
) β A name for the metric in natural language. Example: Test WER. - metrics_id (
str
) β Example: wer. A metric id from https://hf.co/metrics. - metrics_value (
Any
) β The value from the metric. Example: 20.0 or β20.0 Β± 1.2β. - dataset_pretty_name (
str
) β The name of the dataset in natural language. - dataset_id (
str
) β Example: common_voice. A dataset id from https://hf.co/datasets. - metrics_config (
str
, optional) β The name of the metric configuration used inload_metric()
. Example: bleurt-large-512 inload_metric("bleurt", "bleurt-large-512")
. - metrics_verified (
bool
, optional, defaults toFalse
) β Indicates whether the metrics originate from Hugging Faceβs evaluation service or not. Automatically computed by Hugging Face, do not set. - dataset_config (
str
, optional) β Example: fr. The name of the dataset configuration used inload_dataset()
. - dataset_split (
str
, optional) β Example: test. The name of the dataset split used inload_dataset()
. - dataset_revision (
str
, optional) β Example: 5503434ddd753f426f4b38109466949a1217c2bb. The name of the dataset dataset revision used inload_dataset()
. - metrics_verification_token (
bool
, optional) β A JSON Web Token that is used to verify whether the metrics originate from Hugging Faceβs evaluation service or not.
Returns
dict
a metadata dict with the result from a model evaluated on a dataset.
Creates a metadata dict with the result from a model evaluated on a dataset.
Example:
>>> from huggingface_hub import metadata_eval_result
>>> results = metadata_eval_result(
... model_pretty_name="RoBERTa fine-tuned on ReactionGIF",
... task_pretty_name="Text Classification",
... task_id="text-classification",
... metrics_pretty_name="Accuracy",
... metrics_id="accuracy",
... metrics_value=0.2662102282047272,
... dataset_pretty_name="ReactionJPEG",
... dataset_id="julien-c/reactionjpeg",
... dataset_config="default",
... dataset_split="test",
... )
>>> results == {
... 'model-index': [
... {
... 'name': 'RoBERTa fine-tuned on ReactionGIF',
... 'results': [
... {
... 'task': {
... 'type': 'text-classification',
... 'name': 'Text Classification'
... },
... 'dataset': {
... 'name': 'ReactionJPEG',
... 'type': 'julien-c/reactionjpeg',
... 'config': 'default',
... 'split': 'test'
... },
... 'metrics': [
... {
... 'type': 'accuracy',
... 'value': 0.2662102282047272,
... 'name': 'Accuracy',
... 'verified': False
... }
... ]
... }
... ]
... }
... ]
... }
True
metadata_update
huggingface_hub.metadata_update
< source >( repo_id: strmetadata: Dictrepo_type: Optional = Noneoverwrite: bool = Falsetoken: Optional = Nonecommit_message: Optional = Nonecommit_description: Optional = Nonerevision: Optional = Nonecreate_pr: bool = Falseparent_commit: Optional = None ) β str
Parameters
- repo_id (
str
) β The name of the repository. - metadata (
dict
) β A dictionary containing the metadata to be updated. - repo_type (
str
, optional) β Set to"dataset"
or"space"
if updating to a dataset or space,None
or"model"
if updating to a model. Default isNone
. - overwrite (
bool
, optional, defaults toFalse
) β If set toTrue
an existing field can be overwritten, otherwise attempting to overwrite an existing field will cause an error. - token (
str
, optional) β The Hugging Face authentication token. - commit_message (
str
, optional) β The summary / title / first line of the generated commit. Defaults tof"Update metadata with huggingface_hub"
- commit_description (
str
optional) β The description of the generated commit - revision (
str
, optional) β The git revision to commit from. Defaults to the head of the"main"
branch. - create_pr (
boolean
, optional) β Whether or not to create a Pull Request fromrevision
with that commit. Defaults toFalse
. - parent_commit (
str
, optional) β The OID / SHA of the parent commit, as a hexadecimal string. Shorthands (7 first characters) are also supported. If specified andcreate_pr
isFalse
, the commit will fail ifrevision
does not point toparent_commit
. If specified andcreate_pr
isTrue
, the pull request will be created fromparent_commit
. Specifyingparent_commit
ensures the repo has not changed before committing the changes, and can be especially useful if the repo is updated / committed to concurrently.
Returns
str
URL of the commit which updated the card metadata.
Updates the metadata in the README.md of a repository on the Hugging Face Hub.
If the README.md file doesnβt exist yet, a new one is created with metadata and an
the default ModelCard or DatasetCard template. For space
repo, an error is thrown
as a Space cannot exist without a README.md
file.
Example:
>>> from huggingface_hub import metadata_update
>>> metadata = {'model-index': [{'name': 'RoBERTa fine-tuned on ReactionGIF',
... 'results': [{'dataset': {'name': 'ReactionGIF',
... 'type': 'julien-c/reactiongif'},
... 'metrics': [{'name': 'Recall',
... 'type': 'recall',
... 'value': 0.7762102282047272}],
... 'task': {'name': 'Text Classification',
... 'type': 'text-classification'}}]}]}
>>> url = metadata_update("hf-internal-testing/reactiongif-roberta-card", metadata)