# Thẻ kho

Thư viện huggingface_hub cung cấp giao diện Python để tạo, chia sẻ và cập nhật Model/Dataset Cards. Hãy truy cập [trang tài liệu chuyên biệt](https://huggingface.co/docs/hub/models-cards) để tìm hiểu sâu hơn về Model Cards trên Hub là gì và cách chúng hoạt động bên trong. Bạn cũng có thể xem [hướng dẫn về Model Cards](../how-to-model-cards) của chúng tôi để nắm bắt cách sử dụng các tiện ích này trong các dự án của riêng bạn.

## Thẻ kho[[huggingface_hub.RepoCard]]

Đối tượng `RepoCard` là lớp cha của [ModelCard](/docs/huggingface_hub/v2.5.0/vi/package_reference/cards#huggingface_hub.ModelCard), [DatasetCard](/docs/huggingface_hub/v2.5.0/vi/package_reference/cards#huggingface_hub.DatasetCard) và `SpaceCard`.

#### huggingface_hub.RepoCard[[huggingface_hub.RepoCard]]

```python
huggingface_hub.RepoCard(content: str, ignore_metadata_errors: bool = False)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L37)

#### __init__[[huggingface_hub.RepoCard.__init__]]

```python
__init__(content: str, ignore_metadata_errors: bool = False)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L42)

**Tham số:**

content (`str`) : Nội dung của tệp Markdown.

Khởi tạo một RepoCard từ nội dung chuỗi. Nội dung phải là một tệp Markdown có khối YAML ở đầu và phần thân Markdown.

Ví dụ:
```python
>>> 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'

```

> [!TIP]
> Gây ra lỗi sau:
>
> - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) khi nội dung của metadata thẻ repo không phải là một từ điển.

#### from_template[[huggingface_hub.RepoCard.from_template]]

```python
from_template(card_data: CardData, template_path: str | None = None, template_str: str | None = None, **template_kwargs)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L289)

**Tham số:**

card_data (`huggingface_hub.CardData`) : Một instance của huggingface_hub.CardData chứa các metadata bạn muốn bao gồm trong phần header YAML của repo card trên Hugging Face Hub.

template_path (`str`, *tùy chọn*) : Đường dẫn đến một tệp markdown có các biến mẫu Jinja tùy chọn, có thể được điền vào bằng `template_kwargs`. Mặc định là mẫu mặc định.

template_str (`str`, *tuỳ chọn*) : Chuỗi mẫu Jinja thô với các biến tuỳ chọn. Được sử dụng khi cả `template_path` lẫn mẫu mặc định đều không phù hợp. Bị bỏ qua nếu `template_path` cũng được cung cấp.

**Trả về:** [huggingface_hub.repocard.RepoCard](/docs/huggingface_hub/v2.5.0/vi/package_reference/cards#huggingface_hub.RepoCard)

Một instance RepoCard với dữ liệu thẻ và nội dung từ template được chỉ định.

Khởi tạo một RepoCard từ một mẫu. Mặc định, nó sử dụng mẫu mặc định.

Templates là các mẫu Jinja2 có thể được tùy chỉnh bằng cách truyền các đối số dạng từ khóa.

#### load[[huggingface_hub.RepoCard.load]]

```python
load(repo_id_or_path: str | pathlib.Path, repo_type: str | None = None, token: str | None = None, ignore_metadata_errors: bool = False)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L135)

**Tham số:**

repo_id_or_path (`Union[str, Path]`) : ID của kho liên quan đến một kho trên Hugging Face Hub hoặc một đường dẫn tệp cục bộ.

repo_type (`str`, *tùy chọn*) : Kiểu kho Hugging Face để đẩy lên. Mặc định là None, sẽ sử dụng "model". Các tùy chọn khác là "dataset" và "space". Không được sử dụng khi tải từ đường dẫn tệp cục bộ. Nếu điều này được gọi từ một lớp con, giá trị mặc định sẽ là `repo_type` của lớp con đó.

token (`str`, *tùy chọn*) : Token xác thực, được lấy bằng phương thức `huggingface_hub.HfApi.login`. Mặc định sẽ dùng token đã lưu.

ignore_metadata_errors (`str`) : Nếu là True, các lỗi khi phân tích phần metadata sẽ bị bỏ qua. Một số thông tin có thể bị mất trong quá trình này. Sử dụng với rủi ro của chính bạn.

**Trả về:** [huggingface_hub.repocard.RepoCard](/docs/huggingface_hub/v2.5.0/vi/package_reference/cards#huggingface_hub.RepoCard)

RepoCard (hoặc lớp con) được khởi tạo từ tệp README.md của repo hoặc đường dẫn tệp.

Khởi tạo một RepoCard từ README.md của một repo trên Hugging Face Hub hoặc từ một đường dẫn tệp cục bộ.

Ví dụ:
```python
>>> from huggingface_hub.repocard import RepoCard
>>> card = RepoCard.load("nateraw/food")
>>> assert card.data.tags == ["generated_from_trainer", "image-classification", "pytorch"]

```

#### push_to_hub[[huggingface_hub.RepoCard.push_to_hub]]

```python
push_to_hub(repo_id: str, token: str | None = None, repo_type: str | None = None, commit_message: str | None = None, commit_description: str | None = None, revision: str | None = None, create_pr: bool | None = None, parent_commit: str | None = None)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L226)

**Tham số:**

repo_id (`str`) : ID của kho trên Hugging Face Hub mà bạn muốn đẩy lên. Ví dụ: "nateraw/food".

token (`str`, *tùy chọn*) : Token xác thực, được lấy bằng phương thức `huggingface_hub.HfApi.login`. Mặc định sẽ dùng token đã lưu.

repo_type (`str`, *tùy chọn*, mặc định là "model") : Kiểu kho Hugging Face để đẩy lên. Các tùy chọn là "model", "dataset" và "space". Nếu hàm này được gọi bởi một lớp con, giá trị mặc định sẽ là `repo_type` của lớp con đó.

commit_message (`str`, *tùy chọn*) : Tóm tắt / tiêu đề / dòng đầu tiên của commit được tạo.

commit_description (`str`, *tùy chọn*) : Mô tả của commit được tạo.

revision (`str`, *tùy chọn*) : Bản sửa git để commit từ. Mặc định là đầu của nhánh `"main"`.

create_pr (`bool`, *tùy chọn*) : Có tạo Pull Request với commit này hay không. Mặc định là `False`.

parent_commit (`str`, *tùy chọn*) : OID / SHA của commit cha, dưới dạng chuỗi hex. Các dạng viết tắt (7 ký tự đầu tiên) cũng được hỗ trợ. Nếu được chỉ định và `create_pr` là `False`, commit sẽ thất bại nếu `revision` không trỏ đến `parent_commit`. Nếu được chỉ định và `create_pr` là `True`, pull request sẽ được tạo từ `parent_commit`. Việc chỉ định `parent_commit` đảm bảo rằng repo không bị thay đổi trước khi commit các thay đổi, và đặc biệt hữu ích nếu repo được cập nhật / commit đồng thời.

**Trả về:** `str`

URL của commit đã cập nhật metadata của thẻ.

Đẩy một RepoCard lên kho Hugging Face Hub.

#### Lưu[[huggingface_hub.RepoCard.save]]

```python
save(filepath: pathlib.Path | str)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L115)

**Tham số:**

filepath (`Union[Path, str]`) : Đường dẫn tệp đến tệp markdown cần lưu.

Lưu RepoCard vào tệp.

Ví dụ:
```python
>>> from huggingface_hub.repocard import RepoCard
>>> card = RepoCard("---\nlanguage: en\n---\n# This is a test repo card")
>>> card.save("/tmp/test.md")

```

#### validate[[huggingface_hub.RepoCard.validate]]

```python
validate(repo_type: str | None = None)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L189)

**Tham số:**

repo_type (`str`, *tùy chọn*, mặc định là "model") : Kiểu kho Hugging Face để đẩy lên. Các tùy chọn là "model", "dataset" và "space". Nếu hàm này được gọi từ một lớp con, giá trị mặc định sẽ là `repo_type` của lớp con đó.

Kiểm tra thẻ theo logic xác thực thẻ của Hugging Face Hub. Việc sử dụng hàm này yêu cầu quyền truy cập internet, do đó nó chỉ được gọi nội bộ bởi [huggingface_hub.repocard.RepoCard.push_to_hub()](/docs/huggingface_hub/v2.5.0/vi/package_reference/cards#huggingface_hub.RepoCard.push_to_hub).

> [!TIP]
> Gây ra các lỗi sau:
>
> - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) nếu thẻ không vượt qua các kiểm tra xác thực. - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) nếu yêu cầu đến Hub API thất bại vì bất kỳ lý do nào khác.

## Dữ liệu thẻ[[huggingface_hub.CardData]]

Đối tượng [CardData](/docs/huggingface_hub/v2.5.0/vi/package_reference/cards#huggingface_hub.CardData) là lớp cha của [ModelCardData](/docs/huggingface_hub/v2.5.0/vi/package_reference/cards#huggingface_hub.ModelCardData) và [DatasetCardData](/docs/huggingface_hub/v2.5.0/vi/package_reference/cards#huggingface_hub.DatasetCardData).

#### huggingface_hub.CardData[[huggingface_hub.CardData]]

```python
huggingface_hub.CardData(ignore_metadata_errors: bool = False, **kwargs)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard_data.py#L165)

Cấu trúc chứa các siêu dữ liệu từ một RepoCard.

[CardData](/docs/huggingface_hub/v2.5.0/vi/package_reference/cards#huggingface_hub.CardData) là lớp cha của [ModelCardData](/docs/huggingface_hub/v2.5.0/vi/package_reference/cards#huggingface_hub.ModelCardData) và [DatasetCardData](/docs/huggingface_hub/v2.5.0/vi/package_reference/cards#huggingface_hub.DatasetCardData).

Metadata có thể được xuất dưới dạng từ điển hoặc YAML. Việc xuất có thể được tùy chỉnh để thay đổi cách biểu diễn dữ liệu (ví dụ: làm phẳng kết quả đánh giá). `CardData` hoạt động như một từ điển (có thể lấy, xóa, gán giá trị) nhưng không kế thừa từ `dict` để cho phép bước xuất này.

#### get[[huggingface_hub.CardData.get]]

```python
get(key: str, default: typing.Any = None)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard_data.py#L228)

Lấy giá trị cho một khóa metadata đã cho.

#### pop[[huggingface_hub.CardData.pop]]

```python
pop(key: str, default: typing.Any = None)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard_data.py#L233)

Lấy giá trị cho một khóa metadata cụ thể.

#### to_dict[[huggingface_hub.CardData.to_dict]]

```python
to_dict()
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard_data.py#L178)

**Trả về:** `dict`

CardData được biểu diễn dưới dạng từ điển, sẵn sàng để xuất ra khối YAML nhằm đưa vào tệp README.md.

Chuyển đổi CardData thành dict.

#### to_yaml[[huggingface_hub.CardData.to_yaml]]

```python
to_yaml(line_break = None, original_order: list[str] | None = None)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard_data.py#L198)

**Tham số:**

line_break (str, *optional*) : Ký tự xuống dòng được sử dụng khi xuất ra yaml.

original_order (`list[str]`, *tùy chọn*) : Nếu được cung cấp, sắp xếp lại các trường metadata để khớp với danh sách này trước khi dump. Các key không có trong `original_order` sẽ được thêm vào sau các key được liệt kê, giữ nguyên thứ tự tương đối hiện có của chúng. Hữu ích để round-trip một khối YAML mà không làm xáo trộn các key của nó.

**Trả về:** `str`

CardData được biểu diễn dưới dạng khối YAML.

Xuất CardData thành một khối YAML để đưa vào tệp README.md.

## Thẻ mô hình

### ModelCard[[huggingface_hub.ModelCard]]

#### huggingface_hub.ModelCard[[huggingface_hub.ModelCard]]

```python
huggingface_hub.ModelCard(content: str, ignore_metadata_errors: bool = False)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L336)

#### from_template[[huggingface_hub.ModelCard.from_template]]

```python
from_template(card_data: ModelCardData, template_path: str | None = None, template_str: str | None = None, **template_kwargs)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L341)

**Tham số:**

card_data (`huggingface_hub.ModelCardData`) : Một instance của huggingface_hub.ModelCardData chứa các metadata bạn muốn bao gồm trong phần header YAML của model card trên Hugging Face Hub.

template_path (`str`, *tùy chọn*) : Đường dẫn đến một tệp markdown có các biến mẫu Jinja tùy chọn, có thể được điền vào bằng `template_kwargs`. Mặc định là mẫu mặc định.

template_str (`str`, *tuỳ chọn*) : Chuỗi mẫu Jinja thô với các biến tuỳ chọn. Được sử dụng khi cả `template_path` lẫn mẫu mặc định đều không phù hợp. Bị bỏ qua nếu `template_path` cũng được cung cấp.

**Trả về:** [huggingface_hub.ModelCard](/docs/huggingface_hub/v2.5.0/vi/package_reference/cards#huggingface_hub.ModelCard)

Một instance của ModelCard với dữ liệu thẻ và nội dung từ template được chỉ định.

Khởi tạo một ModelCard từ một mẫu. Mặc định, nó sử dụng mẫu mặc định, có thể tìm thấy tại đây: https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md

Templates là các mẫu Jinja2 có thể được tùy chỉnh bằng cách truyền các đối số dạng từ khóa.

Ví dụ:
```python
>>> 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[[huggingface_hub.ModelCardData]]

#### huggingface_hub.ModelCardData[[huggingface_hub.ModelCardData]]

```python
huggingface_hub.ModelCardData(base_model: str | list[str] | None = None, datasets: str | list[str] | None = None, eval_results: list[huggingface_hub.repocard_data.EvalResult] | None = None, language: str | list[str] | None = None, library_name: str | None = None, license: str | None = None, license_name: str | None = None, license_link: str | None = None, metrics: list[str] | None = None, model_name: str | None = None, pipeline_tag: str | None = None, tags: list[str] | None = None, ignore_metadata_errors: bool = False, **kwargs)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard_data.py#L271)

**Tham số:**

base_model (`str` hoặc `list[str]`, *tùy chọn*) : Định danh của mô hình gốc mà mô hình này kế thừa. Điều này áp dụng, chẳng hạn, nếu mô hình của bạn là một bản fine-tune hoặc adapter của một mô hình hiện có. Giá trị phải là ID của một mô hình trên Hub (hoặc một danh sách các ID nếu mô hình của bạn kế thừa từ nhiều mô hình). Mặc định là None.

datasets (`Union[str, list[str]]`, *tùy chọn*) : Dataset hoặc danh sách các dataset đã được sử dụng để huấn luyện mô hình này. Phải là một dataset ID được tìm thấy trên https://hf.co/datasets. Mặc định là None.

eval_results (`Union[list[EvalResult], EvalResult]`, *tùy chọn*) : Danh sách các `huggingface_hub.EvalResult` xác định kết quả đánh giá của mô hình. Nếu được cung cấp, `model_name` sẽ được dùng làm tên trên bảng xếp hạng của PapersWithCode. Mặc định là `None`.

language (`Union[str, list[str]]`, *tùy chọn*) : Ngôn ngữ của dữ liệu huấn luyện hoặc metadata của model. Nó phải là mã ISO 639-1, 639-2 hoặc 639-3 (hai/ba chữ cái), hoặc một giá trị đặc biệt như "code", "multilingual". Mặc định là `None`.

library_name (`str`, *tùy chọn*) : Tên của thư viện được sử dụng bởi mô hình này. Ví dụ: keras hoặc bất kỳ thư viện nào từ https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/src/model-libraries.ts. Mặc định là None.

license (`str`, *tùy chọn*) : Giấy phép của mô hình này. Ví dụ: apache-2.0 hoặc bất kỳ giấy phép nào từ https://huggingface.co/docs/hub/repositories-licenses. Mặc định là None.

license_name (`str`, *tùy chọn*) : Tên của giấy phép cho model này. Mặc định là None. Được sử dụng cùng với `license_link`. Các giấy phép phổ biến (Apache-2.0, MIT, CC-BY-SA-4.0) không cần tên. Trong trường hợp đó, hãy sử dụng `license` thay thế.

license_link (`str`, *tùy chọn*) : Liên kết đến giấy phép của mô hình này. Mặc định là None. Được sử dụng cùng với `license_name`. Các giấy phép phổ biến (Apache-2.0, MIT, CC-BY-SA-4.0) không cần liên kết. Trong trường hợp đó, hãy sử dụng `license` thay thế.

metrics (`list[str]`, *tùy chọn*) : Danh sách các chỉ số được sử dụng để đánh giá mô hình này. Phải là tên chỉ số có thể tìm thấy tại https://hf.co/metrics. Ví dụ: 'accuracy'. Mặc định là None.

model_name (`str`, *tùy chọn*) : Tên của model này. Nó được sử dụng cùng với `eval_results` để xây dựng `model-index` trong metadata của card. Tên bạn cung cấp ở đây sẽ được sử dụng trên bảng xếp hạng của PapersWithCode. Nếu None được cung cấp thì tên repo sẽ được sử dụng làm mặc định. Mặc định là None.

pipeline_tag (`str`, *tùy chọn*) : Thẻ pipeline liên quan đến mô hình. Ví dụ: "text-classification".

tags (`list[str]`, *tùy chọn*) : Danh sách các thẻ để thêm vào mô hình của bạn, có thể được sử dụng khi lọc trên Hugging Face Hub. Mặc định là None.

ignore_metadata_errors (`str`) : Nếu là True, các lỗi khi phân tích phần metadata sẽ bị bỏ qua. Một số thông tin có thể bị mất trong quá trình này. Sử dụng với rủi ro của chính bạn.

kwargs (`dict`, *tùy chọn*) : Các metadata bổ sung sẽ được thêm vào model card. Mặc định là None.

Metadata của Model Card được Hugging Face Hub sử dụng khi được bao gồm ở đầu tệp README.md của bạn

Ví dụ:
```python
>>> 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']}

```

## Thẻ Dữ liệu

Dataset cards còn được gọi là Data Cards trong cộng đồng ML.

### DatasetCard[[huggingface_hub.DatasetCard]]

#### huggingface_hub.DatasetCard[[huggingface_hub.DatasetCard]]

```python
huggingface_hub.DatasetCard(content: str, ignore_metadata_errors: bool = False)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L420)

#### from_template[[huggingface_hub.DatasetCard.from_template]]

```python
from_template(card_data: DatasetCardData, template_path: str | None = None, template_str: str | None = None, **template_kwargs)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L425)

**Tham số:**

card_data (`huggingface_hub.DatasetCardData`) : Một instance của huggingface_hub.DatasetCardData chứa các metadata bạn muốn bao gồm trong phần header YAML của dataset card trên Hugging Face Hub.

template_path (`str`, *tùy chọn*) : Đường dẫn đến một tệp markdown có các biến mẫu Jinja tùy chọn, có thể được điền vào bằng `template_kwargs`. Mặc định là mẫu mặc định.

template_str (`str`, *tuỳ chọn*) : Chuỗi mẫu Jinja thô với các biến tuỳ chọn. Được sử dụng khi cả `template_path` lẫn mẫu mặc định đều không phù hợp. Bị bỏ qua nếu `template_path` cũng được cung cấp.

