Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions examples/NLG/eval/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def bleu_score(refs_path, hyps_path, num_refs):
result = subprocess.check_output(command, shell=True)
try:
bleu = float(re.findall('BLEU = (.+?),', str(result))[0])
except:
except Exception:
logging.error('ERROR ON COMPUTING METEOR. MAKE SURE YOU HAVE PERL INSTALLED GLOBALLY ON YOUR MACHINE.')
print('ERROR ON COMPUTING METEOR. MAKE SURE YOU HAVE PERL INSTALLED GLOBALLY ON YOUR MACHINE.')
bleu = -1
Expand Down Expand Up @@ -156,15 +156,15 @@ def meteor_score(references, hypothesis, num_refs, lng='en'):
command += '{0} {1} -l {2} -norm -r {3}'.format(hyps_tmp, refs_tmp, lng, num_refs)
result = subprocess.check_output(command, shell=True)
meteor = result.split(b'\n')[-2].split()[-1]
except:
except Exception:
logging.error('ERROR ON COMPUTING METEOR. MAKE SURE YOU HAVE JAVA INSTALLED GLOBALLY ON YOUR MACHINE.')
print('ERROR ON COMPUTING METEOR. MAKE SURE YOU HAVE JAVA INSTALLED GLOBALLY ON YOUR MACHINE.')
meteor = -1

try:
os.remove(hyps_tmp)
os.remove(refs_tmp)
except:
except Exception:
pass
logging.info('FINISHING TO COMPUTE METEOR...')
print('FINISHING TO COMPUTE METEOR...')
Expand Down Expand Up @@ -199,14 +199,14 @@ def chrF_score(references, hypothesis, num_refs, nworder, ncorder, beta):

try:
totalF, averageTotalF, totalPrec, totalRec = computeChrF(rtxt, htxt, nworder, ncorder, beta, None)
except:
except Exception:
logging.error('ERROR ON COMPUTING CHRF++.')
print('ERROR ON COMPUTING CHRF++.')
totalF, averageTotalF, totalPrec, totalRec = -1, -1, -1, -1
try:
os.remove(hyps_tmp)
os.remove(refs_tmp)
except:
except Exception:
pass
logging.info('FINISHING TO COMPUTE CHRF++...')
print('FINISHING TO COMPUTE CHRF++...')
Expand All @@ -225,7 +225,7 @@ def ter_score(references, hypothesis, num_refs):
else:
try:
ter_score = pyter.ter(hyp.split(), ref.split())
except:
except Exception:
ter_score = 1
candidates.append(ter_score)

Expand All @@ -250,7 +250,7 @@ def bert_score_(references, hypothesis, lng='en'):
F1 = float(sum(F1) / len(F1))
P = float(sum(P) / len(P))
R = float(sum(R) / len(R))
except:
except Exception:
P, R, F1 = 0, 0, 0
return P, R, F1

Expand Down
2 changes: 1 addition & 1 deletion examples/NLG/src/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def bpe(self, token):
j = word.index(first, i)
new_word.extend(word[i:j])
i = j
except:
except Exception:
new_word.extend(word[i:])
break

Expand Down