The new parser introduces an object-oriented interface for labeling configurations. It is designed to be compatible at the data structure level with an existing parser widely used within the Label Studio ecosystem. This ensures that it works seamlessly with most of the existing functions, either by directly supporting them or by offering re-implemented versions through the new interface.
Moreover, the parser adds significant value by offering functionality to validate predictions and annotations against the specified labeling configuration. Below is a simple example of how to use the new API:
from label_studio_sdk.label_interface import LabelInterface
from label_studio_sdk.label_interface.control_tags import ChoicesTag
config = """<View><Text name="txt" value="$val" /><Choices name="chc" toName="txt"><Choice value="one"/> <Choice value="two"/></Choices></View>"""
li = LabelInterface(config)
region = li.get_tag("chc").label("one")
## returns a JSON representing a Label Studio region
region.as_json()
## check if this config is a classification one (could have multiple classifications)
if len(li.find_tags_by_class(ChoicesTag)) == len(li.controls):
print("Simple classification")
## returns True
li.validate_prediction({
"model_version": "0.0.1",
"score": 0.90,
"result": [{
"from_name": "chc",
"to_name": "txt",
"type": "choices",
"value": { "choices": ["one"] }
}]
})
The new parser introduces an object-oriented interface for labeling configurations. It is designed to be compatible at the data structure level with an existing parser widely used within the Label Studio ecosystem. This ensures that it works seamlessly with most of the existing functions, either by directly supporting them or by offering re-implemented versions through the new interface.
Moreover, the parser adds significant value by offering functionality to validate predictions and annotations against the specified labeling configuration. Below is a simple example of how to use the new API: