vqa.pytorch icon indicating copy to clipboard operation
vqa.pytorch copied to clipboard

Left padding when encoding questions

Open DenisDsh opened this issue 7 years ago • 0 comments

In vqa_processed.py, encode_question fails (index out of range) when the padding desired is 'left' and the question length is larger than the maximum length.

A possible fix is to replace the else branch :

else:   #['pad'] == 'left'
                    new_k = k + maxlength - len(ex['question_words_UNK'])
                    ex['question_wids'][new_k] = word_to_wid[w]
                ex['seq_length'] = len(ex['question_words_UNK'])

With

else:   # ['pad'] == 'left'
    if maxlength < len(ex['question_words_UNK']):
        ex['question_wids'][k] = word_to_id[w]
    else:
        new_k = k + maxlength - len(ex['question_words_UNK'])
        ex['question_wids'][new_k] = word_to_id[w]

DenisDsh avatar Jul 23 '18 16:07 DenisDsh