@Zenglinxiao,
To verify your assumption, I changed the batch_size to 2 and added the following lines in _translate_batch_with_strategy
function of translator.py
.
results["predictions"] = decode_strategy.predictions
results["attention"] = decode_strategy.attention
flatten_prediction = [
best.tolist() for bests in decode_strategy.predictions for best in bests
]
if self.report_align:
try:
results["alignment"] = self._align_forward(
batch, decode_strategy.predictions)
except RuntimeError:
print("src:", src.tolist())
print("predictions:", flatten_prediction)
else:
results["alignment"] = [[] for _ in range(batch_size)]
return results
The output I got is:
src: [
[[13325], [5053]], [[3945], [84]], [[2023], [1]], [[4285], [1]], [[5618], [1]], [[20846], [1]], [[6506], [1]], [[12634], [1]], [[19949], [1]], [[31744], [1]], [[30032], [1]], [[14311], [1]], [[8845], [1]], [[26022], [1]], [[28139], [1]], [[14709], [1]], [[12405], [1]], [[12403], [1]], [[31857], [1]], [[4213], [1]], [[1006], [1]], [[18492], [1]], [[4918], [1]], [[5053], [1]], [[36], [1]], [[30828], [1]], [[14311], [1]], [[11690], [1]], [[26022], [1]], [[22876], [1]], [[13718], [1]], [[31744], [1]], [[29656], [1]], [[15038], [1]], [[30703], [1]], [[12287], [1]], [[12403], [1]], [[11072], [1]], [[31852], [1]], [[4852], [1]], [[31745], [1]], [[15721], [1]], [[2], [1]]
]
predictions: [
[29282, 29427, 16039, 27048, 7452, 23771, 29427, 9663, 8713, 5676, 4947, 1353, 17731, 1713, 11, 30663, 29427, 20410, 31845, 16115, 30650, 7452, 26942, 31845, 6594, 11350, 10892, 7452, 29423, 25, 4598, 18679, 4, 3],
[3]
]
Your assumption seems to be correct: the error is the result of the blank prediction. I think this is happening for something like this: the input text is a single character (like a replacement character ďż˝) that SentencePiece encoder returns as an empty string and the src
text end up containing just an empty string.
Any idea how to fix this blank prediction issue?
Thanks!
ps: For some reason, I donât encounter the error when I set the batch_size to 1. Any reason why this would be the case?