**Trả về:** [huggingface_hub.DatasetCard](/docs/huggingface_hub/v2.5.0/vi/package_reference/cards#huggingface_hub.DatasetCard)

Một instance của DatasetCard với dữ liệu thẻ và nội dung từ template được chỉ định.

Khởi tạo một DatasetCard từ một template. Mặc định, nó sử dụng template mặc định, có thể tìm thấy tại đây: https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/datasetcard_template.md

Templates là các mẫu Jinja2 có thể được tùy chỉnh bằng cách truyền các đối số dạng từ khóa.

Ví dụ:
```python
>>> 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[[huggingface_hub.DatasetCardData]]

#### huggingface_hub.DatasetCardData[[huggingface_hub.DatasetCardData]]

```python
huggingface_hub.DatasetCardData(language: str | list[str] | None = None, license: str | list[str] | None = None, annotations_creators: str | list[str] | None = None, language_creators: str | list[str] | None = None, multilinguality: str | list[str] | None = None, size_categories: str | list[str] | None = None, source_datasets: list[str] | None = None, task_categories: str | list[str] | None = None, task_ids: str | list[str] | None = None, paperswithcode_id: str | None = None, pretty_name: str | None = None, train_eval_index: dict | None = None, config_names: str | list[str] | None = None, ignore_metadata_errors: bool = False, **kwargs)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard_data.py#L400)

**Tham số:**

language (`list[str]`, *tùy chọn*) : Ngôn ngữ của dữ liệu hoặc metadata của dataset. Nó phải là mã ISO 639-1, 639-2 hoặc 639-3 (hai/ba chữ cái), hoặc một giá trị đặc biệt như "code", "multilingual".

license (`Union[str, list[str]]`, *tùy chọn*) : Giấy phép của bộ dữ liệu này. Ví dụ: apache-2.0 hoặc bất kỳ giấy phép nào từ https://huggingface.co/docs/hub/repositories-licenses.

annotations_creators (`Union[str, list[str]]`, *tùy chọn*) : Cách các chú thích cho bộ dữ liệu được tạo ra. Các tùy chọn là: 'found', 'crowdsourced', 'expert-generated', 'machine-generated', 'no-annotation', 'other'.

language_creators (`Union[str, list[str]]`, *tùy chọn*) : Cách dữ liệu dạng văn bản trong bộ dữ liệu được tạo ra. Các tùy chọn là: 'found', 'crowdsourced', 'expert-generated', 'machine-generated', 'other'

multilinguality (`Union[str, list[str]]`, *tùy chọn*) : Dữ liệu có đa ngôn ngữ hay không. Các tùy chọn là: 'monolingual', 'multilingual', 'translation', 'other'.

size_categories (`Union[str, list[str]]`, *tùy chọn*) : Số lượng ví dụ trong bộ dữ liệu. Các tùy chọn là: 'n<1K', '1K1T' và 'other'.

source_datasets (`list[str]]`, *tùy chọn*) : Chỉ ra liệu bộ dữ liệu có phải là bộ dữ liệu gốc hay được mở rộng từ một bộ dữ liệu hiện có khác. Các tùy chọn là: 'original' và 'extended'.

task_categories (`Union[str, list[str]]`, *tùy chọn*) : Dữ liệu hỗ trợ những loại nhiệm vụ nào?

task_ids (`Union[str, list[str]]`, *tùy chọn*) : Bộ dữ liệu hỗ trợ những tác vụ cụ thể nào?

paperswithcode_id (`str`, *tùy chọn*) : ID của bộ dữ liệu trên PapersWithCode.

pretty_name (`str`, *tùy chọn*) : Tên dễ đọc hơn cho bộ dữ liệu. (vd. "Cats vs. Dogs")

train_eval_index (`dict`, *tùy chọn*) : Một từ điển mô tả thông số kỹ thuật cần thiết để thực hiện đánh giá trên Hub. Nếu không được cung cấp, nó sẽ được lấy từ khóa 'train-eval-index' trong kwargs.

config_names (`Union[str, list[str]]`, *tùy chọn*) : Một danh sách các cấu hình bộ dữ liệu có sẵn cho bộ dữ liệu.

Metadata của Dataset Card được Hugging Face Hub sử dụng khi được bao gồm ở đầu tệp README.md của bạn

## Thẻ không gian

### SpaceCard[[huggingface_hub.SpaceCard]]

#### huggingface_hub.SpaceCard[[huggingface_hub.SpaceCard]]

```python
huggingface_hub.SpaceCard(content: str, ignore_metadata_errors: bool = False)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L488)

### SpaceCardData[[huggingface_hub.SpaceCardData]]

#### huggingface_hub.SpaceCardData[[huggingface_hub.SpaceCardData]]

```python
huggingface_hub.SpaceCardData(title: str | None = None, sdk: str | None = None, sdk_version: str | None = None, python_version: str | None = None, app_file: str | None = None, app_port: int | None = None, license: str | None = None, duplicated_from: str | None = None, models: list[str] | None = None, datasets: list[str] | None = None, tags: list[str] | None = None, ignore_metadata_errors: bool = False, **kwargs)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard_data.py#L480)

**Tham số:**

title (`str`, *tùy chọn*) : Tiêu đề của Space.

sdk (`str`, *tùy chọn*) : SDK của Space (một trong `gradio`, `streamlit`, `docker`, hoặc `static`).

sdk_version (`str`, *tùy chọn*) : Phiên bản của SDK được sử dụng (nếu là Gradio/Streamlit sdk).

python_version (`str`, *tùy chọn*) : phiên bản Python được sử dụng trong Space (nếu là Gradio/Streamlit sdk).

app_file (`str`, *tùy chọn*) : Đường dẫn đến tệp ứng dụng chính của bạn (chứa mã Python gradio hoặc streamlit, hoặc mã html tĩnh). Đường dẫn là tương đối so với gốc của kho lưu trữ.

app_port (`str`, *tùy chọn*) : Cổng mà ứng dụng của bạn đang chạy. Chỉ được sử dụng nếu sdk là `docker`.

license (`str`, *tùy chọn*) : Giấy phép của mô hình này. Ví dụ: apache-2.0 hoặc bất kỳ giấy phép nào từ https://huggingface.co/docs/hub/repositories-licenses.

duplicated_from (`str`, *tùy chọn*) : ID của Space gốc nếu đây là một Space được nhân bản.

models (`list[str]`, *tùy chọn*) : Danh sách các mô hình liên quan đến Space này. Phải là một ID dataset được tìm thấy trên https://hf.co/models.

datasets (`list[str]`, *tùy chọn*) : Danh sách các dataset liên quan đến Space này. Phải là ID của dataset được tìm thấy trên https://hf.co/datasets.

tags (`list[str]`, *tùy chọn*) : Danh sách các thẻ để thêm vào Space của bạn, có thể được sử dụng khi lọc trên Hub.

ignore_metadata_errors (`str`) : Nếu là True, các lỗi khi phân tích phần metadata sẽ bị bỏ qua. Một số thông tin có thể bị mất trong quá trình này. Sử dụng với rủi ro của chính bạn.

kwargs (`dict`, *tùy chọn*) : Các metadata bổ sung sẽ được thêm vào thẻ space.

Space Card Metadata được Hugging Face Hub sử dụng khi được bao gồm ở đầu tệp README.md của bạn

Để có tài liệu tham khảo đầy đủ về cấu hình Spaces, vui lòng truy cập https://huggingface.co/docs/hub/spaces-config-reference#spaces-configuration-reference.

Ví dụ:
```python
>>> 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'}
```

## Công cụ tiện ích

### EvalResult[[huggingface_hub.EvalResult]]

#### huggingface_hub.EvalResult[[huggingface_hub.EvalResult]]

```python
huggingface_hub.EvalResult(task_type: str, dataset_type: str, dataset_name: str, metric_type: str, metric_value: typing.Any, task_name: str | None = None, dataset_config: str | None = None, dataset_split: str | None = None, dataset_revision: str | None = None, dataset_args: dict[str, typing.Any] | None = None, metric_name: str | None = None, metric_config: str | None = None, metric_args: dict[str, typing.Any] | None = None, verified: bool | None = None, verify_token: str | None = None, source_name: str | None = None, source_url: str | None = None)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard_data.py#L13)

**Tham số:**

task_type (`str`) : Định danh tác vụ. Ví dụ: "image-classification".

dataset_type (`str`) : Định danh bộ dữ liệu. Ví dụ: "common_voice". Sử dụng id bộ dữ liệu từ https://hf.co/datasets.

dataset_name (`str`) : Một tên dễ đọc cho bộ dữ liệu. Ví dụ: "Common Voice (French)".

metric_type (`str`) : Định danh của chỉ số. Ví dụ: "wer". Sử dụng id chỉ số từ https://hf.co/metrics.

metric_value (`Any`) : Giá trị của chỉ số. Ví dụ: 0.9 hoặc "20.0 ± 1.2".

task_name (`str`, *tùy chọn*) : Một tên dễ đọc cho tác vụ. Ví dụ: "Nhận dạng giọng nói".

dataset_config (`str`, *tùy chọn*) : Tên của cấu hình bộ dữ liệu được sử dụng trong `load_dataset()`. Ví dụ: fr trong `load_dataset("common_voice", "fr")`. Xem tài liệu `datasets` để biết thêm thông tin: https://hf.co/docs/datasets/package_reference/loading_methods#datasets.load_dataset.name

dataset_split (`str`, *tùy chọn*) : Phần chia được sử dụng trong `load_dataset()`. Ví dụ: "test".

dataset_revision (`str`, *tùy chọn*) : Phiên bản (còn gọi là Git Sha) của bộ dữ liệu được sử dụng trong `load_dataset()`. Ví dụ: 5503434ddd753f426f4b38109466949a1217c2bb

dataset_args (`dict[str, Any]`, *tùy chọn*) : Các đối số được truyền trong `Metric.compute()`. Ví dụ cho `bleu`: `{"max_order": 4}`

metric_name (`str`, *tùy chọn*) : Một tên đẹp cho chỉ số. Ví dụ: "Test WER".

metric_config (`str`, *tùy chọn*) : Tên của cấu hình chỉ số được sử dụng trong `load_metric()`. Ví dụ: bleurt-large-512 trong `load_metric("bleurt", "bleurt-large-512")`. Xem tài liệu `datasets` để biết thêm thông tin: https://huggingface.co/docs/datasets/v2.1.0/en/loading#load-configurations

metric_args (`dict[str, Any]`, *tùy chọn*) : Các đối số được truyền trong `Metric.compute()`. Ví dụ cho `bleu`: max_order: 4

verified (`bool`, *tùy chọn*) : Chỉ ra liệu các chỉ số có xuất phát từ [dịch vụ đánh giá](https://huggingface.co/spaces/autoevaluate/model-evaluator) của Hugging Face hay không. Được Hugging Face tự động tính toán, không cần thiết lập.

verify_token (`str`, *tùy chọn*) : Một JSON Web Token được sử dụng để xác minh xem các chỉ số có xuất phát từ [dịch vụ đánh giá](https://huggingface.co/spaces/autoevaluate/model-evaluator) của Hugging Face hay không.

source_name (`str`, *tùy chọn*) : Tên của nguồn kết quả đánh giá. Ví dụ: "Open LLM Leaderboard".

source_url (`str`, *tùy chọn*) : URL của nguồn kết quả đánh giá. Ví dụ: "https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard".

Biểu diễn dạng phẳng của các kết quả đánh giá riêng lẻ được tìm thấy trong model-index của Model Cards.

Để biết thêm thông tin về quy cách model-index, hãy xem https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1.

#### is_equal_except_value[[huggingface_hub.EvalResult.is_equal_except_value]]

```python
is_equal_except_value(other: EvalResult)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard_data.py#L145)

Trả về True nếu `self` và `other` mô tả cùng một chỉ số chính xác nhưng với giá trị khác nhau.

### model_index_to_eval_results[[huggingface_hub.repocard_data.model_index_to_eval_results]]

#### huggingface_hub.repocard_data.model_index_to_eval_results[[huggingface_hub.repocard_data.model_index_to_eval_results]]

```python
huggingface_hub.repocard_data.model_index_to_eval_results(model_index: list)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard_data.py#L561)

**Tham số:**

model_index (`list[dict[str, Any]]`) : Cấu trúc dữ liệu chỉ mục mô hình, có thể đến từ tệp README.md trên Hugging Face Hub.

**Trả về:** model_name (`str`)

Tên của mô hình như được tìm thấy trong model index. Tên này được sử dụng làm định danh cho mô hình trên các bảng xếp hạng như PapersWithCode. eval_results (`list[EvalResult]`): Một danh sách các đối tượng `huggingface_hub.EvalResult` chứa các chỉ số được báo cáo trong model_index được cung cấp.

Nhận vào một chỉ mục mô hình và trả về tên mô hình cùng một danh sách các đối tượng `huggingface_hub.EvalResult`.

Chi tiết về đặc tả của chỉ mục mô hình có thể được tìm thấy tại đây: https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1

Ví dụ:
```python
>>> 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]]

