Skip to content

Annotators

Initialization of the ZenML annotator stack component.

BaseAnnotator

Bases: StackComponent, ABC

Base class for all ZenML annotators.

Source code in src/zenml/annotators/base_annotator.py
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
class BaseAnnotator(StackComponent, ABC):
    """Base class for all ZenML annotators."""

    @property
    def config(self) -> BaseAnnotatorConfig:
        """Returns the `BaseAnnotatorConfig` config.

        Returns:
            The configuration.
        """
        return cast(BaseAnnotatorConfig, self._config)

    @abstractmethod
    def get_url(self) -> str:
        """Gets the URL of the annotation interface.

        Returns:
            The URL of the annotation interface.
        """

    @abstractmethod
    def get_url_for_dataset(self, dataset_name: str) -> str:
        """Gets the URL of the annotation interface for a specific dataset.

        Args:
            dataset_name: name of the dataset.

        Returns:
            The URL of the dataset annotation interface.
        """

    @abstractmethod
    def get_datasets(self) -> List[Any]:
        """Gets the datasets currently available for annotation.

        Returns:
            The datasets currently available for annotation.
        """

    @abstractmethod
    def get_dataset_names(self) -> List[str]:
        """Gets the names of the datasets currently available for annotation.

        Returns:
            The names of the datasets currently available for annotation.
        """

    @abstractmethod
    def get_dataset_stats(self, dataset_name: str) -> Tuple[int, int]:
        """Gets the statistics of a dataset.

        Args:
            dataset_name: name of the dataset.

        Returns:
            A tuple containing (labeled_task_count, unlabeled_task_count) for
                the dataset.
        """

    @abstractmethod
    def launch(self, **kwargs: Any) -> None:
        """Launches the annotation interface.

        Args:
            **kwargs: Additional keyword arguments to pass to the
                annotation client.
        """

    @abstractmethod
    def add_dataset(self, **kwargs: Any) -> Any:
        """Registers a dataset for annotation.

        Args:
            **kwargs: keyword arguments.

        Returns:
            The dataset or confirmation object on adding the dataset.
        """

    @abstractmethod
    def get_dataset(self, **kwargs: Any) -> Any:
        """Gets the dataset with the given name.

        Args:
            **kwargs: keyword arguments.

        Returns:
            The dataset with the given name.
        """

    @abstractmethod
    def delete_dataset(self, **kwargs: Any) -> None:
        """Deletes a dataset.

        Args:
            **kwargs: keyword arguments.
        """

    @abstractmethod
    def get_labeled_data(self, **kwargs: Any) -> Any:
        """Gets the labeled data for the given dataset.

        Args:
            **kwargs: keyword arguments.

        Returns:
            The labeled data for the given dataset.
        """

    @abstractmethod
    def get_unlabeled_data(self, **kwargs: str) -> Any:
        """Gets the unlabeled data for the given dataset.

        Args:
            **kwargs: Additional keyword arguments to pass to the Label Studio client.

        Returns:
            The unlabeled data for the given dataset.
        """

config property

Returns the BaseAnnotatorConfig config.

Returns:

Type Description
BaseAnnotatorConfig

The configuration.

add_dataset(**kwargs) abstractmethod

Registers a dataset for annotation.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments.

{}

Returns:

Type Description
Any

The dataset or confirmation object on adding the dataset.

Source code in src/zenml/annotators/base_annotator.py
102
103
104
105
106
107
108
109
110
111
@abstractmethod
def add_dataset(self, **kwargs: Any) -> Any:
    """Registers a dataset for annotation.

    Args:
        **kwargs: keyword arguments.

    Returns:
        The dataset or confirmation object on adding the dataset.
    """

delete_dataset(**kwargs) abstractmethod

Deletes a dataset.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments.

{}
Source code in src/zenml/annotators/base_annotator.py
124
125
126
127
128
129
130
@abstractmethod
def delete_dataset(self, **kwargs: Any) -> None:
    """Deletes a dataset.

    Args:
        **kwargs: keyword arguments.
    """

get_dataset(**kwargs) abstractmethod

Gets the dataset with the given name.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments.

{}

Returns:

Type Description
Any

The dataset with the given name.

Source code in src/zenml/annotators/base_annotator.py
113
114
115
116
117
118
119
120
121
122
@abstractmethod
def get_dataset(self, **kwargs: Any) -> Any:
    """Gets the dataset with the given name.

    Args:
        **kwargs: keyword arguments.

    Returns:
        The dataset with the given name.
    """

