From 37644b193e463f6f7e852326edb49957e9547e5a Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 24 Oct 2022 08:32:05 +0900 Subject: [PATCH] Add score field to example model --- doccano_client/cli/active_learning/manager.py | 2 +- doccano_client/client.py | 10 ++++++---- doccano_client/models/example.py | 1 + doccano_client/usecase/example.py | 7 ++++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/doccano_client/cli/active_learning/manager.py b/doccano_client/cli/active_learning/manager.py index cbd494e..01972ee 100644 --- a/doccano_client/cli/active_learning/manager.py +++ b/doccano_client/cli/active_learning/manager.py @@ -67,6 +67,6 @@ def execute_active_learning( ) print("Update confidence scores...") for score, example_id in tqdm(zip(scores, example_ids)): - client.update_example(project_id, example_id, meta={"confidence": score}) + client.update_example(project_id, example_id, score=score) print("Update completed.") time.sleep(10) diff --git a/doccano_client/client.py b/doccano_client/client.py index 7af2361..af20b0b 100644 --- a/doccano_client/client.py +++ b/doccano_client/client.py @@ -561,21 +561,22 @@ def count_examples(self, project_id: int) -> int: """ return self.example.count(project_id) - def create_example(self, project_id: int, text: str, meta: Dict[str, Any] = None) -> Example: + def create_example(self, project_id: int, text: str, score: float = 100, meta: Dict[str, Any] = None) -> Example: """Create a new example. Args: project_id (int): The id of the project. text (str): The text of the example. + score (float): The confidence score of the example. Defaults to 100. meta (Dict[str, Any]): The meta data of the example. Returns: Example: The created example. """ - return self.example.create(project_id, text, meta) + return self.example.create(project_id, text, score, meta) def update_example( - self, project_id: int, example_id: int, text: str = None, meta: Dict[str, Any] = None + self, project_id: int, example_id: int, text: str = None, score: float = None, meta: Dict[str, Any] = None ) -> Example: """Update an example. @@ -583,12 +584,13 @@ def update_example( project_id (int): The id of the project. example_id (int): The id of the example. text (str): The text of the example. + score (float): The confidence score of the example. meta (Dict[str, Any]): The meta data of the example. Returns: Example: The updated example. """ - return self.example.update(project_id, example_id, text, meta) + return self.example.update(project_id, example_id, text, score, meta) def delete_example(self, project_id: int, example_id: int): """Delete an example. diff --git a/doccano_client/models/example.py b/doccano_client/models/example.py index 7906c8c..5df9488 100644 --- a/doccano_client/models/example.py +++ b/doccano_client/models/example.py @@ -14,3 +14,4 @@ class Example(BaseModel): is_confirmed: bool = False filename: str = "" upload_name: str = "" + score: float = 100 diff --git a/doccano_client/usecase/example.py b/doccano_client/usecase/example.py index e2d4c2c..a0a0b07 100644 --- a/doccano_client/usecase/example.py +++ b/doccano_client/usecase/example.py @@ -47,6 +47,7 @@ def create( self, project_id: int, text: str, + score: float = 100.0, meta: Dict[str, Any] = None, ) -> Example: """Create a new example @@ -54,6 +55,7 @@ def create( Args: project_id (int): The id of the project text (str): The text of the example + score (float): The confidence score of the example meta (Dict[str, Any]): The meta data of the example Returns: @@ -61,7 +63,7 @@ def create( """ if meta is None: meta = {} - example = Example(text=text, meta=meta) + example = Example(text=text, score=score, meta=meta) return self._repository.create(project_id, example) def update( @@ -69,6 +71,7 @@ def update( project_id: int, example_id: int, text: str = None, + score: float = None, meta: Dict[str, Any] = None, ) -> Example: """Update a example @@ -77,6 +80,7 @@ def update( project_id (int): The id of the project example_id (int): The id of the example text (str): The text of the example + score (float): The confidence score of the example meta (Dict[str, Any]): The meta data of the example Returns: @@ -86,6 +90,7 @@ def update( example = Example( id=example_id, text=text if text is not None else example.text, + score=score if score is not None else example.score, meta=meta if meta is not None else example.meta, ) return self._repository.update(project_id, example)