Код: Выделить всё
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlenlp/metrics/bleu.py in accumulate(self)
230 logs = math.fsum(w_i * math.log(p_i)
231 for w_i, p_i in zip(self.weights, prob_list))
--> 232 if float(self.bp_c) != 0:
233 bp = math.exp(min(1 - self.bp_r / float(self.bp_c), 0))
234 else:
ZeroDivisionError: float division by zero
Я запускаю этот проект на BML CodeLab, который похож на блокнот Jupyter. Но я не знаю, как добавить PDB и просмотреть значения. Я могу исправить только некоторые коды в cmd.
Вот функция.
Код: Выделить всё
def accumulate(self):
'''
Calculates and returns the final bleu metric.
Returns:
Tensor: Returns the accumulated metric `bleu` and its data type is float64.
'''
prob_list = []
for n_size in range(self.n_size):
try:
if self.candi_ngram[n_size] == 0:
_score = 0.0
else:
_score = self.match_ngram[n_size] / float(
self.candi_ngram[n_size])
except:
_score = 0
if _score == 0:
_score = sys.float_info.min
prob_list.append(_score)
logs = math.fsum(w_i * math.log(p_i)
for w_i, p_i in zip(self.weights, prob_list))
if float(self.bp_c) != 0:
bp = math.exp(min(1 - self.bp_r / float(self.bp_c), 0))
else:
bp = math.exp(0)
bleu = bp * math.exp(logs)
return bleu
Подробнее здесь: https://stackoverflow.com/questions/787 ... s-not-zero