Skip to content

Commit

Permalink
Merge pull request #116 from doccano/enhancement/add-score-field-to-e…
Browse files Browse the repository at this point in the history
…xample-model

Add score field to example model
  • Loading branch information
Hironsan authored Oct 23, 2022
2 parents 396e86b + 37644b1 commit 2334454
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion doccano_client/cli/active_learning/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 6 additions & 4 deletions doccano_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,34 +561,36 @@ 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.
Args:
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.
Expand Down
1 change: 1 addition & 0 deletions doccano_client/models/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ class Example(BaseModel):
is_confirmed: bool = False
filename: str = ""
upload_name: str = ""
score: float = 100
7 changes: 6 additions & 1 deletion doccano_client/usecase/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,31 @@ def create(
self,
project_id: int,
text: str,
score: float = 100.0,
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
meta (Dict[str, Any]): The meta data of the example
Returns:
Example: The created example
"""
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(
self,
project_id: int,
example_id: int,
text: str = None,
score: float = None,
meta: Dict[str, Any] = None,
) -> Example:
"""Update a example
Expand All @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit 2334454

Please sign in to comment.