Skip to content

Commit

Permalink
update to core 1.0.1 (with str confidence)
Browse files Browse the repository at this point in the history
  • Loading branch information
bertsky committed Oct 25, 2019
1 parent 8d47082 commit ab21b1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions ocrd_keraslm/wrapper/rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def process(self):
element.set_TextEquiv([textequiv]) # delete others
textequiv_len = len(textequiv.Unicode)
conf = sum(confidences[i:i+textequiv_len])/textequiv_len # mean probability
conf2 = textequiv.get_conf() or 1.0
conf2 = textequiv.conf
textequiv.set_conf(conf * lm_weight + conf2 * (1. - lm_weight))
i += textequiv_len
if i != len(confidences):
Expand Down Expand Up @@ -370,12 +370,20 @@ def _get_edges(graph, start_node):

def _filter_choices(textequivs):
'''assuming `textequivs` are already sorted by input confidence (conf attribute), ensure maximum number and maximum relative threshold'''
textequivs = textequivs[:min(CHOICE_THRESHOLD_NUM, len(textequivs))]
if textequivs:
textequivs = textequivs[:min(CHOICE_THRESHOLD_NUM, len(textequivs))]
for te in textequivs:
# generateDS does not convert simpleType for attributes (yet?)
if te.conf:
te.set_conf(float(te.conf))
else:
te.set_conf(1.0)
conf0 = textequivs[0].conf
if conf0:
return [te for te in textequivs if conf0 - te.conf < CHOICE_THRESHOLD_CONF]
else:
return textequivs
return [te for te in textequivs
if conf0 - te.conf < CHOICE_THRESHOLD_CONF]
else:
return []

def _get_conf(textequiv, default=1.0):
'''get float value of conf attribute with default'''
return float(textequiv.conf or str(default))
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ocrd >= 1.0.0b10
ocrd >= 1.0.1
click
keras >= 2.2.4
numpy
Expand Down

0 comments on commit ab21b1a

Please sign in to comment.