File size: 11,597 Bytes
06a86d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
{
 "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
}