Skip to content

Commit

Permalink
Clamp confidence scores to [0, 1]
Browse files Browse the repository at this point in the history
  • Loading branch information
TimKoornstra committed Mar 19, 2024
1 parent 7ff7c91 commit 6f593e5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def decode_batch_predictions(pred, utils, greedy=True, beam_width=1, num_oov_ind
confidence = np.exp(-log_prob)
else:
confidence = np.exp(log_prob)

i = i + 1
# print(confidence)
res = res + num_oov_indices
Expand Down Expand Up @@ -207,6 +208,10 @@ def normalize_confidence(confidence, predicted_text):
confidence = pow(confidence, (1 / len(predicted_text)))
if confidence < 0:
confidence = -confidence

if confidence < 0 or confidence > 1:
confidence = np.clip(confidence, 0, 1)

return confidence


Expand Down

0 comments on commit 6f593e5

Please sign in to comment.