Skip to content

Commit

Permalink
Bugs for hypotheses with empty lines fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Weiyue Wang committed Apr 18, 2018
1 parent 3618e1e commit 24594b0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion CharacTER.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import sys
import itertools
import math
import time


# Character error rate calculator, both hyp and ref are word lists
Expand All @@ -43,7 +44,11 @@ def cer(hyp, ref):
shifted_chars = list(" ".join(hyp_words))
ref_chars = list(" ".join(ref_words))
edit_cost = edit_distance(shifted_chars, ref_chars) + shift_cost
return edit_cost / len(shifted_chars)

if len(shifted_chars) == 0:
return 1.0
else:
return edit_cost / len(shifted_chars)


"""
Expand Down Expand Up @@ -329,4 +334,8 @@ def main():


if __name__ == '__main__':
# start_time = time.time()
main()
# end_time = time.time()
# print(int(start_time))
# print(int(end_time))

0 comments on commit 24594b0

Please sign in to comment.