Hub Python 庫文件
倉庫卡片
並獲得增強的文件體驗
開始使用
倉庫卡片
huggingface_hub 庫提供了用於建立、共享和更新模型/資料集卡片的 Python 介面。訪問專用文件頁面以深入瞭解 Hub 上的模型卡片是什麼以及它們在底層如何工作。您還可以檢視我們的模型卡片指南,瞭解如何在自己的專案中使用這些實用工具。
倉庫卡片
RepoCard
物件是 ModelCard、DatasetCard 和 SpaceCard
的父類。
從字串內容初始化 RepoCard。內容應為 Markdown 檔案,開頭包含 YAML 塊,後跟 Markdown 主體。
示例
>>> 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
。
from_template
< 來源 >( 卡片_資料: CardData 模板_路徑: typing.Optional[str] = None 模板_字串: typing.Optional[str] = None **template_kwargs ) → huggingface_hub.repocard.RepoCard
從模板初始化 RepoCard。預設情況下,它使用預設模板。
模板是 Jinja2 模板,可以透過傳遞關鍵字引數進行自定義。
載入
< 來源 >( 倉庫_ID_或_路徑: typing.Union[str, pathlib.Path] 倉庫_型別: typing.Optional[str] = None 令牌: typing.Optional[str] = None 忽略_元資料_錯誤: bool = False ) → huggingface_hub.repocard.RepoCard
引數
- repo_id_or_path (
Union[str, Path]
) — 與 Hugging Face Hub 倉庫或本地檔案路徑關聯的倉庫 ID。 - repo_type (
str
, 可選) — 要推送到的 Hugging Face 倉庫型別。預設為 None,將使用“模型”。其他選項是“資料集”和“空間”。從本地檔案路徑載入時未使用。如果從子類呼叫此函式,預設值將為子類的repo_type
。 - token (
str
, 可選) — 身份驗證令牌,透過huggingface_hub.HfApi.login
方法獲取。將預設為儲存的令牌。 - ignore_metadata_errors (
str
) — 如果為 True,解析元資料部分時發生的錯誤將被忽略。在此過程中可能會丟失一些資訊。請自行承擔風險。
從倉庫的 README.md 檔案或檔案路徑初始化的 RepoCard(或子類)。
從 Hugging Face Hub 倉庫的 README.md 或本地檔案路徑初始化 RepoCard。
push_to_hub
< 來源 >( 倉庫_ID: str 令牌: typing.Optional[str] = None 倉庫_型別: typing.Optional[str] = None 提交_資訊: typing.Optional[str] = None 提交_描述: typing.Optional[str] = None 版本: typing.Optional[str] = None 建立_PR: typing.Optional[bool] = None 父提交: typing.Optional[str] = None ) → str
引數
- repo_id (
str
) — 要推送到的 Hugging Face Hub 倉庫的倉庫 ID。示例:“nateraw/food”。 - token (
str
, 可選) — 身份驗證令牌,透過huggingface_hub.HfApi.login
方法獲取。將預設為儲存的令牌。 - repo_type (
str
, 可選, 預設為“model”) — 要推送到的 Hugging Face 倉庫型別。選項有“model”、“dataset”和“space”。如果此函式由子類呼叫,它將預設為子類的repo_type
。 - commit_message (
str
, 可選) — 生成的提交的摘要/標題/第一行。 - commit_description (
str
, 可選) — 生成的提交的描述。 - revision (
str
, 可選) — 要從其提交的 git 版本。預設為"main"
分支的頭部。 - create_pr (
bool
, 可選) — 是否建立包含此提交的拉取請求。預設為False
。 - parent_commit (
str
, 可選) — 父提交的 OID / SHA,以十六進位制字串表示。也支援簡寫(前 7 個字元)。如果指定且create_pr
為False
,則如果revision
不指向parent_commit
,提交將失敗。如果指定且create_pr
為True
,將從parent_commit
建立拉取請求。指定parent_commit
確保在提交更改之前倉庫未更改,在倉庫同時更新/提交時尤其有用。
返回
字串
更新卡片元資料的提交 URL。
將 RepoCard 推送到 Hugging Face Hub 倉庫。
儲存
< 來源 >( 檔案路徑: typing.Union[pathlib.Path, str] )
將 RepoCard 儲存到檔案。
驗證
< 來源 >( 倉庫_型別: typing.Optional[str] = None )
根據 Hugging Face Hub 的卡片驗證邏輯驗證卡片。使用此函式需要訪問網際網路,因此它僅由 huggingface_hub.repocard.RepoCard.push_to_hub() 內部呼叫。
- 如果卡片未能透過驗證檢查,則引發
ValueError
。 - 如果 Hub API 請求因任何其他原因失敗,則引發
HTTPError
。
卡片資料
CardData 物件是 ModelCardData 和 DatasetCardData 的父類。
包含 RepoCard 元資料的結構。
CardData 是 ModelCardData 和 DatasetCardData 的父類。
元資料可以匯出為字典或 YAML。匯出可以自定義以改變資料的表示(例如:扁平化評估結果)。CardData
的行為類似於字典(可以獲取、彈出、設定值),但不繼承自 dict
以允許此匯出步驟。
獲取給定元資料鍵的值。
彈出給定元資料鍵的值。
將 CardData 轉換為字典。
to_yaml
< 來源 >( 換行符 = None 原始_順序: typing.Optional[typing.List[str]] = None ) → str
將 CardData 轉儲為 YAML 塊,以便包含在 README.md 檔案中。
模型卡片
ModelCard
from_template
< 來源 >( 卡片_資料: ModelCardData 模板_路徑: typing.Optional[str] = None 模板_字串: typing.Optional[str] = None **template_kwargs ) → huggingface_hub.ModelCard
從模板初始化 ModelCard。預設情況下,它使用預設模板,該模板可在此處找到:https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md
模板是 Jinja2 模板,可以透過傳遞關鍵字引數進行自定義。
示例
>>> 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: typing.Union[typing.List[str], str, NoneType] = None datasets: typing.Union[typing.List[str], str, NoneType] = None eval_results: typing.Optional[typing.List[huggingface_hub.repocard_data.EvalResult]] = None language: typing.Union[typing.List[str], str, NoneType] = None library_name: typing.Optional[str] = None license: typing.Optional[str] = None license_name: typing.Optional[str] = None license_link: typing.Optional[str] = None metrics: typing.Optional[typing.List[str]] = None model_name: typing.Optional[str] = None pipeline_tag: typing.Optional[str] = None tags: typing.Optional[typing.List[str]] = None ignore_metadata_errors: bool = False **kwargs )
引數
- base_model (
str
或List[str]
, 可選) — 派生模型的基模型識別符號。例如,如果您的模型是現有模型的微調或介面卡,則適用。該值必須是 Hub 上模型的 ID(如果您的模型派生自多個模型,則為 ID 列表)。預設為 None。 - datasets (
Union[str, List[str]]
, 可選) — 用於訓練此模型的資料集或資料集列表。應為 https://huggingface.co/datasets 上找到的資料集 ID。預設為 None。 - eval_results (
Union[List[EvalResult], EvalResult]
, 可選) — 定義模型評估結果的 `huggingface_hub.EvalResult` 列表。如果提供,`model_name` 將用作 PapersWithCode 排行榜上的名稱。預設為 `None`。 - language (
Union[str, List[str]]
, 可選) — 模型訓練資料或元資料的語言。必須是 ISO 639-1、639-2 或 639-3 程式碼(兩個/三個字母),或“code”、“multilingual”等特殊值。預設為 `None`。 - library_name (
str
, 可選) — 模型使用的庫名稱。示例:keras 或 https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/src/model-libraries.ts 中的任何庫。預設為 None。 - license (
str
, 可選) — 此模型的許可證。示例:apache-2.0 或 https://huggingface.co/docs/hub/repositories-licenses 中的任何許可證。預設為 None。 - license_name (
str
, 可選) — 此模型的許可證名稱。預設為 None。與 `license_link` 結合使用。常見許可證(Apache-2.0、MIT、CC-BY-SA-4.0)不需要名稱。在這種情況下,請使用 `license`。 - license_link (
str
, 可選) — 此模型的許可證連結。預設為 None。與 `license_name` 結合使用。常見許可證(Apache-2.0、MIT、CC-BY-SA-4.0)不需要連結。在這種情況下,請使用 `license`。 - metrics (
List[str]
, 可選) — 用於評估此模型的指標列表。應為可在 https://huggingface.co/metrics 找到的指標名稱。示例:“accuracy”。預設為 None。 - model_name (
str
, 可選) — 此模型的名稱。它與 `eval_results` 一起用於在卡片元資料中構建 `model-index`。您在此處提供的名稱將用於 PapersWithCode 的排行榜。如果未提供,則預設使用倉庫名稱。預設為 None。 - pipeline_tag (
str
, 可選) — 與模型關聯的管道標籤。示例:“text-classification”。 - tags (
List[str]
, 可選) — 用於在 Hugging Face Hub 上篩選時新增到模型的標籤列表。預設為 None。 - ignore_metadata_errors (
str
) — 如果為 True,解析元資料部分時發生的錯誤將被忽略。在此過程中可能會丟失一些資訊。使用風險自負。 - kwargs (
dict
, 可選) — 將新增到模型卡中的其他元資料。預設為 None。
Hugging Face Hub 在您的 README.md 頂部包含時使用的模型卡元資料
示例
>>> 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']}
資料集卡片
資料集卡片在機器學習社群中也稱為資料卡片。
DatasetCard
from_template
< source >( card_data: DatasetCardData template_path: typing.Optional[str] = None template_str: typing.Optional[str] = None **template_kwargs ) → huggingface_hub.DatasetCard
從模板初始化 DatasetCard。預設情況下,它使用預設模板,該模板可在此處找到:https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/datasetcard_template.md
模板是 Jinja2 模板,可以透過傳遞關鍵字引數進行自定義。
示例
>>> 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: typing.Union[typing.List[str], str, NoneType] = None license: typing.Union[typing.List[str], str, NoneType] = None annotations_creators: typing.Union[typing.List[str], str, NoneType] = None language_creators: typing.Union[typing.List[str], str, NoneType] = None multilinguality: typing.Union[typing.List[str], str, NoneType] = None size_categories: typing.Union[typing.List[str], str, NoneType] = None source_datasets: typing.Optional[typing.List[str]] = None task_categories: typing.Union[typing.List[str], str, NoneType] = None task_ids: typing.Union[typing.List[str], str, NoneType] = None paperswithcode_id: typing.Optional[str] = None pretty_name: typing.Optional[str] = None train_eval_index: typing.Optional[typing.Dict] = None config_names: typing.Union[typing.List[str], str, NoneType] = None ignore_metadata_errors: bool = False **kwargs )
引數
- language (
List[str]
, 可選) — 資料集的語言資料或元資料。必須是 ISO 639-1、639-2 或 639-3 程式碼(兩個/三個字母),或“code”、“multilingual”等特殊值。 - license (
Union[str, List[str]]
, 可選) — 此資料集的許可證。示例:apache-2.0 或 https://huggingface.co/docs/hub/repositories-licenses 中的任何許可證。 - annotations_creators (
Union[str, List[str]]
, 可選) — 資料集的註釋建立方式。選項包括:“found”、“crowdsourced”、“expert-generated”、“machine-generated”、“no-annotation”、“other”。 - language_creators (
Union[str, List[str]]
, 可選) — 資料集中基於文字的資料的建立方式。選項包括:“found”、“crowdsourced”、“expert-generated”、“machine-generated”、“other” - multilinguality (
Union[str, List[str]]
, 可選) — 資料集是否為多語言。選項包括:“monolingual”、“multilingual”、“translation”、“other”。 - size_categories (
Union[str, List[str]]
, 可選) — 資料集中的示例數量。選項包括:“n<1K”、“1K1T”和“other”。 - source_datasets (
List[str]]
, 可選) — 指示資料集是原始資料集還是從現有資料集擴充套件而來。選項包括:“original”和“extended”。 - task_categories (
Union[str, List[str]]
, 可選) — 資料集支援的任務類別? - task_ids (
Union[str, List[str]]
, 可選) — 資料集支援的特定任務? - paperswithcode_id (
str
, 可選) — PapersWithCode 上資料集的 ID。 - pretty_name (
str
, 可選) — 資料集更易於閱讀的名稱。(例如:“貓狗大戰”) - train_eval_index (
Dict
, 可選) — 描述在 Hub 上進行評估所需規範的字典。如果未提供,將從 kwargs 的“train-eval-index”鍵中收集。 - config_names (
Union[str, List[str]]
, 可選) — 資料集的可用資料集配置列表。
Hugging Face Hub 在您的 README.md 頂部包含時使用的資料集卡片元資料
空間卡片
SpaceCard
SpaceCardData
class huggingface_hub.SpaceCardData
< source >( title: typing.Optional[str] = None sdk: typing.Optional[str] = None sdk_version: typing.Optional[str] = None python_version: typing.Optional[str] = None app_file: typing.Optional[str] = None app_port: typing.Optional[int] = None license: typing.Optional[str] = None duplicated_from: typing.Optional[str] = None models: typing.Optional[typing.List[str]] = None datasets: typing.Optional[typing.List[str]] = None tags: typing.Optional[typing.List[str]] = None ignore_metadata_errors: bool = False **kwargs )
引數
- title (
str
, 可選) — Space 的標題。 - sdk (
str
, 可選) — Space 的 SDK(`gradio`、`streamlit`、`docker` 或 `static` 之一)。 - sdk_version (
str
, 可選) — 所使用 SDK 的版本(如果是 Gradio/Streamlit SDK)。 - python_version (
str
, 可選) — Space 中使用的 Python 版本(如果為 Gradio/Streamlit sdk)。 - app_file (
str
, 可選) — 主應用程式檔案的路徑(包含 gradio 或 streamlit Python 程式碼,或靜態 html 程式碼)。路徑是相對於倉庫根目錄的。 - app_port (
str
, 可選) — 應用程式執行的埠。僅當 sdk 為docker
時使用。 - license (
str
, 可選) — 此模型的許可證。示例:apache-2.0 或 https://huggingface.co/docs/hub/repositories-licenses 中的任何許可證。 - duplicated_from (
str
, 可選) — 如果此 Space 是複製的 Space,則為原始 Space 的 ID。 - models (List
str
, 可選) — 與此 Space 相關的模型列表。應為 https://huggingface.co/models 上找到的資料集 ID。 - datasets (
List[str]
, 可選) — 與此 Space 相關的列表。應為 https://huggingface.co/datasets 上找到的資料集 ID。 - tags (
List[str]
, 可選) — 要新增到 Space 的標籤列表,可在 Hub 上過濾時使用。 - ignore_metadata_errors (
str
) — 如果為 True,則在解析元資料部分時將忽略錯誤。在此過程中可能會丟失某些資訊。請自行承擔風險。 - kwargs (
dict
, 可選) — 將新增到 Space 卡片中的其他元資料。
Hugging Face Hub 在 README.md 檔案頂部包含的 Space Card 元資料
有關 Spaces 配置的詳盡參考,請訪問 https://huggingface.co/docs/hub/spaces-config-reference#spaces-configuration-reference。
示例
>>> 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'}
實用工具
EvalResult
class huggingface_hub.EvalResult
< source >( task_type: str dataset_type: str dataset_name: str metric_type: str metric_value: typing.Any task_name: typing.Optional[str] = None dataset_config: typing.Optional[str] = None dataset_split: typing.Optional[str] = None dataset_revision: typing.Optional[str] = None dataset_args: typing.Optional[typing.Dict[str, typing.Any]] = None metric_name: typing.Optional[str] = None metric_config: typing.Optional[str] = None metric_args: typing.Optional[typing.Dict[str, typing.Any]] = None verified: typing.Optional[bool] = None verify_token: typing.Optional[str] = None source_name: typing.Optional[str] = None source_url: typing.Optional[str] = None )
引數
- task_type (
str
) — 任務識別符號。示例:“image-classification”。 - dataset_type (
str
) — 資料集識別符號。示例:“common_voice”。使用 https://huggingface.co/datasets 中的資料集 ID。 - dataset_name (
str
) — 資料集的漂亮名稱。示例:“Common Voice (French)”。 - metric_type (
str
) — 評估指標識別符號。示例:“wer”。使用 https://huggingface.co/metrics 中的評估指標 ID。 - metric_value (
Any
) — 評估指標值。示例:0.9 或 “20.0 ± 1.2”。 - task_name (
str
, 可選) — 任務的漂亮名稱。示例:“語音識別”。 - dataset_config (
str
, 可選) —load_dataset()
中使用的資料集配置名稱。示例:在load_dataset("common_voice", "fr")
中使用 fr。有關更多資訊,請參閱datasets
文件:https://huggingface.co/docs/datasets/package_reference/loading_methods#datasets.load_dataset.name - dataset_split (
str
, 可選) —load_dataset()
中使用的拆分。示例:“test”。 - dataset_revision (
str
, 可選) —load_dataset()
中使用的資料集修訂版本(即 Git Sha)。示例:5503434ddd753f426f4b38109466949a1217c2bb - dataset_args (
Dict[str, Any]
, 可選) — 在Metric.compute()
期間傳遞的引數。bleu 的示例:{"max_order": 4}
- metric_name (
str
, 可選) — 評估指標的漂亮名稱。示例:“Test WER”。 - metric_config (
str
, 可選) —load_metric()
中使用的評估指標配置名稱。示例:在load_metric("bleurt", "bleurt-large-512")
中使用 bleurt-large-512。有關更多資訊,請參閱datasets
文件:https://huggingface.co/docs/datasets/v2.1.0/en/loading#load-configurations - metric_args (
Dict[str, Any]
, 可選) — 在Metric.compute()
期間傳遞的引數。bleu 的示例:max_order: 4 - verified (
bool
, 可選) — 指示評估指標是否來自 Hugging Face 的評估服務。由 Hugging Face 自動計算,請勿設定。 - verify_token (
str
, 可選) — 用於驗證評估指標是否來自 Hugging Face 的評估服務的 JSON Web Token。 - source_name (
str
, 可選) — 評估結果來源的名稱。示例:“Open LLM 排行榜”。 - source_url (
str
, 可選) — 評估結果來源的 URL。示例:”https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard”。
模型卡中模型索引中找到的單個評估結果的扁平化表示。
有關模型索引規範的更多資訊,請參閱 https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1。
如果 self
和 other
描述的是完全相同的評估指標,但值不同,則返回 True。
model_index_to_eval_results
huggingface_hub.repocard_data.model_index_to_eval_results
< source >( model_index: typing.List[typing.Dict[str, typing.Any]] ) → model_name (str
)
接受模型索引並返回模型名稱和 huggingface_hub.EvalResult
物件列表。
有關模型索引的詳細規範,請參閱此處:https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1
示例
>>> 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: str eval_results: typing.List[huggingface_hub.repocard_data.EvalResult] ) → model_index (List[Dict[str, Any]]
)
接受給定的模型名稱和 huggingface_hub.EvalResult
列表,並返回一個與 Hugging Face Hub 期望的格式相容的有效模型索引。
示例
>>> 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: str task_pretty_name: str task_id: str metrics_pretty_name: str metrics_id: str metrics_value: typing.Any dataset_pretty_name: str dataset_id: str metrics_config: typing.Optional[str] = None metrics_verified: bool = False dataset_config: typing.Optional[str] = None dataset_split: typing.Optional[str] = None dataset_revision: typing.Optional[str] = None metrics_verification_token: typing.Optional[str] = None ) → dict
引數
- model_pretty_name (
str
) — 模型名稱,採用自然語言表示。 - task_pretty_name (
str
) — 任務名稱,採用自然語言表示。 - task_id (
str
) — 示例:automatic-speech-recognition。任務 ID。 - metrics_pretty_name (
str
) — 指標名稱,採用自然語言表示。示例:測試 WER。 - metrics_id (
str
) — 示例:wer。來自 https://huggingface.co/metrics 的評估指標 ID。 - metrics_value (
Any
) — 指標的值。示例:20.0 或 “20.0 ± 1.2”。 - dataset_pretty_name (
str
) — 資料集名稱,採用自然語言表示。 - dataset_id (
str
) — 示例:common_voice。來自 https://huggingface.co/datasets 的資料集 ID。 - metrics_config (
str
, 可選) —load_metric()
中使用的評估指標配置名稱。示例:在load_metric("bleurt", "bleurt-large-512")
中使用 bleurt-large-512。 - metrics_verified (
bool
, 可選,預設為False
) — 指示評估指標是否來自 Hugging Face 的評估服務。由 Hugging Face 自動計算,請勿設定。 - dataset_config (
str
, 可選) — 示例:fr。load_dataset()
中使用的資料集配置名稱。 - dataset_split (
str
, 可選) — 示例:test。load_dataset()
中使用的資料集拆分名稱。 - dataset_revision (
str
, 可選) — 示例:5503434ddd753f426f4b38109466949a1217c2bb。load_dataset()
中使用的資料集修訂版本。 - metrics_verification_token (
bool
, 可選) — 用於驗證評估指標是否來自 Hugging Face 的評估服務的 JSON Web Token。
返回
字典
一個元資料字典,包含模型在資料集上評估的結果。
建立包含模型在資料集上評估結果的元資料字典。
示例
>>> 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: str metadata: typing.Dict repo_type: typing.Optional[str] = None overwrite: bool = False token: typing.Optional[str] = None commit_message: typing.Optional[str] = None commit_description: typing.Optional[str] = None revision: typing.Optional[str] = None create_pr: bool = False parent_commit: typing.Optional[str] = None ) → str
引數
- repo_id (
str
) — 倉庫的名稱。 - metadata (
dict
) — 包含要更新的元資料字典。 - repo_type (
str
, 可選) — 如果更新到資料集或空間,則設定為"dataset"
或"space"
;如果更新到模型,則設定為None
或"model"
。預設為None
。 - overwrite (
bool
, 可選, 預設為False
) — 如果設定為True
,則可以覆蓋現有欄位,否則嘗試覆蓋現有欄位將導致錯誤。 - token (
str
, 可選) — Hugging Face 認證令牌。 - commit_message (
str
, 可選) — 生成提交的摘要/標題/第一行。預設為f"Update metadata with huggingface_hub"
- commit_description (
str
可選) — 生成提交的描述。 - revision (
str
, 可選) — 提交的 Git 修訂版本。預設為"main"
分支的 HEAD。 - create_pr (
boolean
, 可選) — 是否從revision
建立帶此提交的拉取請求。預設為False
。 - parent_commit (
str
, 可選) — 父提交的 OID / SHA,以十六進位制字串表示。也支援簡寫(前 7 個字元)。如果指定且create_pr
為False
,則如果revision
不指向parent_commit
,則提交將失敗。如果指定且create_pr
為True
,則將從parent_commit
建立拉取請求。指定parent_commit
可確保倉庫在提交更改之前沒有更改,在倉庫併發更新/提交時特別有用。
返回
字串
更新卡片元資料的提交 URL。
更新 Hugging Face Hub 上倉庫的 README.md 中的元資料。如果 README.md 檔案尚不存在,則會建立一個新檔案,其中包含元資料和預設的 ModelCard 或 DatasetCard 模板。對於 `space` 倉庫,如果 Space 不存在 `README.md` 檔案,則會丟擲錯誤。
示例
>>> 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)