get_dataset_names() abstractmethod

Gets the names of the datasets currently available for annotation.

Returns:

Type Description
List[str]

The names of the datasets currently available for annotation.

Source code in src/zenml/annotators/base_annotator.py
73
74
75
76
77
78
79
@abstractmethod
def get_dataset_names(self) -> List[str]:
    """Gets the names of the datasets currently available for annotation.

    Returns:
        The names of the datasets currently available for annotation.
    """

get_dataset_stats(dataset_name) abstractmethod

Gets the statistics of a dataset.

Parameters:

Name Type Description Default
dataset_name str

name of the dataset.

required

Returns:

Type Description
Tuple[int, int]

A tuple containing (labeled_task_count, unlabeled_task_count) for the dataset.

Source code in src/zenml/annotators/base_annotator.py
81
82
83
84
85
86
87
88
89
90
91
@abstractmethod
def get_dataset_stats(self, dataset_name: str) -> Tuple[int, int]:
    """Gets the statistics of a dataset.

    Args:
        dataset_name: name of the dataset.

    Returns:
        A tuple containing (labeled_task_count, unlabeled_task_count) for
            the dataset.
    """

get_datasets() abstractmethod

Gets the datasets currently available for annotation.

Returns:

Type Description
List[Any]

The datasets currently available for annotation.

Source code in src/zenml/annotators/base_annotator.py
65
66
67
68
69
70
71
@abstractmethod
def get_datasets(self) -> List[Any]:
    """Gets the datasets currently available for annotation.

    Returns:
        The datasets currently available for annotation.
    """

get_labeled_data(**kwargs) abstractmethod

Gets the labeled data for the given dataset.

Parameters:

Name Type Description Default
**kwargs Any

keyword arguments.

{}

Returns:

Type Description
Any

The labeled data for the given dataset.

Source code in src/zenml/annotators/base_annotator.py
132
133
134
135
136
137
138
139
140
141
@abstractmethod
def get_labeled_data(self, **kwargs: Any) -> Any:
    """Gets the labeled data for the given dataset.

    Args:
        **kwargs: keyword arguments.

    Returns:
        The labeled data for the given dataset.
    """

get_unlabeled_data(**kwargs) abstractmethod

Gets the unlabeled data for the given dataset.

Parameters:

Name Type Description Default
**kwargs str

Additional keyword arguments to pass to the Label Studio client.

{}

Returns:

Type Description
Any

The unlabeled data for the given dataset.

Source code in src/zenml/annotators/base_annotator.py
143
144
145
146
147
148
149
150
151
152
@abstractmethod
def get_unlabeled_data(self, **kwargs: str) -> Any:
    """Gets the unlabeled data for the given dataset.

    Args:
        **kwargs: Additional keyword arguments to pass to the Label Studio client.

    Returns:
        The unlabeled data for the given dataset.
    """

get_url() abstractmethod

Gets the URL of the annotation interface.

Returns:

Type Description
str

The URL of the annotation interface.

Source code in src/zenml/annotators/base_annotator.py
46
47
48
49
50
51
52
@abstractmethod
def get_url(self) -> str:
    """Gets the URL of the annotation interface.

    Returns:
        The URL of the annotation interface.
    """

get_url_for_dataset(dataset_name) abstractmethod

Gets the URL of the annotation interface for a specific dataset.

Parameters:

Name Type Description Default
dataset_name str

name of the dataset.

required

Returns:

Type Description
str

The URL of the dataset annotation interface.

Source code in src/zenml/annotators/base_annotator.py
54
55
56
57
58
59
60
61
62
63
@abstractmethod
def get_url_for_dataset(self, dataset_name: str) -> str:
    """Gets the URL of the annotation interface for a specific dataset.

    Args:
        dataset_name: name of the dataset.

    Returns:
        The URL of the dataset annotation interface.
    """

launch(**kwargs) abstractmethod

Launches the annotation interface.

Parameters:

Name Type Description Default
**kwargs Any

Additional keyword arguments to pass to the annotation client.

{}
Source code in src/zenml/annotators/base_annotator.py
 93
 94
 95
 96
 97
 98
 99
100
@abstractmethod
def launch(self, **kwargs: Any) -> None:
    """Launches the annotation interface.

    Args:
        **kwargs: Additional keyword arguments to pass to the
            annotation client.
    """