Skip to content

Commit ce1187e

Browse files
authored
Final updates
1 parent c9e591f commit ce1187e

File tree

1 file changed

+45
-52
lines changed

1 file changed

+45
-52
lines changed

examples/annotation_import/text.ipynb

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -86,33 +86,19 @@
8686
},
8787
{
8888
"cell_type": "code",
89-
"execution_count": null,
89+
"execution_count": 36,
9090
"id": "4d63074b-2379-48af-b9d6-2a66190f03c4",
9191
"metadata": {
92-
"id": "4d63074b-2379-48af-b9d6-2a66190f03c4",
93-
"colab": {
94-
"base_uri": "https://localhost:8080/"
95-
},
96-
"outputId": "0b4547c9-e534-441d-9bf6-7588ee50c8a2"
92+
"id": "4d63074b-2379-48af-b9d6-2a66190f03c4"
9793
},
98-
"outputs": [
99-
{
100-
"output_type": "stream",
101-
"name": "stdout",
102-
"text": [
103-
"\u001b[K |████████████████████████████████| 184 kB 5.2 MB/s \n",
104-
"\u001b[K |████████████████████████████████| 7.8 MB 45.4 MB/s \n",
105-
"\u001b[?25h Building wheel for pygeotile (setup.py) ... \u001b[?25l\u001b[?25hdone\n"
106-
]
107-
}
108-
],
94+
"outputs": [],
10995
"source": [
11096
"!pip install -q 'labelbox[data]'"
11197
]
11298
},
11399
{
114100
"cell_type": "code",
115-
"execution_count": null,
101+
"execution_count": 37,
116102
"id": "01fca8c9-0680-4a9c-a11e-1b49f31e9121",
117103
"metadata": {
118104
"id": "01fca8c9-0680-4a9c-a11e-1b49f31e9121"
@@ -124,7 +110,7 @@
124110
"from labelbox.schema.queue_mode import QueueMode\n",
125111
"from labelbox.data.annotation_types import (\n",
126112
" Label, TextData, Checklist, Radio, ObjectAnnotation, TextEntity,\n",
127-
" ClassificationAnnotation, ClassificationAnswer, LabelList, Text \n",
113+
" ClassificationAnnotation, ClassificationAnswer, LabelList, Text, ImageData\n",
128114
")\n",
129115
"from labelbox.data.serialization import NDJsonConverter\n",
130116
"import uuid\n",
@@ -144,7 +130,7 @@
144130
},
145131
{
146132
"cell_type": "code",
147-
"execution_count": null,
133+
"execution_count": 38,
148134
"id": "86003724-4807-4281-95c1-5284a6f9609f",
149135
"metadata": {
150136
"id": "86003724-4807-4281-95c1-5284a6f9609f"
@@ -199,7 +185,7 @@
199185
"id": "Z5ORHD1pZKt1"
200186
},
201187
"id": "Z5ORHD1pZKt1",
202-
"execution_count": null,
188+
"execution_count": 39,
203189
"outputs": []
204190
},
205191
{
@@ -226,13 +212,13 @@
226212
"id": "mrPJ1Ko0ZMdl"
227213
},
228214
"id": "mrPJ1Ko0ZMdl",
229-
"execution_count": null,
215+
"execution_count": 40,
230216
"outputs": []
231217
},
232218
{
233219
"cell_type": "code",
234220
"source": [
235-
"########## Nested Classifications are only supported with NDJSON tools ##########\n",
221+
"########## Classification - Radio (with subclassifcations) is only suppported with NDJSON tools ##########\n",
236222
"\n",
237223
"# NDJSON\n",
238224
"radio_annotation_ndjson_with_subclass = {\n",
@@ -250,7 +236,7 @@
250236
"id": "vt7QvfV7ZPAF"
251237
},
252238
"id": "vt7QvfV7ZPAF",
253-
"execution_count": null,
239+
"execution_count": 41,
254240
"outputs": []
255241
},
256242
{
@@ -283,12 +269,12 @@
283269
"id": "45BDh768ZYsH"
284270
},
285271
"id": "45BDh768ZYsH",
286-
"execution_count": null,
272+
"execution_count": 42,
287273
"outputs": []
288274
},
289275
{
290276
"cell_type": "code",
291-
"execution_count": null,
277+
"execution_count": 43,
292278
"id": "f9f9287c-aad7-4914-bc87-1453fb8bce81",
293279
"metadata": {
294280
"id": "f9f9287c-aad7-4914-bc87-1453fb8bce81"
@@ -351,27 +337,27 @@
351337
"base_uri": "https://localhost:8080/"
352338
},
353339
"id": "Ak-jnABK3OPH",
354-
"outputId": "ff481cce-af08-4748-e8ac-a959085e07de"
340+
"outputId": "0f80ba52-adde-4d97-d04a-fcdbe4d1a414"
355341
},
356342
"id": "Ak-jnABK3OPH",
357-
"execution_count": null,
343+
"execution_count": 44,
358344
"outputs": [
359345
{
360346
"output_type": "stream",
361347
"name": "stdout",
362348
"text": [
363349
"<DataRow {\n",
364-
" \"created_at\": \"2022-12-22 20:59:28+00:00\",\n",
350+
" \"created_at\": \"2023-01-30 18:06:23+00:00\",\n",
365351
" \"external_id\": null,\n",
366-
" \"global_key\": \"TEST-ID-190217471490724126308456269288159181446d\",\n",
352+
" \"global_key\": \"TEST-ID-321668750509639104503407808903937477958d\",\n",
367353
" \"media_attributes\": {},\n",
368354
" \"metadata\": [],\n",
369355
" \"metadata_fields\": [],\n",
370356
" \"row_data\": \"https://storage.googleapis.com/labelbox-sample-datasets/nlp/lorem-ipsum.txt\",\n",
371-
" \"uid\": \"clbzkhbxy18ws07ysdumbbgnq\",\n",
372-
" \"updated_at\": \"2022-12-22 20:59:28+00:00\"\n",
357+
" \"uid\": \"cldj4gyf60fy207xh3z1y2g1h\",\n",
358+
" \"updated_at\": \"2023-01-30 18:06:23+00:00\"\n",
373359
"}>\n",
374-
"clbzkhbxy18ws07ysdumbbgnq\n"
360+
"cldj4gyf60fy207xh3z1y2g1h\n"
375361
]
376362
}
377363
]
@@ -382,7 +368,7 @@
382368
"### Step 2: Create/select an ontology\n",
383369
"Your project should have the correct ontology setup with all the tools and classifications supported for your annotations, and the tool names and classification instructions should match the `name`/`instructions` fields in your annotations to ensure the correct feature schemas are matched.\n",
384370
"\n",
385-
"For example, when we create the checklist annotation [above](https://colab.research.google.com/drive/1mXfgydXxVR2OMAjJo1nj2EU9QQyVhW90#scrollTo=45BDh768ZYsH&line=1&uniqifier=1), we provided the `name` as `checklist_question`. Now, when we setup our ontology, we must ensure that the name of my classification tool is also `checklist_question`. The same alignment must hold true for the other tools and classifications we create in our ontology.\n",
371+
"For example, when we create the checklist annotation above, we provided the `name` as `checklist_question`. Now, when we setup our ontology, we must ensure that the name of my classification tool is also `checklist_question`. The same alignment must hold true for the other tools and classifications we create in our ontology.\n",
386372
"\n",
387373
"[Documentation for reference ](https://docs.labelbox.com/reference/import-text-annotations)"
388374
],
@@ -440,13 +426,13 @@
440426
" ]\n",
441427
")\n",
442428
"\n",
443-
"ontology = client.create_ontology(\"Ontology Text Annotations\", ontology_builder.asdict(), media_type=MediaType.Text)\n"
429+
"ontology = client.create_ontology(\"Ontology Text Annotations\", ontology_builder.asdict())\n"
444430
],
445431
"metadata": {
446432
"id": "_wWxYFoDTsar"
447433
},
448434
"id": "_wWxYFoDTsar",
449-
"execution_count": null,
435+
"execution_count": 45,
450436
"outputs": []
451437
},
452438
{
@@ -462,7 +448,7 @@
462448
},
463449
{
464450
"cell_type": "code",
465-
"execution_count": null,
451+
"execution_count": 46,
466452
"id": "044e9194-d21d-403e-b64c-047c1063b0fe",
467453
"metadata": {
468454
"id": "044e9194-d21d-403e-b64c-047c1063b0fe"
@@ -524,22 +510,22 @@
524510
"colab": {
525511
"base_uri": "https://localhost:8080/"
526512
},
527-
"outputId": "153857ae-455d-4c7c-fb36-40fc16dc0819"
513+
"outputId": "6eb66aad-477d-490e-ea91-53de995f1f65"
528514
},
529515
"id": "DbwheC8RzI-0",
530-
"execution_count": null,
516+
"execution_count": 47,
531517
"outputs": [
532518
{
533519
"output_type": "stream",
534520
"name": "stdout",
535521
"text": [
536522
"Batch: <Batch {\n",
537523
" \"consensus_settings_json\": \"{\\\"numberOfLabels\\\":1,\\\"coveragePercentage\\\":0}\",\n",
538-
" \"created_at\": \"2022-12-22 20:59:51+00:00\",\n",
524+
" \"created_at\": \"2023-01-30 18:06:28+00:00\",\n",
539525
" \"name\": \"first-batch-text-demo\",\n",
540526
" \"size\": 1,\n",
541-
" \"uid\": \"94297660-823b-11ed-8039-c1b641c04d88\",\n",
542-
" \"updated_at\": \"2022-12-22 20:59:51+00:00\"\n",
527+
" \"uid\": \"d14be9f0-a0c8-11ed-a7e5-f9da6146996d\",\n",
528+
" \"updated_at\": \"2023-01-30 18:06:28+00:00\"\n",
543529
"}>\n"
544530
]
545531
}
@@ -562,7 +548,7 @@
562548
{
563549
"cell_type": "markdown",
564550
"source": [
565-
"#### Python Annotations"
551+
"#### Python annotations"
566552
],
567553
"metadata": {
568554
"id": "7IgSl5SxcO4R"
@@ -571,7 +557,7 @@
571557
},
572558
{
573559
"cell_type": "code",
574-
"execution_count": null,
560+
"execution_count": 48,
575561
"id": "53aaf87b-114f-4b56-a417-8c7cddc1f532",
576562
"metadata": {
577563
"id": "53aaf87b-114f-4b56-a417-8c7cddc1f532"
@@ -580,17 +566,24 @@
580566
"source": [
581567
"# Create a Label\n",
582568
"label = Label(\n",
583-
" data=TextData(\n",
569+
" data=ImageData(\n",
584570
" uid=data_row.uid),\n",
585571
" annotations = [\n",
586572
" named_entitity_annotation, \n",
587573
" radio_annotation, \n",
588574
" checklist_annotation, \n",
589-
" text_annotation \n"
575+
" text_annotation\n",
590576
" ]\n",
591577
")\n",
592578
"\n",
593579
"\n",
580+
"# Create urls to mask data for upload\n",
581+
"def signing_function(obj_bytes: bytes) -> str:\n",
582+
" url = client.upload_data(content=obj_bytes, sign=True)\n",
583+
" return url \n",
584+
"\n",
585+
"label.add_url_to_masks(signing_function)\n",
586+
"\n",
594587
"# Convert our label from a Labelbox class object to the underlying NDJSON format required for upload \n",
595588
"label_ndjson = list(NDJsonConverter.serialize([label]))"
596589
]
@@ -607,7 +600,7 @@
607600
},
608601
{
609602
"cell_type": "code",
610-
"execution_count": null,
603+
"execution_count": 49,
611604
"id": "c66672c7-33e8-4d5d-b79d-2ac76d830341",
612605
"metadata": {
613606
"id": "c66672c7-33e8-4d5d-b79d-2ac76d830341"
@@ -672,10 +665,10 @@
672665
"base_uri": "https://localhost:8080/"
673666
},
674667
"id": "izli4zhEfi75",
675-
"outputId": "b1cdc2d0-9541-4df2-d922-be0a7ce80499"
668+
"outputId": "4eb1b790-4e60-4cc6-9224-de6a9ed339bf"
676669
},
677670
"id": "izli4zhEfi75",
678-
"execution_count": null,
671+
"execution_count": 50,
679672
"outputs": [
680673
{
681674
"output_type": "stream",
@@ -699,14 +692,14 @@
699692
},
700693
{
701694
"cell_type": "code",
702-
"execution_count": null,
695+
"execution_count": 51,
703696
"id": "e8d4e99b-ad7e-48b9-8073-afb764d7c5b4",
704697
"metadata": {
705698
"id": "e8d4e99b-ad7e-48b9-8073-afb764d7c5b4",
706699
"colab": {
707700
"base_uri": "https://localhost:8080/"
708701
},
709-
"outputId": "be9df775-f18c-44ed-e02e-82b3c2a3691f"
702+
"outputId": "1e52b23b-cefc-439b-f374-2e8b886280f4"
710703
},
711704
"outputs": [
712705
{
@@ -749,7 +742,7 @@
749742
"id": "ubbraAmo2_fe"
750743
},
751744
"id": "ubbraAmo2_fe",
752-
"execution_count": null,
745+
"execution_count": 52,
753746
"outputs": []
754747
}
755748
],

0 commit comments

Comments
 (0)