Skip to content

Commit 64bbf71

Browse files
authored
[AL-4858] Update example notebook imports
2 parents 13703c4 + 1782da3 commit 64bbf71

36 files changed

+615
-660
lines changed

examples/annotation_import/conversational.ipynb

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
"cell_type": "code",
8181
"outputs": [
8282
{
83-
"output_type": "stream",
8483
"name": "stdout",
84+
"output_type": "stream",
8585
"text": [
8686
"\u001b[K |\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 185 kB 29.6 MB/s \n",
8787
"\u001b[K |\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 7.8 MB 53.9 MB/s \n",
@@ -101,11 +101,8 @@
101101
{
102102
"metadata": {},
103103
"source": [
104-
"from labelbox.schema.ontology import OntologyBuilder, Tool, Classification, Option\n",
105-
"from labelbox import Client, LabelingFrontend, MALPredictionImport, LabelImport\n",
106-
"from labelbox.schema.media_type import MediaType\n",
107-
"import uuid\n",
108-
"import json"
104+
"import labelbox as lb\n",
105+
"import uuid"
109106
],
110107
"cell_type": "code",
111108
"outputs": [],
@@ -124,7 +121,7 @@
124121
"source": [
125122
"# Add your api key\n",
126123
"API_KEY = None\n",
127-
"client = Client(api_key=API_KEY)"
124+
"client = lb.Client(api_key=API_KEY)"
128125
],
129126
"cell_type": "code",
130127
"outputs": [],
@@ -218,8 +215,8 @@
218215
"cell_type": "code",
219216
"outputs": [
220217
{
221-
"output_type": "stream",
222218
"name": "stdout",
219+
"output_type": "stream",
223220
"text": [
224221
"<DataRow {\n",
225222
" \"created_at\": \"2022-12-23 20:18:48+00:00\",\n",
@@ -251,32 +248,32 @@
251248
{
252249
"metadata": {},
253250
"source": [
254-
"ontology_builder = OntologyBuilder(\n",
251+
"ontology_builder = lb.OntologyBuilder(\n",
255252
" tools=[ \n",
256-
" Tool( # NER tool given the name \"ner\"\n",
257-
" tool=Tool.Type.NER, \n",
253+
" lb.Tool( # NER tool given the name \"ner\"\n",
254+
" tool=lb.Tool.Type.NER, \n",
258255
" name=\"ner\")], \n",
259256
" classifications=[ \n",
260-
" Classification( # Text classification given the name \"text\"\n",
261-
" class_type=Classification.Type.TEXT,\n",
262-
" scope=Classification.Scope.INDEX, \n",
257+
" lb.Classification( # Text classification given the name \"text\"\n",
258+
" class_type=lb.Classification.Type.TEXT,\n",
259+
" scope=lb.Classification.Scope.INDEX, \n",
263260
" instructions=\"text_convo\"), \n",
264-
" Classification( # Checklist classification given the name \"text\" with two options: \"first_checklist_answer\" and \"second_checklist_answer\"\n",
265-
" class_type=Classification.Type.CHECKLIST, \n",
266-
" scope=Classification.Scope.INDEX, \n",
261+
" lb.Classification( # Checklist classification given the name \"text\" with two options: \"first_checklist_answer\" and \"second_checklist_answer\"\n",
262+
" class_type=lb.Classification.Type.CHECKLIST, \n",
263+
" scope=lb.Classification.Scope.INDEX, \n",
267264
" instructions=\"checklist_convo\", \n",
268265
" options=[\n",
269-
" Option(value=\"first_checklist_answer\"),\n",
270-
" Option(value=\"second_checklist_answer\") \n",
266+
" lb.Option(value=\"first_checklist_answer\"),\n",
267+
" lb.Option(value=\"second_checklist_answer\") \n",
271268
" ]\n",
272269
" ), \n",
273-
" Classification( # Radio classification given the name \"text\" with two options: \"first_radio_answer\" and \"second_radio_answer\"\n",
274-
" class_type=Classification.Type.RADIO, \n",
270+
" lb.Classification( # Radio classification given the name \"text\" with two options: \"first_radio_answer\" and \"second_radio_answer\"\n",
271+
" class_type=lb.Classification.Type.RADIO, \n",
275272
" instructions=\"radio_convo\", \n",
276-
" scope=Classification.Scope.INDEX, \n",
273+
" scope=lb.Classification.Scope.INDEX, \n",
277274
" options=[\n",
278-
" Option(value=\"first_radio_answer\"),\n",
279-
" Option(value=\"second_radio_answer\")\n",
275+
" lb.Option(value=\"first_radio_answer\"),\n",
276+
" lb.Option(value=\"second_radio_answer\")\n",
280277
" ]\n",
281278
" )\n",
282279
" ]\n",
@@ -300,18 +297,18 @@
300297
"source": [
301298
"# Create Labelbox project\n",
302299
"project = client.create_project(name=\"conversational_mal_project\", \n",
303-
" media_type=MediaType.Conversational)\n",
300+
" media_type=lb.MediaType.Conversational)\n",
304301
"\n",
305302
"# Setup your ontology / labeling editor\n",
306-
"editor = next(client.get_labeling_frontends(where=LabelingFrontend.name == \"Editor\")) # Unless using a custom editor, do not modify this\n",
303+
"editor = next(client.get_labeling_frontends(where=lb.LabelingFrontend.name == \"Editor\")) # Unless using a custom editor, do not modify this\n",
307304
"\n",
308305
"project.setup(editor, ontology_builder.asdict()) # Connect your ontology and editor to your project\n"
309306
],
310307
"cell_type": "code",
311308
"outputs": [
312309
{
313-
"output_type": "stream",
314310
"name": "stderr",
311+
"output_type": "stream",
315312
"text": [
316313
"WARNING:labelbox.client:Default createProject behavior will soon be adjusted to prefer batch projects. Pass in `queue_mode` parameter explicitly to opt-out for the time being.\n"
317314
]
@@ -343,8 +340,8 @@
343340
"cell_type": "code",
344341
"outputs": [
345342
{
346-
"output_type": "stream",
347343
"name": "stdout",
344+
"output_type": "stream",
348345
"text": [
349346
"Batch: <Batch {\n",
350347
" \"consensus_settings_json\": \"{\\\"numberOfLabels\\\":1,\\\"coveragePercentage\\\":0}\",\n",
@@ -405,7 +402,6 @@
405402
"cell_type": "code",
406403
"outputs": [
407404
{
408-
"output_type": "execute_result",
409405
"data": {
410406
"text/plain": [
411407
"[{'name': 'ner',\n",
@@ -431,8 +427,9 @@
431427
" 'dataRow': {'id': 'clc0ygvde029307yn96gv2byu'}}]"
432428
]
433429
},
430+
"execution_count": 13,
434431
"metadata": {},
435-
"execution_count": 13
432+
"output_type": "execute_result"
436433
}
437434
],
438435
"execution_count": null
@@ -456,7 +453,7 @@
456453
"metadata": {},
457454
"source": [
458455
"# Upload our label using Model-Assisted Labeling\n",
459-
"upload_job = MALPredictionImport.create_from_objects(\n",
456+
"upload_job = lb.MALPredictionImport.create_from_objects(\n",
460457
" client = client, \n",
461458
" project_id = project.uid, \n",
462459
" name=f\"mal_job-{str(uuid.uuid4())}\", \n",
@@ -469,8 +466,8 @@
469466
"cell_type": "code",
470467
"outputs": [
471468
{
472-
"output_type": "stream",
473469
"name": "stdout",
470+
"output_type": "stream",
474471
"text": [
475472
"Errors: []\n",
476473
" \n"
@@ -487,7 +484,6 @@
487484
"cell_type": "code",
488485
"outputs": [
489486
{
490-
"output_type": "execute_result",
491487
"data": {
492488
"text/plain": [
493489
"[{'name': 'ner', 'location': {'start': 0, 'end': 8}, 'messageId': '4'},\n",
@@ -509,8 +505,9 @@
509505
" 'messageId': '0'}]"
510506
]
511507
},
508+
"execution_count": 45,
512509
"metadata": {},
513-
"execution_count": 45
510+
"output_type": "execute_result"
514511
}
515512
],
516513
"execution_count": null
@@ -526,7 +523,7 @@
526523
"metadata": {},
527524
"source": [
528525
"# Upload label for this data row in project \n",
529-
"upload_job = LabelImport.create_from_objects(\n",
526+
"upload_job = lb.LabelImport.create_from_objects(\n",
530527
" client = client, \n",
531528
" project_id = project.uid, \n",
532529
" name=\"label_geo_import_job\"+str(uuid.uuid4()), \n",
@@ -539,8 +536,8 @@
539536
"cell_type": "code",
540537
"outputs": [
541538
{
542-
"output_type": "stream",
543539
"name": "stdout",
540+
"output_type": "stream",
544541
"text": [
545542
"Errors: []\n"
546543
]

examples/annotation_import/image.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
"import labelbox as lb\n",
8787
"import labelbox.data.annotation_types as lb_types\n",
8888
"import labelbox.data.serialization as lb_serializers\n",
89-
"import labelbox.schema.queue_mode as lb_queue_mode\n",
9089
"import uuid\n",
9190
"import numpy as np\n"
9291
],
@@ -164,7 +163,6 @@
164163
"}\n",
165164
"\n",
166165
"\n",
167-
"\n",
168166
"nested_checklist_annotation_ndjson = {\n",
169167
" \"name\": \"nested_checklist_question\",\n",
170168
" \"answer\": [{\n",
@@ -658,7 +656,7 @@
658656
"project = client.create_project(\n",
659657
" name=\"annotations_import_project_demo\",\n",
660658
" media_type=lb.MediaType.Image,\n",
661-
" queue_mode=lb_queue_mode.QueueMode.Batch)\n",
659+
" queue_mode=lb.QueueMode.Batch)\n",
662660
"\n",
663661
"project.setup_editor(ontology) # Connect your ontology and editor to your MAL project"
664662
],

examples/annotation_import/pdf.ipynb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,8 @@
6161
{
6262
"metadata": {},
6363
"source": [
64-
"from labelbox.schema.ontology import OntologyBuilder, Tool, Classification, Option\n",
65-
"from labelbox import Client, LabelingFrontend, MALPredictionImport\n",
66-
"from labelbox.data.annotation_types import (\n",
67-
" Label, ImageData, ObjectAnnotation, \n",
68-
" Rectangle, Point,\n",
69-
" Radio, Checklist, Text,\n",
70-
" ClassificationAnnotation, ClassificationAnswer\n",
71-
")\n",
72-
"from labelbox.schema.media_type import MediaType\n",
64+
"import labelbox as lb\n",
65+
"import labelbox.types as lb_types\n",
7366
"import uuid\n",
7467
"from uuid import uuid4\n",
7568
"import json"
@@ -91,7 +84,7 @@
9184
"source": [
9285
"# Add your api key\n",
9386
"API_KEY = None\n",
94-
"client = Client(api_key=API_KEY)"
87+
"client = lb.Client(api_key=API_KEY)"
9588
],
9689
"cell_type": "code",
9790
"outputs": [],
@@ -128,10 +121,10 @@
128121
"metadata": {},
129122
"source": [
130123
"tool_name = \"super\"\n",
131-
"ontology_builder = OntologyBuilder(\n",
124+
"ontology_builder = lb.OntologyBuilder(\n",
132125
" tools=[ \n",
133-
" Tool( # Entity tool given the name \"NER\"\n",
134-
" tool=Tool.Type.NER, \n",
126+
" lb.Tool( # Entity tool given the name \"NER\"\n",
127+
" tool=lb.Tool.Type.NER, \n",
135128
" name= tool_name)]\n",
136129
" )"
137130
],
@@ -152,7 +145,7 @@
152145
"metadata": {},
153146
"source": [
154147
"# Create Labelbox project\n",
155-
"mal_project = client.create_project(name=\"pdf_entity_import\", media_type=MediaType.Document)\n",
148+
"mal_project = client.create_project(name=\"pdf_entity_import\", media_type=lb.MediaType.Document)\n",
156149
"\n",
157150
"# Create one Labelbox dataset\n",
158151
"dataset = client.create_dataset(name=\"pdf_entity_import_dataset\")\n",
@@ -243,7 +236,7 @@
243236
{
244237
"metadata": {},
245238
"source": [
246-
"task = MALPredictionImport.create_from_objects(client, mal_project.uid, str(uuid.uuid4()), [ANNOTATION])"
239+
"task = lb.MALPredictionImport.create_from_objects(client, mal_project.uid, str(uuid.uuid4()), [ANNOTATION])"
247240
],
248241
"cell_type": "code",
249242
"outputs": [],

0 commit comments

Comments
 (0)