Skip to content
Snippets Groups Projects

Replace all transcription scores with confidences

Merged ml bonhomme requested to merge no-more-score into master
3 files
+ 138
128
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -18,7 +18,11 @@ class TextOrientation(Enum):
class TranscriptionMixin(object):
def create_transcription(
self, element, text, score, orientation=TextOrientation.HorizontalLeftToRight
self,
element,
text,
confidence,
orientation=TextOrientation.HorizontalLeftToRight,
):
"""
Create a transcription on the given element through the API.
@@ -33,8 +37,8 @@ class TranscriptionMixin(object):
orientation, TextOrientation
), "orientation shouldn't be null and should be of type TextOrientation"
assert (
isinstance(score, float) and 0 <= score <= 1
), "score shouldn't be null and should be a float in [0..1] range"
isinstance(confidence, float) and 0 <= confidence <= 1
), "confidence shouldn't be null and should be a float in [0..1] range"
if self.is_read_only:
logger.warning(
@@ -48,7 +52,7 @@ class TranscriptionMixin(object):
body={
"text": text,
"worker_version": self.worker_version_id,
"score": score,
"confidence": confidence,
"orientation": orientation.value,
},
)
@@ -99,10 +103,12 @@ class TranscriptionMixin(object):
text, str
), f"Transcription at index {index} in transcriptions: text shouldn't be null and should be of type str"
score = transcription.get("score")
confidence = transcription.get("confidence")
assert (
score is not None and isinstance(score, float) and 0 <= score <= 1
), f"Transcription at index {index} in transcriptions: score shouldn't be null and should be a float in [0..1] range"
confidence is not None
and isinstance(confidence, float)
and 0 <= confidence <= 1
), f"Transcription at index {index} in transcriptions: confidence shouldn't be null and should be a float in [0..1] range"
orientation = transcription.get(
"orientation", TextOrientation.HorizontalLeftToRight
@@ -169,10 +175,12 @@ class TranscriptionMixin(object):
text, str
), f"Transcription at index {index} in transcriptions: text shouldn't be null and should be of type str"
score = transcription.get("score")
confidence = transcription.get("confidence")
assert (
score is not None and isinstance(score, float) and 0 <= score <= 1
), f"Transcription at index {index} in transcriptions: score shouldn't be null and should be a float in [0..1] range"
confidence is not None
and isinstance(confidence, float)
and 0 <= confidence <= 1
), f"Transcription at index {index} in transcriptions: confidence shouldn't be null and should be a float in [0..1] range"
orientation = transcription.get(
"orientation", TextOrientation.HorizontalLeftToRight
@@ -255,7 +263,7 @@ class TranscriptionMixin(object):
"id": annotation["id"],
"element_id": annotation["element_id"],
"text": transcription["text"],
"confidence": transcription["score"],
"confidence": transcription["confidence"],
"orientation": transcription.get(
"orientation", TextOrientation.HorizontalLeftToRight
).value,
Loading