|
33 | 33 | "# Conversational Text Annotation Import\n", |
34 | 34 | "* This notebook will provide examples of each supported annotation type for conversational text assets, and also cover MAL and Label Import methods:\n", |
35 | 35 | "\n", |
36 | | - "Suported annotations that can be uploaded through the SDK\n", |
| 36 | + "Supported annotations that can be uploaded through the SDK\n", |
37 | 37 | "\n", |
38 | 38 | "* Classification Radio \n", |
39 | 39 | "* Classification Checklist \n", |
40 | 40 | "* Classification Free Text \n", |
41 | 41 | "* NER\n", |
42 | | - "* Relationships (only supported for MAL imports)\n", |
| 42 | + "\n", |
43 | 43 | "\n", |
44 | 44 | "**Not** supported annotations\n", |
45 | 45 | "\n", |
| 46 | + "* Relationships\n", |
46 | 47 | "* Bouding box \n", |
47 | 48 | "* Polygon \n", |
48 | 49 | "* Point\n", |
|
139 | 140 | " )\n", |
140 | 141 | ")\n", |
141 | 142 | "\n", |
142 | | - "ner_annotation_ndjson = { \n", |
| 143 | + "ner_annotation_ndjson = {\n", |
143 | 144 | " \"name\": \"ner\",\n", |
144 | | - " \"location\": { \n", |
145 | | - " \"start\": 0, \n", |
146 | | - " \"end\": 8 \n", |
| 145 | + " \"location\": {\n", |
| 146 | + " \"start\": 0,\n", |
| 147 | + " \"end\": 8\n", |
147 | 148 | " },\n", |
148 | 149 | " \"messageId\": \"4\"\n", |
149 | 150 | " }" |
|
177 | 178 | { |
178 | 179 | "metadata": {}, |
179 | 180 | "source": [ |
180 | | - "##### Checklist Classification ####### \n", |
| 181 | + "##### Checklist Classification #######\n", |
181 | 182 | "\n", |
182 | 183 | "checklist_annotation= lb_types.ClassificationAnnotation(\n", |
183 | 184 | " name=\"checklist_convo\", # must match your ontology feature\"s name\n", |
184 | 185 | " value=lb_types.Checklist(\n", |
185 | 186 | " answer = [\n", |
186 | 187 | " lb_types.ClassificationAnswer(\n", |
187 | 188 | " name = \"first_checklist_answer\"\n", |
188 | | - " ), \n", |
| 189 | + " ),\n", |
189 | 190 | " lb_types.ClassificationAnswer(\n", |
190 | 191 | " name = \"second_checklist_answer\"\n", |
191 | 192 | " )\n", |
|
214 | 215 | "######## Radio Classification ######\n", |
215 | 216 | "\n", |
216 | 217 | "radio_annotation = lb_types.ClassificationAnnotation(\n", |
217 | | - " name=\"radio_convo\", \n", |
| 218 | + " name=\"radio_convo\",\n", |
218 | 219 | " value=lb_types.Radio(answer = lb_types.ClassificationAnswer(name = \"first_radio_answer\")),\n", |
219 | 220 | " message_id=\"0\"\n", |
220 | 221 | ")\n", |
|
231 | 232 | "outputs": [], |
232 | 233 | "execution_count": null |
233 | 234 | }, |
234 | | - { |
235 | | - "metadata": {}, |
236 | | - "source": [ |
237 | | - "####### Relationships ########## \n", |
238 | | - "ner_source = lb_types.ObjectAnnotation(\n", |
239 | | - " name=\"ner\",\n", |
240 | | - " value=lb_types.ConversationEntity(\n", |
241 | | - " start=16,\n", |
242 | | - " end=26,\n", |
243 | | - " message_id=\"4\"\n", |
244 | | - " )\n", |
245 | | - ")\n", |
246 | | - "ner_target = lb_types.ObjectAnnotation(\n", |
247 | | - " name=\"ner\",\n", |
248 | | - " value=lb_types.ConversationEntity(\n", |
249 | | - " start=29, \n", |
250 | | - " end=34, \n", |
251 | | - " message_id=\"4\"\n", |
252 | | - " )\n", |
253 | | - ")\n", |
254 | | - "\n", |
255 | | - "ner_relationship = lb_types.RelationshipAnnotation(\n", |
256 | | - " name=\"relationship\",\n", |
257 | | - " value=lb_types.Relationship(\n", |
258 | | - " source=ner_source,\n", |
259 | | - " target=ner_target,\n", |
260 | | - " type=lb_types.Relationship.Type.UNIDIRECTIONAL,\n", |
261 | | - " ))\n", |
262 | | - "\n", |
263 | | - "uuid_source = str(uuid.uuid4())\n", |
264 | | - "uuid_target = str(uuid.uuid4())\n", |
265 | | - "\n", |
266 | | - "ner_source_ndjson = { \n", |
267 | | - " \"uuid\": uuid_source, \n", |
268 | | - " \"name\": \"ner\",\n", |
269 | | - " \"location\": { \n", |
270 | | - " \"start\": 16, \n", |
271 | | - " \"end\": 26 \n", |
272 | | - " },\n", |
273 | | - " \"messageId\": \"4\"\n", |
274 | | - " }\n", |
275 | | - "\n", |
276 | | - "ner_target_ndjson = { \n", |
277 | | - " \"uuid\": uuid_target,\n", |
278 | | - " \"name\": \"ner\",\n", |
279 | | - " \"location\": { \n", |
280 | | - " \"start\": 29, \n", |
281 | | - " \"end\": 34\n", |
282 | | - " },\n", |
283 | | - " \"messageId\": \"4\"\n", |
284 | | - " }\n", |
285 | | - "\n", |
286 | | - "ner_relationship_annotation_ndjson = {\n", |
287 | | - " \"name\": \"relationship\", \n", |
288 | | - " \"relationship\": {\n", |
289 | | - " \"source\": uuid_source,\n", |
290 | | - " \"target\": uuid_target,\n", |
291 | | - " \"type\": \"bidirectional\"\n", |
292 | | - " }\n", |
293 | | - "}" |
294 | | - ], |
295 | | - "cell_type": "code", |
296 | | - "outputs": [], |
297 | | - "execution_count": null |
298 | | - }, |
299 | 235 | { |
300 | 236 | "metadata": {}, |
301 | 237 | "source": [ |
|
328 | 264 | " \"name\": \"first_checklist_answer\",\n", |
329 | 265 | " \"classifications\" : [\n", |
330 | 266 | " {\n", |
331 | | - " \"name\": \"sub_checklist_question\", \n", |
| 267 | + " \"name\": \"sub_checklist_question\",\n", |
332 | 268 | " \"answer\": {\n", |
333 | 269 | " \"name\": \"first_sub_checklist_answer\"\n", |
334 | 270 | " }\n", |
335 | | - " } \n", |
336 | | - " ] \n", |
| 271 | + " }\n", |
| 272 | + " ]\n", |
337 | 273 | " }]\n", |
338 | 274 | "}\n", |
339 | 275 | "# Global\n", |
|
424 | 360 | "metadata": {}, |
425 | 361 | "source": [ |
426 | 362 | "ontology_builder = lb.OntologyBuilder(\n", |
427 | | - " tools=[ \n", |
| 363 | + " tools=[\n", |
428 | 364 | " lb.Tool(tool=lb.Tool.Type.NER,name=\"ner\"),\n", |
429 | | - " lb.Tool(tool=lb.Tool.Type.RELATIONSHIP,name=\"relationship\")\n", |
430 | | - " ], \n", |
431 | | - " classifications=[ \n", |
432 | | - " lb.Classification( \n", |
| 365 | + " ],\n", |
| 366 | + " classifications=[\n", |
| 367 | + " lb.Classification(\n", |
433 | 368 | " class_type=lb.Classification.Type.TEXT,\n", |
434 | | - " scope=lb.Classification.Scope.INDEX, \n", |
435 | | - " name=\"text_convo\"), \n", |
436 | | - " lb.Classification( \n", |
437 | | - " class_type=lb.Classification.Type.CHECKLIST, \n", |
438 | | - " scope=lb.Classification.Scope.INDEX, \n", |
439 | | - " name=\"checklist_convo\", \n", |
| 369 | + " scope=lb.Classification.Scope.INDEX,\n", |
| 370 | + " name=\"text_convo\"),\n", |
| 371 | + " lb.Classification(\n", |
| 372 | + " class_type=lb.Classification.Type.CHECKLIST,\n", |
| 373 | + " scope=lb.Classification.Scope.INDEX,\n", |
| 374 | + " name=\"checklist_convo\",\n", |
440 | 375 | " options=[\n", |
441 | 376 | " lb.Option(value=\"first_checklist_answer\"),\n", |
442 | | - " lb.Option(value=\"second_checklist_answer\") \n", |
| 377 | + " lb.Option(value=\"second_checklist_answer\")\n", |
443 | 378 | " ]\n", |
444 | | - " ), \n", |
445 | | - " lb.Classification( \n", |
446 | | - " class_type=lb.Classification.Type.RADIO, \n", |
447 | | - " name=\"radio_convo\", \n", |
448 | | - " scope=lb.Classification.Scope.INDEX, \n", |
| 379 | + " ),\n", |
| 380 | + " lb.Classification(\n", |
| 381 | + " class_type=lb.Classification.Type.RADIO,\n", |
| 382 | + " name=\"radio_convo\",\n", |
| 383 | + " scope=lb.Classification.Scope.INDEX,\n", |
449 | 384 | " options=[\n", |
450 | 385 | " lb.Option(value=\"first_radio_answer\"),\n", |
451 | 386 | " lb.Option(value=\"second_radio_answer\")\n", |
|
460 | 395 | " options=[\n", |
461 | 396 | " lb.Classification(\n", |
462 | 397 | " class_type=lb.Classification.Type.CHECKLIST,\n", |
463 | | - " name=\"sub_checklist_question\", \n", |
| 398 | + " name=\"sub_checklist_question\",\n", |
464 | 399 | " options=[lb.Option(\"first_sub_checklist_answer\")]\n", |
465 | 400 | " )\n", |
466 | 401 | " ])\n", |
|
503 | 438 | "metadata": {}, |
504 | 439 | "source": [ |
505 | 440 | "# Create Labelbox project\n", |
506 | | - "project = client.create_project(name=\"Conversational Text Annotation Import Demo\", \n", |
| 441 | + "project = client.create_project(name=\"Conversational Text Annotation Import Demo\",\n", |
507 | 442 | " media_type=lb.MediaType.Conversational)\n", |
508 | 443 | "\n", |
509 | | - "# Setup your ontology \n", |
| 444 | + "# Setup your ontology\n", |
510 | 445 | "project.setup_editor(ontology) # Connect your ontology and editor to your project" |
511 | 446 | ], |
512 | 447 | "cell_type": "code", |
|
523 | 458 | { |
524 | 459 | "metadata": {}, |
525 | 460 | "source": [ |
526 | | - "# Setup Batches and Ontology\n", |
527 | | - "\n", |
528 | 461 | "# Create a batch to send to your MAL project\n", |
529 | 462 | "batch = project.create_batch(\n", |
530 | 463 | " \"first-batch-convo-demo\", # Each batch in a project must have a unique name\n", |
|
570 | 503 | " text_annotation,\n", |
571 | 504 | " checklist_annotation,\n", |
572 | 505 | " radio_annotation,\n", |
573 | | - " ner_source,\n", |
574 | | - " ner_target,\n", |
575 | | - " ner_relationship,\n", |
576 | 506 | " nested_radio_annotation,\n", |
577 | 507 | " nested_checklist_annotation\n", |
578 | 508 | " ]\n", |
|
600 | 530 | " text_annotation_ndjson,\n", |
601 | 531 | " checklist_annotation_ndjson,\n", |
602 | 532 | " radio_annotation_ndjson,\n", |
603 | | - " ner_source_ndjson,\n", |
604 | | - " ner_target_ndjson,\n", |
605 | | - " ner_relationship_annotation_ndjson,\n", |
606 | 533 | " nested_checklist_annotation_ndjson,\n", |
607 | 534 | " nested_radio_annotation_ndjson\n", |
608 | 535 | " ]:\n", |
|
637 | 564 | "source": [ |
638 | 565 | "# Upload our label using Model-Assisted Labeling\n", |
639 | 566 | "upload_job = lb.MALPredictionImport.create_from_objects(\n", |
640 | | - " client = client, \n", |
641 | | - " project_id = project.uid, \n", |
642 | | - " name=f\"mal_job-{str(uuid.uuid4())}\", \n", |
| 567 | + " client = client,\n", |
| 568 | + " project_id = project.uid,\n", |
| 569 | + " name=f\"mal_job-{str(uuid.uuid4())}\",\n", |
643 | 570 | " predictions=label)\n", |
644 | 571 | "\n", |
645 | 572 | "upload_job.wait_until_done()\n", |
|
660 | 587 | { |
661 | 588 | "metadata": {}, |
662 | 589 | "source": [ |
663 | | - "# Upload label for this data row in project \n", |
664 | | - "# Uncomment this code when excluding relationships from label import\n", |
665 | | - "# Relationships are not currently supported for label import\n", |
| 590 | + "# Upload label for this data row in project\n", |
| 591 | + "upload_job = lb.LabelImport.create_from_objects(\n", |
| 592 | + " client = client,\n", |
| 593 | + " project_id = project.uid,\n", |
| 594 | + " name=\"label_import_job\"+str(uuid.uuid4()),\n", |
| 595 | + " labels=label)\n", |
666 | 596 | "\n", |
667 | | - "\n", |
668 | | - "# upload_job = lb.LabelImport.create_from_objects(\n", |
669 | | - "# client = client, \n", |
670 | | - "# project_id = project.uid, \n", |
671 | | - "# name=\"label_import_job\"+str(uuid.uuid4()), \n", |
672 | | - "# labels=label)\n", |
673 | | - "\n", |
674 | | - "# upload_job.wait_until_done();\n", |
675 | | - "# print(\"Errors:\", upload_job.errors)\n", |
676 | | - "# print(\"Status of uploads: \", upload_job.statuses)" |
| 597 | + "upload_job.wait_until_done()\n", |
| 598 | + "print(\"Errors:\", upload_job.errors)\n", |
| 599 | + "print(\"Status of uploads: \", upload_job.statuses)" |
677 | 600 | ], |
678 | 601 | "cell_type": "code", |
679 | 602 | "outputs": [], |
|
0 commit comments