Skip to content

Commit

Permalink
convert langid confidences to floats
Browse files Browse the repository at this point in the history
  • Loading branch information
svirpioj committed Jun 26, 2024
1 parent b722f04 commit 1003490
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion opusfilter/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def confidence(self, sentence: str, lan: str) -> float:

if self.id_method == 'langid':
lidetails = self.identifier.classify(sentence)
lilan, liconf = lidetails[0], round(lidetails[1], 2)
lilan, liconf = lidetails[0], round(float(lidetails[1]), 2)
if lilan != lan:
liconf = 0.0
return liconf
Expand Down
6 changes: 5 additions & 1 deletion opusfilter/opusfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,11 @@ def _write_jsonl(objects, fname):
"""Write objects to file as JSON lines"""
with file_open(fname, 'w') as fobj:
for obj in objects:
fobj.write(json.dumps(obj, sort_keys=True)+'\n')
try:
fobj.write(json.dumps(obj, sort_keys=True)+'\n')
except TypeError as err:
logger.error("Could not convert to JSON: %s", obj)
raise err

@staticmethod
def _read_jsonl(fname):
Expand Down

0 comments on commit 1003490

Please sign in to comment.