Skip to content

Commit 2d2377a

Browse files
committed
Add example to list the data rows in a batch
1 parent 0197e0a commit 2d2377a

File tree

1 file changed

+101
-91
lines changed

1 file changed

+101
-91
lines changed

examples/basics/batches.ipynb

Lines changed: 101 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@
3232
},
3333
{
3434
"cell_type": "markdown",
35-
"source": [
36-
"## Batches (*Currently in Public Beta*)"
37-
],
35+
"id": "Lup2QNWjaxKg",
3836
"metadata": {
3937
"id": "Lup2QNWjaxKg"
4038
},
41-
"id": "Lup2QNWjaxKg"
39+
"source": [
40+
"## Batches (*Currently in Public Beta*)"
41+
]
4242
},
4343
{
4444
"cell_type": "markdown",
45+
"id": "KONWmRQkadPf",
46+
"metadata": {
47+
"id": "KONWmRQkadPf"
48+
},
4549
"source": [
4650
"* A Batch is collection of datarows picked out of a Data Set.\n",
4751
"* A Datarow cannot be part of more than one batch in a project.\n",
@@ -50,59 +54,55 @@
5054
"* Batches may have Datarows from multiple Datasets.\n",
5155
"* Datarows can only be attached to a Project as part of a single Batch.\n",
5256
"* You can set priority for each Batch."
53-
],
54-
"metadata": {
55-
"id": "KONWmRQkadPf"
56-
},
57-
"id": "KONWmRQkadPf"
57+
]
5858
},
5959
{
6060
"cell_type": "code",
6161
"execution_count": null,
62+
"id": "HoW5ypnyzpqb",
6263
"metadata": {
6364
"id": "HoW5ypnyzpqb"
6465
},
6566
"outputs": [],
6667
"source": [
6768
"!pip install labelbox[data]"
68-
],
69-
"id": "HoW5ypnyzpqb"
69+
]
7070
},
7171
{
7272
"cell_type": "code",
7373
"execution_count": null,
74+
"id": "6-Us9Gj1zpqc",
7475
"metadata": {
7576
"id": "6-Us9Gj1zpqc"
7677
},
7778
"outputs": [],
7879
"source": [
7980
"from labelbox import DataRow, Client\n",
8081
"import random"
81-
],
82-
"id": "6-Us9Gj1zpqc"
82+
]
8383
},
8484
{
8585
"cell_type": "markdown",
86+
"id": "qQiozm-dzpqd",
8687
"metadata": {
8788
"id": "qQiozm-dzpqd"
8889
},
8990
"source": [
9091
"Set the following cell with your data to run this notebook:"
91-
],
92-
"id": "qQiozm-dzpqd"
92+
]
9393
},
9494
{
9595
"cell_type": "code",
9696
"execution_count": null,
97+
"id": "84Zna5c0zpqd",
9798
"metadata": {
9899
"id": "84Zna5c0zpqd"
99100
},
100101
"outputs": [],
101102
"source": [
102103
"PROJECT_NAME = \"Batch Queue Demo\" #text project\n",
103104
"DATASET_NAME = \"Batch Queue Demo Data\""
104-
],
105-
"id": "84Zna5c0zpqd"
105+
]
106106
},
107107
{
108108
"cell_type": "markdown",
@@ -118,6 +118,7 @@
118118
{
119119
"cell_type": "code",
120120
"execution_count": null,
121+
"id": "Ge-dfNh-zpqe",
121122
"metadata": {
122123
"id": "Ge-dfNh-zpqe"
123124
},
@@ -126,12 +127,12 @@
126127
"# Add your api key\n",
127128
"API_KEY = None\n",
128129
"client = Client(api_key=API_KEY)"
129-
],
130-
"id": "Ge-dfNh-zpqe"
130+
]
131131
},
132132
{
133133
"cell_type": "code",
134134
"execution_count": null,
135+
"id": "nMVtBYQmzpqe",
135136
"metadata": {
136137
"id": "nMVtBYQmzpqe"
137138
},
@@ -146,161 +147,175 @@
146147
" 'row_data': 'https://picsum.photos/200/300'\n",
147148
" })\n",
148149
"dataset.create_data_rows(uploads)"
149-
],
150-
"id": "nMVtBYQmzpqe"
150+
]
151151
},
152152
{
153153
"cell_type": "markdown",
154-
"source": [
155-
"# Ensure project is in batch mode:"
156-
],
154+
"id": "61CvCD3C7qv6",
157155
"metadata": {
158156
"id": "61CvCD3C7qv6"
159157
},
160-
"id": "61CvCD3C7qv6"
158+
"source": [
159+
"# Ensure project is in batch mode:"
160+
]
161161
},
162162
{
163163
"cell_type": "code",
164-
"source": [
165-
"project = client.create_project(name=PROJECT_NAME)\n",
166-
"project.update(queue_mode=project.QueueMode.Batch)"
167-
],
164+
"execution_count": null,
165+
"id": "tqtT4q31787T",
168166
"metadata": {
169167
"id": "tqtT4q31787T"
170168
},
171-
"id": "tqtT4q31787T",
172-
"execution_count": null,
173-
"outputs": []
169+
"outputs": [],
170+
"source": [
171+
"project = client.create_project(name=PROJECT_NAME)\n",
172+
"project.update(queue_mode=project.QueueMode.Batch)"
173+
]
174174
},
175175
{
176176
"cell_type": "markdown",
177-
"source": [
178-
"# Collect Datarow id's:"
179-
],
177+
"id": "Xti9AoZWELrq",
180178
"metadata": {
181179
"id": "Xti9AoZWELrq"
182180
},
183-
"id": "Xti9AoZWELrq"
181+
"source": [
182+
"# Collect Datarow id's:"
183+
]
184184
},
185185
{
186186
"cell_type": "markdown",
187-
"source": [
188-
"### Select All Data Rows from dataset."
189-
],
187+
"id": "9JVLsXdevywS",
190188
"metadata": {
191189
"id": "9JVLsXdevywS"
192190
},
193-
"id": "9JVLsXdevywS"
191+
"source": [
192+
"### Select All Data Rows from dataset."
193+
]
194194
},
195195
{
196196
"cell_type": "code",
197-
"source": [
198-
"data_rows = [dr.uid for dr in list(dataset.export_data_rows())]"
199-
],
197+
"execution_count": null,
198+
"id": "U4C1ZyJ2EgTS",
200199
"metadata": {
201200
"id": "U4C1ZyJ2EgTS"
202201
},
203-
"id": "U4C1ZyJ2EgTS",
204-
"execution_count": null,
205-
"outputs": []
202+
"outputs": [],
203+
"source": [
204+
"data_rows = [dr.uid for dr in list(dataset.export_data_rows())]"
205+
]
206206
},
207207
{
208208
"cell_type": "markdown",
209+
"id": "B0UqO_O1V8ei",
210+
"metadata": {
211+
"id": "B0UqO_O1V8ei"
212+
},
209213
"source": [
210214
"### Randomly sample\n",
211215
"\n",
212216
"Rather than selecting all of the data we sample 5 data rows at random"
213-
],
214-
"metadata": {
215-
"id": "B0UqO_O1V8ei"
216-
},
217-
"id": "B0UqO_O1V8ei"
217+
]
218218
},
219219
{
220220
"cell_type": "code",
221-
"source": [
222-
"sample = random.sample(data_rows, 5)"
223-
],
221+
"execution_count": null,
222+
"id": "WJAXBf1bV-td",
224223
"metadata": {
225224
"id": "WJAXBf1bV-td"
226225
},
227-
"id": "WJAXBf1bV-td",
228-
"execution_count": null,
229-
"outputs": []
226+
"outputs": [],
227+
"source": [
228+
"sample = random.sample(data_rows, 5)"
229+
]
230230
},
231231
{
232232
"cell_type": "markdown",
233-
"source": [
234-
"# Batch Manipulation"
235-
],
233+
"id": "UPdaTqkgYyvt",
236234
"metadata": {
237235
"id": "UPdaTqkgYyvt"
238236
},
239-
"id": "UPdaTqkgYyvt"
237+
"source": [
238+
"# Batch Manipulation"
239+
]
240240
},
241241
{
242242
"cell_type": "markdown",
243-
"source": [
244-
"### Create a Batch:"
245-
],
243+
"id": "Al-K1lBBEjtb",
246244
"metadata": {
247245
"id": "Al-K1lBBEjtb"
248246
},
249-
"id": "Al-K1lBBEjtb"
247+
"source": [
248+
"### Create a Batch:"
249+
]
250250
},
251251
{
252252
"cell_type": "code",
253+
"execution_count": null,
254+
"id": "resH3xqeErVv",
255+
"metadata": {
256+
"id": "resH3xqeErVv"
257+
},
258+
"outputs": [],
253259
"source": [
254260
"batch = project.create_batch(\n",
255261
" \"first batch\", # Each batch in a project must have a unique name\n",
256262
" sample, # A list of data rows or data row ids\n",
257263
" 5 # priority between 1(Highest) - 5(lowest)\n",
258264
")"
259-
],
260-
"metadata": {
261-
"id": "resH3xqeErVv"
262-
},
263-
"id": "resH3xqeErVv",
264-
"execution_count": null,
265-
"outputs": []
265+
]
266266
},
267267
{
268268
"cell_type": "code",
269-
"source": [
270-
"# number of data rows in the batch\n",
271-
"batch.size"
272-
],
269+
"execution_count": null,
270+
"id": "gFio7ONOWYdJ",
273271
"metadata": {
274272
"id": "gFio7ONOWYdJ"
275273
},
276-
"id": "gFio7ONOWYdJ",
277-
"execution_count": null,
278-
"outputs": []
274+
"outputs": [],
275+
"source": [
276+
"# number of data rows in the batch\n",
277+
"batch.size"
278+
]
279279
},
280280
{
281281
"cell_type": "markdown",
282+
"id": "8Cj64Isxzpqe",
282283
"metadata": {
283284
"id": "8Cj64Isxzpqe"
284285
},
285286
"source": [
286-
"### List DataRows in a Batch (Not supported yet)\n",
287-
"Note: You can view your batch through in the Data Row table of the project"
288-
],
289-
"id": "8Cj64Isxzpqe"
287+
"### List DataRows in a Batch\n",
288+
"Note: You can view your batch through in the *Data Row tab* of the project"
289+
]
290+
},
291+
{
292+
"cell_type": "code",
293+
"execution_count": null,
294+
"id": "0a7d1d3e",
295+
"metadata": {},
296+
"outputs": [],
297+
"source": [
298+
"data_rows = [dr for dr in batch.export_data_rows()]"
299+
]
290300
},
291301
{
292302
"cell_type": "markdown",
303+
"id": "rU7iddSQzpqg",
293304
"metadata": {
294305
"id": "rU7iddSQzpqg"
295306
},
296307
"source": [
297308
"### Remove queued data rows by batch (Not supported yet)\n",
298309
"Note: You can do this through the batch management pane on the data rows tab of the project"
299-
],
300-
"id": "rU7iddSQzpqg"
310+
]
301311
}
302312
],
303313
"metadata": {
314+
"colab": {
315+
"collapsed_sections": [],
316+
"name": "Batches.ipynb",
317+
"provenance": []
318+
},
304319
"kernelspec": {
305320
"display_name": "Python 3",
306321
"language": "python",
@@ -317,13 +332,8 @@
317332
"nbconvert_exporter": "python",
318333
"pygments_lexer": "ipython3",
319334
"version": "3.8.5"
320-
},
321-
"colab": {
322-
"name": "Batches.ipynb",
323-
"provenance": [],
324-
"collapsed_sections": []
325335
}
326336
},
327337
"nbformat": 4,
328338
"nbformat_minor": 5
329-
}
339+
}

0 commit comments

Comments
 (0)