[search] Fixing the dimension mismatch error and bool comparison issue
This commit is fixing two bugs I had while running the code with PyTorch 1.3.0 - When the alpha value is set to -1 or lower (i.e. alpha = -1) I was having dimension mismatch error in the line 281 (log_probs += topk_log_probs.view(-1).unsqueeze(1)). Adding the lines 298-299 fixed that error. - The comparisons of bool tensors with int values, i.e. end_condition.eq(0), was not working properly (which might have something to do with the new pytorch version). As a result, the beam search was predicting sequences without <eos> tokens and lots of <pad>s. I replaced the int values with their boolean counterparts the lines 318, 320 and 348 to fix this issue. I also did some housekeeping changes - Changed the creation/initialisation of topk_log_probs tensor to match the shape of topk_scores. - Combined the results dict creation into a single command at lines 238-242. - I added a tensor clone() call in the line 282 for keeping the code safe for future changes. (Changes in curr_scores were effecting the log_probs tensor) - I added an if statement to check how many <eos> tokens are there in a predicted sequence. If it has more than one <eos>, it means that the prediction should have already been added to the hypotheses, so you don't have to add them again.
Loading
Please register or sign in to comment