{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "ed2ddd96-57f3-452e-9d28-e44654edbb65", "metadata": {}, "outputs": [], "source": [ "from huggingface_hub import DatasetFilter, list_datasets, HfApi, ModelFilter, DatasetSearchArguments\n", "from pathlib import Path\n", "from dotenv import load_dotenv\n", "import os\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "c45ae63c-4e02-47e3-a3e9-895a7bc2702d", "metadata": {}, "outputs": [], "source": [ "if Path(\".env\").is_file():\n", " load_dotenv(\".env\")\n", "\n", "auth_token = os.getenv(\"HF_HUB_TOKEN\")" ] }, { "cell_type": "code", "execution_count": 7, "id": "23e088a3-276a-45bf-9373-4dfe934b5556", "metadata": {}, "outputs": [], "source": [ "filt = DatasetFilter(benchmark=\"raft\")\n", "submissions = list_datasets(filter=filt, full=True, use_auth_token=auth_token)" ] }, { "cell_type": "code", "execution_count": 8, "id": "641c4060", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[0;31mSignature:\u001b[0m\n", "\u001b[0mlist_datasets\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mfilter\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mhuggingface_hub\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mutils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mendpoint_helpers\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDatasetFilter\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mIterable\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mNoneType\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mauthor\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mNoneType\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0msearch\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mNoneType\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0msort\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'lastModified'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mNoneType\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mdirection\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mLiteral\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mNoneType\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mlimit\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mNoneType\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mcardData\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mbool\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mNoneType\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mfull\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mbool\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mNoneType\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0muse_auth_token\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mNoneType\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mList\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mhuggingface_hub\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhf_api\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDatasetInfo\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mDocstring:\u001b[0m\n", "Get the public list of all the datasets on huggingface.co\n", "\n", "Args:\n", " filter ([`DatasetFilter`] or `str` or `Iterable`, *optional*):\n", " A string or [`DatasetFilter`] which can be used to identify\n", " datasets on the hub.\n", " author (`str`, *optional*):\n", " A string which identify the author of the returned models\n", " search (`str`, *optional*):\n", " A string that will be contained in the returned models.\n", " sort (`Literal[\"lastModified\"]` or `str`, *optional*):\n", " The key with which to sort the resulting datasets. Possible\n", " values are the properties of the [`huggingface_hub.hf_api.DatasetInfo`] class.\n", " direction (`Literal[-1]` or `int`, *optional*):\n", " Direction in which to sort. The value `-1` sorts by descending\n", " order while all other values sort by ascending order.\n", " limit (`int`, *optional*):\n", " The limit on the number of datasets fetched. Leaving this option\n", " to `None` fetches all datasets.\n", " cardData (`bool`, *optional*):\n", " Whether to grab the metadata for the dataset as well. Can\n", " contain useful information such as the PapersWithCode ID.\n", " full (`bool`, *optional*):\n", " Whether to fetch all dataset data, including the `lastModified`\n", " and the `cardData`.\n", " use_auth_token (`bool` or `str`, *optional*):\n", " Whether to use the `auth_token` provided from the\n", " `huggingface_hub` cli. If not logged in, a valid `auth_token`\n", " can be passed in as a string.\n", "\n", "Example usage with the `filter` argument:\n", "\n", "```python\n", ">>> from huggingface_hub import HfApi\n", "\n", ">>> api = HfApi()\n", "\n", ">>> # List all datasets\n", ">>> api.list_datasets()\n", "\n", ">>> # Get all valid search arguments\n", ">>> args = DatasetSearchArguments()\n", "\n", ">>> # List only the text classification datasets\n", ">>> api.list_datasets(filter=\"task_categories:text-classification\")\n", ">>> # Using the `DatasetFilter`\n", ">>> filt = DatasetFilter(task_categories=\"text-classification\")\n", ">>> # With `DatasetSearchArguments`\n", ">>> filt = DatasetFilter(task=args.task_categories.text_classification)\n", ">>> api.list_models(filter=filt)\n", "\n", ">>> # List only the datasets in russian for language modeling\n", ">>> api.list_datasets(\n", "... filter=(\"languages:ru\", \"task_ids:language-modeling\")\n", "... )\n", ">>> # Using the `DatasetFilter`\n", ">>> filt = DatasetFilter(languages=\"ru\", task_ids=\"language-modeling\")\n", ">>> # With `DatasetSearchArguments`\n", ">>> filt = DatasetFilter(\n", "... languages=args.languages.ru,\n", "... task_ids=args.task_ids.language_modeling,\n", "... )\n", ">>> api.list_datasets(filter=filt)\n", "```\n", "\n", "Example usage with the `search` argument:\n", "\n", "```python\n", ">>> from huggingface_hub import HfApi\n", "\n", ">>> api = HfApi()\n", "\n", ">>> # List all datasets with \"text\" in their name\n", ">>> api.list_datasets(search=\"text\")\n", "\n", ">>> # List all datasets with \"text\" in their name made by google\n", ">>> api.list_datasets(search=\"text\", author=\"google\")\n", "```\n", "\u001b[0;31mFile:\u001b[0m ~/miniconda3/envs/raft-leaderboard/lib/python3.8/site-packages/huggingface_hub/hf_api.py\n", "\u001b[0;31mType:\u001b[0m method\n" ] } ], "source": [ "?list_datasets" ] }, { "cell_type": "code", "execution_count": 9, "id": "228750aa-6d92-4d26-971f-5248e056f54b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(submissions)" ] }, { "cell_type": "code", "execution_count": 11, "id": "6dc34fa3-be44-4170-8daf-39f87aae5b34", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "benchmark\n", "type\n", "submission_name\n" ] } ], "source": [ "for k,v in submissions[3].cardData.items():\n", " print(k)" ] }, { "cell_type": "code", "execution_count": 12, "id": "f4dd2dbc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "DatasetInfo: {\n", "\tid: moshew/my_raft\n", "\tsha: 534086adc3aec801687316b3fe162e4231ab0a6b\n", "\tlastModified: 2022-07-16T17:01:04.000Z\n", "\ttags: ['benchmark:raft']\n", "\tprivate: False\n", "\tauthor: moshew\n", "\tdescription: \n", "\tcitation: @InProceedings{huggingface:dataset,\n", "title = {A great new dataset},\n", "author={huggingface, Inc.\n", "},\n", "year={2020}\n", "}\n", "\tcardData: {'benchmark': 'raft', 'type': 'prediction', 'submission_name': 'SetFit300'}\n", "\tsiblings: None\n", "\t_id: 621ffdd236468d709f183ac3\n", "\tdisabled: False\n", "\tgated: auto\n", "\tgitalyUid: 0d29a8b3b8364fb2d86b3ad56d62ea4aaf13a5cf95884aa0381b966d79b045e1\n", "\tlikes: 0\n", "\tdownloads: 0\n", "}" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "submissions[0]" ] }, { "cell_type": "code", "execution_count": null, "id": "27079f0b", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "raft-leaderboard", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.15" } }, "nbformat": 4, "nbformat_minor": 5 }