Open In Colab Open this Colab for an interactive tutorial about how to import annotations on document data.

Supported annotations

To import annotations in Labelbox, you need to create the annotations payload. In this section, we provide this payload for every annotation type.

Labelbox support two formats for the annotations payload: Python Annotation types (recommended) and NDJSON. Both are described below.

Classification - radio (single-choice)

radio_annotation_ndjson = {
  'name': 'radio_question',
  'answer': {'name': 'second_radio_answer'}
}

Classification - checklist (multi-choice)

checklist_annotation_ndjson = {
  'name': 'checklist_question',
  'answer': [
    {'name': 'first_checklist_answer'},
    {'name': 'second_checklist_answer'}
  ]
}

Classification - free-form text

text_annotation_ndjson = {
  'name': 'free_text',
  'answer': 'sample text',
}

Bounding box

bbox_annotation = ObjectAnnotation(
  name = "bounding_box",  # must match your ontology feature's name
  value = Point(x=10, y=10),
)

bbox_with_radio_subclass_annotation = ObjectAnnotation(
    name="bounding_box_with_radio_subclass", # must match your ontology feature's name
    value=Rectangle(
        start=Point(x=0, y=0), # Top left
        end=Point(x=10, y=10), # Bottom right
    ),
    classifications=[
        ClassificationAnnotation(
            name="sub_radio_question",
            value=Radio(answer=ClassificationAnswer(name="first_sub_radio_answer"))
    )
  ]
)
bbox_annotation_ndjson = {
  'name': 'bounding_box',
  'classifications': [],
  'bbox': {'top': 0.0, 'left': 0.0, 'height': 10.0, 'width': 10.0}
}

bbox_with_radio_subclass_annotation_ndjson = {
  'name': 'bounding_box_with_radio_subclass',
  'classifications': [
    {
      'name': 'sub_radio_question',
      'answer': {'name': 'first_sub_radio_answer'}
    }
  ],
  'bbox': {'top': 0.0, 'left': 0.0, 'height': 10.0, 'width': 10.0}
}

Entity

textSelections is the payload for entity annotations. The required fields for each textSelections are the list of tokenIds for each entity, the groupId, and the page page (1-indexed).

ner_annotation_json = {
    "name" : tool_name,
    "textSelections": [
        {
            "tokenIds": [
                "521f705e-b276-4ac7-8e5b-2e38e037f80f",
            ],
            "groupId": "ed53dd86-ef39-4634-9505-ee0eebedef44",
            "page": 1,
        }
    ]
}