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

[PTDT-2863]: Feature schema attributes #1930

Merged
merged 20 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libs/labelbox/src/labelbox/schema/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from labelbox.schema.tool_building.tool_type_mapping import (
map_tool_type_to_tool_cls,
)
from labelbox.schema.tool_building.types import FeatureSchemaAttributes


class DeleteFeatureFromOntologyResult:
Expand Down Expand Up @@ -73,6 +74,7 @@ class Tool:
classifications: (list)
schema_id: (str)
feature_schema_id: (str)
attributes: (list)
"""
Tim-Kerr marked this conversation as resolved.
Show resolved Hide resolved

class Type(Enum):
Expand All @@ -95,6 +97,7 @@ class Type(Enum):
classifications: List[Classification] = field(default_factory=list)
schema_id: Optional[str] = None
feature_schema_id: Optional[str] = None
attributes: Optional[FeatureSchemaAttributes] = None

@classmethod
def from_dict(cls, dictionary: Dict[str, Any]) -> Dict[str, Any]:
Expand All @@ -109,6 +112,7 @@ def from_dict(cls, dictionary: Dict[str, Any]) -> Dict[str, Any]:
for c in dictionary["classifications"]
],
color=dictionary["color"],
attributes=dictionary.get("attributes", None),
)

def asdict(self) -> Dict[str, Any]:
Expand All @@ -122,6 +126,7 @@ def asdict(self) -> Dict[str, Any]:
],
"schemaNodeId": self.schema_id,
"featureSchemaId": self.feature_schema_id,
"attributes": self.attributes,
}

def add_classification(self, classification: Classification) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

from lbox.exceptions import InconsistentOntologyException

from labelbox.schema.tool_building.types import FeatureSchemaId
from labelbox.schema.tool_building.types import (
FeatureSchemaId,
vbrodsky marked this conversation as resolved.
Show resolved Hide resolved
FeatureSchemaAttributes,
)


@dataclass
Expand Down Expand Up @@ -42,6 +45,7 @@ class Classification:
schema_id: (str)
feature_schema_id: (str)
scope: (str)
attributes: (list)
"""

class Type(Enum):
Expand Down Expand Up @@ -70,6 +74,7 @@ class UIMode(Enum):
ui_mode: Optional[UIMode] = (
None # How this classification should be answered (e.g. hotkeys / autocomplete, etc)
)
attributes: Optional[FeatureSchemaAttributes] = None

def __post_init__(self):
if self.name is None:
Expand All @@ -88,6 +93,10 @@ def __post_init__(self):
else:
if self.instructions is None:
self.instructions = self.name
if self.attributes is not None:
warnings.warn(
"Attributes are an experimental feature and may change in the future."
)

@classmethod
def from_dict(cls, dictionary: Dict[str, Any]) -> "Classification":
Expand All @@ -103,6 +112,7 @@ def from_dict(cls, dictionary: Dict[str, Any]) -> "Classification":
schema_id=dictionary.get("schemaNodeId", None),
feature_schema_id=dictionary.get("featureSchemaId", None),
scope=cls.Scope(dictionary.get("scope", cls.Scope.GLOBAL)),
attributes=dictionary.get("attributes", None),
)

def asdict(self, is_subclass: bool = False) -> Dict[str, Any]:
Expand All @@ -118,6 +128,9 @@ def asdict(self, is_subclass: bool = False) -> Dict[str, Any]:
"options": [o.asdict() for o in self.options],
"schemaNodeId": self.schema_id,
"featureSchemaId": self.feature_schema_id,
"attributes": self.attributes
if self.attributes is not None
else None,
}
if (
self.class_type == self.Type.RADIO
Expand Down
15 changes: 13 additions & 2 deletions libs/labelbox/src/labelbox/schema/tool_building/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
from typing import Annotated
from typing import Annotated, List
from pydantic import Field, BaseModel
from typing import TypedDict

from pydantic import Field

class FeatureSchemaAttribute(TypedDict):
attributeName: str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this into a data class? We already use Pydantic and dataclasses, so adding another paradigm feels unnecessary. Also, I’ve found TypedDict has quirks that make it less reliable. Personally, I treat it as a temporary internal type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

attributeValue: str


FeatureSchemaAttriubte = Annotated[FeatureSchemaAttribute, Field()]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FeatureSchemaAttriubte - typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ty, fixed

FeatureSchemaId = Annotated[str, Field(min_length=25, max_length=25)]
SchemaId = Annotated[str, Field(min_length=25, max_length=25)]
FeatureSchemaAttributes = Annotated[
List[FeatureSchemaAttribute], Field(default_factory=list)
vbrodsky marked this conversation as resolved.
Show resolved Hide resolved
]
10 changes: 10 additions & 0 deletions libs/labelbox/tests/unit/test_unit_ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"color": "#FF0000",
"tool": "polygon",
"classifications": [],
"attributes": None,
},
{
"schemaNodeId": None,
Expand All @@ -24,6 +25,7 @@
"color": "#FF0000",
"tool": "superpixel",
"classifications": [],
"attributes": None,
},
{
"schemaNodeId": None,
Expand All @@ -32,6 +34,7 @@
"name": "bbox",
"color": "#FF0000",
"tool": "rectangle",
"attributes": None,
"classifications": [
{
"schemaNodeId": None,
Expand All @@ -56,6 +59,7 @@
"name": "nested nested text",
"type": "text",
"options": [],
"attributes": None,
}
],
},
Expand All @@ -67,6 +71,7 @@
"options": [],
},
],
"attributes": None,
},
{
"schemaNodeId": None,
Expand All @@ -76,6 +81,7 @@
"name": "nested text",
"type": "text",
"options": [],
"attributes": None,
},
],
},
Expand All @@ -87,6 +93,7 @@
"color": "#FF0000",
"tool": "point",
"classifications": [],
"attributes": None,
},
{
"schemaNodeId": None,
Expand All @@ -96,6 +103,7 @@
"color": "#FF0000",
"tool": "line",
"classifications": [],
"attributes": None,
},
{
"schemaNodeId": None,
Expand All @@ -105,6 +113,7 @@
"color": "#FF0000",
"tool": "named-entity",
"classifications": [],
"attributes": None,
},
],
"classifications": [
Expand All @@ -117,6 +126,7 @@
"type": "radio",
"scope": "global",
"uiMode": "searchable",
"attributes": None,
"options": [
{
"schemaNodeId": None,
Expand Down
1 change: 1 addition & 0 deletions libs/labelbox/tests/unit/test_unit_prompt_issue_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_as_dict():
"schemaNodeId": None,
"featureSchemaId": None,
"scope": "global",
"attributes": None,
}
],
"color": None,
Expand Down
Loading