Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New labeling config parser #187

Merged
merged 19 commits into from
Mar 5, 2024
Merged

feat: New labeling config parser #187

merged 19 commits into from
Mar 5, 2024

Conversation

deppp
Copy link

@deppp deppp commented Feb 26, 2024

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"] }
  }]
})

@deppp deppp changed the title New labeling config parser feat: New labeling config parser Feb 26, 2024
@deppp deppp requested a review from niklub February 26, 2024 17:54
@deppp deppp marked this pull request as ready for review March 4, 2024 00:56
Mikhail Maluyk and others added 6 commits March 4, 2024 00:56
Several additions were made to the control_tags, label_tags, and object_tags files.
These changes added extensive Python documentation strings to all classes and methods, providing a detailed explanation of each element's functionality, parameters, and returns.
Added type hints to all method parameters for better understanding and improved coding assistance.
Reformatted code to align with Python style guidelines with more consistent use of whitespace and line breaks.
Minor changes to some logic (replacing the _dict method with Python's built-in dict function; replacing string concatenation with f-string formatting, etc.).
@niklub niklub force-pushed the dev/config-parser branch from ecedc96 to ef5d7c8 Compare March 5, 2024 13:06
@deppp deppp requested a review from farioas as a code owner March 5, 2024 15:16
@niklub niklub merged commit 895d156 into master Mar 5, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants