Hugging Face's logo
加入 Hugging Face 社区

并获取增强的文档体验

开始使用

门控数据集

为了更好地控制数据集的使用方式,Hub 允许数据集作者为其数据集启用访问请求。用户必须同意与数据集作者分享其联系信息(用户名和电子邮件地址),以便在启用时访问数据集文件。数据集作者可以使用其他字段配置此请求。启用了访问请求的数据集称为门控数据集。访问请求始终授予个人用户,而不是整个组织。门控数据集的常见用例是在更广泛的发布之前提供对早期研究数据集的访问。

作为数据集作者管理门控数据集

要启用访问请求,请转到数据集设置页面。默认情况下,数据集未被门控。单击右上角的启用访问请求

默认情况下,当用户请求访问数据集时,会自动授予其访问权限。这被称为自动批准。在此模式下,任何用户在与您共享其个人信息后都可以访问您的数据集。

如果您想手动批准哪些用户可以访问您的数据集,则必须将其设置为手动批准。在这种情况下,您会注意到更多选项

  • 添加访问权限 允许您搜索用户并授予他们访问权限,即使他们没有请求访问。
  • 通知频率 让您配置在新用户请求访问时何时收到通知。可以设置为每天一次或实时。默认情况下,电子邮件会发送到您的主要电子邮件地址。对于组织托管的数据集,电子邮件默认发送给组织的前 5 名管理员。在这两种情况下(用户或组织),您都可以在通知电子邮件字段中设置不同的电子邮件地址。

审核访问请求

启用访问请求后,无论审批模式是手动还是自动,您都可以完全控制谁可以访问您的数据集。您可以从 UI 或通过 API 审核和管理请求。

从 UI

您可以从数据集的设置页面审核谁有权访问您的门控数据集,方法是单击审核访问请求按钮。这将打开一个模态框,其中包含 3 个用户列表

  • 待处理:等待批准访问您的数据集的用户列表。除非您选择了手动批准,否则此列表为空。您可以接受拒绝该请求。如果请求被拒绝,用户将无法访问您的数据集,也无法再次请求访问。
  • 已接受:有权访问您的数据集的用户的完整列表。您可以选择随时拒绝任何用户的访问权限,无论审批模式是手动还是自动。您也可以取消批准,这将把用户移动到待处理列表。
  • 已拒绝:您手动拒绝的用户列表。这些用户无法访问您的数据集。如果他们访问您的数据集仓库,他们将看到一条消息您访问此仓库的请求已被仓库作者拒绝

通过 API

您可以使用 API 自动化访问请求的批准。您必须传递一个带有对门控仓库的 write 访问权限的 token。要生成令牌,请转到您的用户设置

方法 URI 描述 标头 载荷
GET /api/datasets/{repo_id}/user-access-request/pending 检索待处理请求的列表。 {"authorization": "Bearer $token"}
GET /api/datasets/{repo_id}/user-access-request/accepted 检索已接受请求的列表。 {"authorization": "Bearer $token"}
GET /api/datasets/{repo_id}/user-access-request/rejected 检索已拒绝请求的列表。 {"authorization": "Bearer $token"}
POST /api/datasets/{repo_id}/user-access-request/handle 将给定访问请求的状态更改为 status {"authorization": "Bearer $token"} {"status": "accepted"/"rejected"/"pending", "user": "username", "rejectionReason": "可选的拒绝理由,用户可见(最多 200 个字符)。"}}
POST /api/datasets/{repo_id}/user-access-request/grant 允许特定用户访问您的仓库。 {"authorization": "Bearer $token"} {"user": "username"}

上述 HTTP 终端节点的基本 URL 是 https://huggingface.co

新功能! 这些终端节点现在在我们的 Python 客户端 huggingface_hub 中得到正式支持。使用 list_pending_access_requestslist_accepted_access_requestslist_rejected_access_requests 列出对您数据集的访问请求。您还可以使用 accept_access_requestcancel_access_requestreject_access_request 接受、取消和拒绝访问请求。最后,您可以使用 grant_access 授予用户访问权限。

下载访问报告

您可以使用下载用户访问报告按钮下载门控数据集的所有访问请求的报告。单击它以下载包含用户列表的 json 文件。对于每个条目,您都有

  • 用户:用户 ID。示例:julien-c
  • 全名:Hub 上用户的姓名。示例:Julien Chaumond
  • 状态:请求的状态。可以是 "pending""accepted""rejected"
  • 电子邮件:用户的电子邮件。
  • 时间:用户最初发出请求的日期时间。

Agree and send request to access repo button.

If you want to request more user information to provide access, you can configure additional fields. This information will be accessible from the Settings tab. To do so, add an extra_gated_fields property to your dataset card metadata containing a list of key/value pairs. The key is the name of the field and value its type or an object with a type field. The list of field types is

  • text: a single-line text field.
  • checkbox: a checkbox field.
  • date_picker: a date picker field.
  • country: a country dropdown. The list of countries is based on the ISO 3166-1 alpha-2 standard.
  • select: a dropdown with a list of options. The list of options is defined in the options field. Example: options: ["option 1", "option 2", {label: "option3", value: "opt3"}].

Finally, you can also personalize the message displayed to the user with the extra_gated_prompt extra field.

Here is an example of customized request form where the user is asked to provide their company name and country and acknowledge that the dataset is for non-commercial use only.

---
extra_gated_prompt: "You agree to not use the dataset to conduct experiments that cause harm to human subjects."
extra_gated_fields:
  Company: text
  Country: country
  Specific date: date_picker
  I want to use this dataset for:
    type: select
    options: 
      - Research
      - Education
      - label: Other
        value: other
  I agree to use this dataset for non-commercial use ONLY: checkbox
---

In some cases, you might also want to modify the default text in the gate heading, description, and button. For those use cases, you can modify extra_gated_heading, extra_gated_description and extra_gated_button_content like this

---
extra_gated_heading: "Acknowledge license to accept the repository"
extra_gated_description: "Our team may take 2-3 days to process your request"
extra_gated_button_content: "Acknowledge license"
---

Manage gated datasets as an organization (Enterprise Hub)

Enterprise Hub subscribers can create a Gating Group Collection to grant (or reject) access to all the models and datasets in a collection at once.

More information about Gating Group Collections can be found in our dedicated doc.

Access gated datasets as a user

As a user, if you want to use a gated dataset, you will need to request access to it. This means that you must be logged in to a Hugging Face user account.

Requesting access can only be done from your browser. Go to the dataset on the Hub and you will be prompted to share your information

By clicking on Agree, you agree to share your username and email address with the dataset authors. In some cases, additional fields might be requested. To help the dataset authors decide whether to grant you access, try to fill out the form as completely as possible.

Once the access request is sent, there are two possibilities. If the approval mechanism is automatic, you immediately get access to the dataset files. Otherwise, the requests have to be approved manually by the authors, which can take more time.

The dataset authors have complete control over dataset access. In particular, they can decide at any time to block your access to the dataset without prior notice, regardless of approval mechanism or if your request has already been approved.

下载文件

要从受限数据集下载文件,您需要进行身份验证。在浏览器中,如果您已使用帐户登录,则此操作是自动的。如果您正在使用脚本,您将需要提供用户令牌。在 Hugging Face Python 生态系统(transformersdiffusersdatasets 等)中,您可以使用 huggingface_hub 库并在终端中运行以下命令来登录您的机器

huggingface-cli login

或者,您可以在 notebook 或脚本中使用 login() 以编程方式登录

>>> from huggingface_hub import login
>>> login()

您还可以直接从脚本向库中的大多数加载方法(from_pretrainedhf_hub_downloadload_dataset 等)提供 token 参数。

有关如何登录的更多详细信息,请查看登录指南

< > 在 GitHub 上更新