Skip to main content

Define a label tree

Tator supports definition of label trees, hierarchies of labels that are required in many classification tasks. In Tator, label trees are defined via Leaf objects, entities which can be assigned user defined attributes besides just a label and that also have foriegn keys to parents. This document will explain how to create a label tree in Tator using a tator-py example script, as well as how to associate that label tree to a custom attribute for use in the web interface's autocomplete function.

Define the label tree

In the tator-py source tree, a script at examples/ allows for definition a label tree via a yaml file. Start by creating a yaml file similar to the following or copy this source to a file called got.yaml:

name: GoT # The name of the hierarchy.
- name: Targaryen
- name: Maekar I
- name: Maester Aemon
- name: Aegon V
- name: Jaehaerys II
- name: Aerys II (Mad King)
- name: Daenerys
- name: Viserys
- name: Rhaegar
- name: Aegon
- name: Rhaelle
- name: Stark
- name: Rickard
- name: Brandon
- name: Eddard
- name: Robb
- name: Sansa
- name: Arya
- name: Brandon
- name: Rickon
- name: Benjen
- name: Lyanna
- name: Baratheon
- name: Ormund
- name: Steffon
- name: Robert
- name: Stannis
- name: Shireen
- name: Renly
- name: Lannister
- name: Tywin
- name: Jaime
- name: Cersei
- name: Joffrey
- name: Myrcella
- name: Tommen
- name: Tyrion

Next we need to create a LeafType object. This can be done in tator-py with the following:

import tator
api = tator.get_api(host='', token=MY_TOKEN)
leaf_spec = {
'name': 'leaves',
'description': 'Simple leaf type',
'attribute_types': [],
response = api.create_leaf_type(PROJECT_ID, leaf_type_spec=leaf_spec)
leaf_type_id =

We can now run the example script on the file and create the Leaf objects, passing in the leaf type ID for TYPE_ID:

python examples/ --host --token $MY_TOKEN --type_id TYPE_ID --input got.yaml

Set the autocomplete service

Once a label hierarchy is created, a suggestion service becomes available. The last element in the URI is based on the name of the hierarchy as defined by the root node, in this case GoT. The autocomplete service for the entire tree in this example is available at:{project_name}.GoT/{project}

The suggestion service can be scoped to a branch within the tree. For example, to make suggestions for only Lannisters, you can use:{project_name}.GoT.Lannister/{project}


Spaces, dashes, and parentheses in project_name must be replaced by underscores.

These suggestion services are documented in the REST API reference documentation.

Below is an example where a string attribute with name ATTRIBUTE_TYPE_NAME defined for a media type VIDEO_TYPE is associated with this service for autocompletion. Note that the attribute type could be associated with a localization type, state type, file type, or leaf type as well.

api = tator.get_api(host, token)
video_type_obj = api.get_media_type(VIDEO_TYPE)
project_obj = api.get_project(PROJECT_ID)
attribute_type = {}
for elem in video_type_obj.attribute_types:
attribute_type = elem
attribute_type.autocomplete = {'serviceUrl': f'/rest/Leaves/Suggestion/{}.GoT/{PROJECT_ID}'}
api.rename_attribute(VIDEO_TYPE, {
'entity_type': 'MediaType',
'global': 'true',
'old_attribute_type_name': ATTRIBUTE_TYPE_NAME,
'new_attribute_type': attribute_type,

Use autocomplete

Now users of the web interface who type at least three letters into the string field will see a suggestion list come up matching to all the leaves defined.