Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion src/rapidata/rapidata_client/selection/labeling_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,25 @@ class LabelingSelection(RapidataSelection):
max_iterations (int | None): An annotator can answer the same task only once if the retrieval_mode is "Shuffled"
or "Sequential". max_iterations can increase the amount of responses an annotator can do
to the same task (datapoint).
advance_on_view (bool): Move an annotator past a task as soon as it is shown, even without an answer,
so a skipped task is not served to them again. Requires "Shuffled" or "Sequential". Defaults to False.
"""

def __init__(
self,
amount: int,
retrieval_mode: RapidataRetrievalMode = RapidataRetrievalMode.Shuffled,
max_iterations: int | None = None,
advance_on_view: bool = False,
):
if advance_on_view and retrieval_mode == RapidataRetrievalMode.Random:
raise ValueError(
'advance_on_view requires the "Shuffled" or "Sequential" retrieval mode'
)
self.amount = amount
self.retrieval_mode = retrieval_mode
self.max_iterations = max_iterations
self.advance_on_view = advance_on_view

def _to_model(self):
from rapidata.api_client.models.i_selection import ISelection
Expand All @@ -41,11 +49,12 @@ def _to_model(self):
amount=self.amount,
retrievalMode=self.retrieval_mode.value,
maxIterations=self.max_iterations,
advanceOnView=self.advance_on_view,
)
)

def __str__(self) -> str:
return f"LabelingSelection(amount={self.amount}, retrieval_mode={self.retrieval_mode}, max_iterations={self.max_iterations})"
return f"LabelingSelection(amount={self.amount}, retrieval_mode={self.retrieval_mode}, max_iterations={self.max_iterations}, advance_on_view={self.advance_on_view})"

def __repr__(self) -> str:
return self.__str__()
Empty file.
32 changes: 32 additions & 0 deletions tests/rapidata_client/selection/test_labeling_selection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import annotations

import pytest

from rapidata.rapidata_client.selection.labeling_selection import LabelingSelection
from rapidata.rapidata_client.selection.rapidata_retrieval_modes import (
RapidataRetrievalMode,
)


@pytest.mark.parametrize(
"mode", [RapidataRetrievalMode.Shuffled, RapidataRetrievalMode.Sequential]
)
def test_advance_on_view_is_sent(mode: RapidataRetrievalMode) -> None:
model = LabelingSelection(amount=3, retrieval_mode=mode, advance_on_view=True)

assert model._to_model().to_dict()["advanceOnView"] is True


def test_advance_on_view_defaults_to_false() -> None:
model = LabelingSelection(amount=3)

assert model._to_model().to_dict()["advanceOnView"] is False


def test_advance_on_view_rejects_random() -> None:
with pytest.raises(ValueError, match="Shuffled"):
LabelingSelection(
amount=3,
retrieval_mode=RapidataRetrievalMode.Random,
advance_on_view=True,
)
Loading