#### huggingface_hub.repocard_data.eval_results_to_model_index[[huggingface_hub.repocard_data.eval_results_to_model_index]]

```python
huggingface_hub.repocard_data.eval_results_to_model_index(model_name: str, eval_results: list)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard_data.py#L681)

**Tham số:**

model_name (`str`) : Tên của mô hình (ví dụ: "my-cool-model"). Đây được dùng làm định danh cho mô hình trên các bảng xếp hạng như PapersWithCode.

eval_results (`list[EvalResult]`) : Danh sách các đối tượng `huggingface_hub.EvalResult` chứa các chỉ số cần báo cáo trong model-index.

**Trả về:** model_index (`list[dict[str, Any]]`)

eval_results được chuyển đổi thành model-index.

Nhận tên model đã cho và danh sách `huggingface_hub.EvalResult`, sau đó trả về một model-index hợp lệ, tương thích với định dạng được kỳ vọng bởi Hugging Face Hub.

Ví dụ:
```python
>>> 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]]

#### huggingface_hub.metadata_eval_result[[huggingface_hub.metadata_eval_result]]

```python
huggingface_hub.metadata_eval_result(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: str | None = None, metrics_verified: bool = False, dataset_config: str | None = None, dataset_split: str | None = None, dataset_revision: str | None = None, metrics_verification_token: str | None = None)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L560)

**Tham số:**

model_pretty_name (`str`) : Tên của mô hình trong ngôn ngữ tự nhiên.

task_pretty_name (`str`) : Tên của một tác vụ bằng ngôn ngữ tự nhiên.

task_id (`str`) : Ví dụ: automatic-speech-recognition. Một id của tác vụ.

metrics_pretty_name (`str`) : Tên của chỉ số bằng ngôn ngữ tự nhiên. Ví dụ: Test WER.

metrics_id (`str`) : Ví dụ: wer. Một id chỉ số từ https://hf.co/metrics.

metrics_value (`Any`) : Giá trị từ chỉ số. Ví dụ: 20.0 hoặc "20.0 ± 1.2".

dataset_pretty_name (`str`) : Tên của bộ dữ liệu bằng ngôn ngữ tự nhiên.

dataset_id (`str`) : Ví dụ: common_voice. Một id bộ dữ liệu từ https://hf.co/datasets.

metrics_config (`str`, *tùy chọn*) : Tên của cấu hình chỉ số được sử dụng trong `load_metric()`. Ví dụ: bleurt-large-512 trong `load_metric("bleurt", "bleurt-large-512")`.

metrics_verified (`bool`, *tùy chọn*, mặc định là `False`) : Chỉ ra liệu các chỉ số có xuất phát từ [dịch vụ đánh giá](https://huggingface.co/spaces/autoevaluate/model-evaluator) của Hugging Face hay không. Được Hugging Face tự động tính toán, không cần thiết lập.

dataset_config (`str`, *tùy chọn*) : Ví dụ: fr. Tên của cấu hình bộ dữ liệu được sử dụng trong `load_dataset()`.

dataset_split (`str`, *tùy chọn*) : Ví dụ: test. Tên của phần chia bộ dữ liệu được sử dụng trong `load_dataset()`.

dataset_revision (`str`, *tùy chọn*) : Ví dụ: 5503434ddd753f426f4b38109466949a1217c2bb. Tên của bản sửa đổi bộ dữ liệu được sử dụng trong `load_dataset()`.

metrics_verification_token (`bool`, *tuỳ chọn*) : Một JSON Web Token được sử dụng để xác minh xem các chỉ số có xuất phát từ [dịch vụ đánh giá](https://huggingface.co/spaces/autoevaluate/model-evaluator) của Hugging Face hay không.

**Trả về:** `dict`

một dict metadata chứa kết quả từ một model được đánh giá trên một dataset.

Tạo một từ điển metadata chứa kết quả từ một mô hình được đánh giá trên một tập dữ liệu.

Ví dụ:
```python
>>> 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]]

