KaihuaTang / VQA2.0-Recent-Approachs-2018.pytorch

A pytroch reimplementation of "Bilinear Attention Network", "Intra- and Inter-modality Attention", "Learning Conditioned Graph Structures", "Learning to count object", "Bottom-up top-down" for Visual Question Answering 2.0
GNU General Public License v3.0
295 stars 57 forks source link

issue about question encoding #7

Closed sunqiang85 closed 4 years ago

sunqiang85 commented 5 years ago
    def _encode_question(self, question):
        """ Turn a question into a vector of indices and a question length """
        vec = torch.zeros(self.max_question_length).long().fill_(self.num_tokens)
        for i, token in enumerate(question):
            if i >= self.max_question_length:
                break
            index = self.token_to_index.get(token, self.num_tokens - 1)
            vec[i] = index
        return vec, min(len(question), self.max_question_length)

why fill the question vector with 'num_tokens'; since the index 0 is preserved in question vocabulary. and 'self.num_tokens-1' is used as index of '0' in question token vocabulary "vocab.json"

KaihuaTang commented 5 years ago

sorry i forgot the detail. the difference of index 0 and index num_tokens might be "unknown token" and "empty token".