#### huggingface_hub.metadata_update[[huggingface_hub.metadata_update]]

```python
huggingface_hub.metadata_update(repo_id: str, metadata: dict, repo_type: str | None = None, overwrite: bool = False, token: str | None = None, commit_message: str | None = None, commit_description: str | None = None, revision: str | None = None, create_pr: bool = False, parent_commit: str | None = None)
```

[Nguồn](https://github.com/huggingface/huggingface_hub/blob/v2.5.0/src/huggingface_hub/repocard.py#L688)

**Tham số:**

repo_id (`str`) : Tên của kho lưu trữ.

metadata (`dict`) : Một từ điển chứa các siêu dữ liệu cần được cập nhật.

repo_type (`str`, *tùy chọn*) : Đặt thành `"dataset"` hoặc `"space"` nếu cập nhật lên một dataset hoặc space, `None` hoặc `"model"` nếu cập nhật lên một model. Mặc định là `None`.

overwrite (`bool`, *tùy chọn*, mặc định là `False`) : Nếu được đặt thành `True`, một trường hiện có có thể bị ghi đè, ngược lại, việc cố gắng ghi đè lên một trường hiện có sẽ gây ra lỗi.

token (`str`, *tùy chọn*) : Token xác thực Hugging Face.

commit_message (`str`, *tùy chọn*) : Tóm tắt / tiêu đề / dòng đầu tiên của commit được tạo. Mặc định là `f"Update metadata with huggingface_hub"`

commit_description (`str`, *tùy chọn*) : Mô tả của commit được tạo

revision (`str`, *tùy chọn*) : Bản sửa git để commit từ. Mặc định là đầu của nhánh `"main"`.

create_pr (`boolean`, *tùy chọn*) : Có tạo Pull Request từ `revision` với commit đó hay không. Mặc định là `False`.

parent_commit (`str`, *tùy chọn*) : OID / SHA của commit cha, dưới dạng chuỗi hex. Các dạng viết tắt (7 ký tự đầu tiên) cũng được hỗ trợ. Nếu được chỉ định và `create_pr` là `False`, commit sẽ thất bại nếu `revision` không trỏ đến `parent_commit`. Nếu được chỉ định và `create_pr` là `True`, pull request sẽ được tạo từ `parent_commit`. Việc chỉ định `parent_commit` đảm bảo rằng repo không bị thay đổi trước khi commit các thay đổi, và đặc biệt hữu ích nếu repo được cập nhật / commit đồng thời.

**Trả về:** `str`

URL của commit đã cập nhật metadata của thẻ.

Cập nhật metadata trong README.md của một repository trên Hugging Face Hub. Nếu tệp README.md chưa tồn tại, một tệp mới sẽ được tạo với metadata và mẫu ModelCard hoặc DatasetCard mặc định. Đối với repo `space`, một lỗi sẽ được ném ra vì Space không thể tồn tại mà không có tệp `README.md`.

Ví dụ:
```python
>>> 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)

```

