(n_src_features, n_tgt_features)
return fields
Args:
            n_src_features: the number of source features to
                create `torchtext.data.Field` for.
            n_tgt_features: the number of target features to
                create `torchtext.data.Field` for.

        Returns:
            A dictionary whose keys are strings and whose values
            are the corresponding Field objects.
Args:
            n_src_features: the number of source features to
                create `torchtext.data.Field` for.
            n_tgt_features: the number of target features to
                create `torchtext.data.Field` for.
Args : n_src_features : the number of source features to create torchtext . data . Field for . n_tgt_features : the number of target features to create torchtext . data . Field for .
def get_fields(n_src_features, n_tgt_features):
        """
        Args:
            n_src_features: the number of source features to
                create `torchtext.data.Field` for.
            n_tgt_features: the number of target features to
                create `torchtext.data.Field` for.

        Returns:
            A dictionary whose keys are strings and whose values
            are the corresponding Field objects.
        """
        fields = {}

        def make_img(data, vocab):
            """ ? """
            c = data[0].size(0)
            h = max([t.size(1) for t in data])
            w = max([t.size(2) for t in data])
            imgs = torch.zeros(len(data), c, h, w).fill_(1)
            for i, img in enumerate(data):
                imgs[i, :, 0:img.size(1), 0:img.size(2)] = img
            return imgs

        fields["src"] = torchtext.data.Field(
            use_vocab=False, dtype=torch.float,
            postprocessing=make_img, sequential=False)

        for j in range(n_src_features):
            fields["src_feat_" + str(j)] = \
                torchtext.data.Field(pad_token=PAD_WORD)

        fields["tgt"] = torchtext.data.Field(
            init_token=BOS_WORD, eos_token=EOS_WORD,
            pad_token=PAD_WORD)

        for j in range(n_tgt_features):
            fields["tgt_feat_" + str(j)] = \
                torchtext.data.Field(init_token=BOS_WORD, eos_token=EOS_WORD,
                                     pad_token=PAD_WORD)

        def make_src(data, vocab):
            """ ? """
            src_size = max([t.size(0) for t in data])
            src_vocab_size = max([t.max() for t in data]) + 1
            alignment = torch.zeros(src_size, len(data), src_vocab_size)
            for i, sent in enumerate(data):
                for j, t in enumerate(sent):
                    alignment[j, i, t] = 1
            return alignment

        fields["src_map"] = torchtext.data.Field(
            use_vocab=False, dtype=torch.float,
            postprocessing=make_src, sequential=False)

        def make_tgt(data, vocab):
            """ ? """
            tgt_size = max([t.size(0) for t in data])
            alignment = torch.zeros(tgt_size, len(data)).long()
            for i, sent in enumerate(data):
                alignment[:sent.size(0), i] = sent
            return alignment

        fields["alignment"] = torchtext.data.Field(
            use_vocab=False, dtype=torch.long,
            postprocessing=make_tgt, sequential=False)

        fields["indices"] = torchtext.data.Field(
            use_vocab=False, dtype=torch.long,
            sequential=False)

        return fields
def get_fields ( n_src_features , n_tgt_features ) : fields = { } def make_img ( data , vocab ) : """ ? """ c = data [ 0 ] . size ( 0 ) h = max ( [ t . size ( 1 ) for t in data ] ) w = max ( [ t . size ( 2 ) for t in data ] ) imgs = torch . zeros ( len ( data ) , c , h , w ) . fill_ ( 1 ) for i , img in enumerate ( data ) : imgs [ i , : , 0 : img . size ( 1 ) , 0 : img . size ( 2 ) ] = img return imgs fields [ "src" ] = torchtext . data . Field ( use_vocab = False , dtype = torch . float , postprocessing = make_img , sequential = False ) for j in range ( n_src_features ) : fields [ "src_feat_" + str ( j ) ] = torchtext . data . Field ( pad_token = PAD_WORD ) fields [ "tgt" ] = torchtext . data . Field ( init_token = BOS_WORD , eos_token = EOS_WORD , pad_token = PAD_WORD ) for j in range ( n_tgt_features ) : fields [ "tgt_feat_" + str ( j ) ] = torchtext . data . Field ( init_token = BOS_WORD , eos_token = EOS_WORD , pad_token = PAD_WORD ) def make_src ( data , vocab ) : """ ? """ src_size = max ( [ t . size ( 0 ) for t in data ] ) src_vocab_size = max ( [ t . max ( ) for t in data ] ) + 1 alignment = torch . zeros ( src_size , len ( data ) , src_vocab_size ) for i , sent in enumerate ( data ) : for j , t in enumerate ( sent ) : alignment [ j , i , t ] = 1 return alignment fields [ "src_map" ] = torchtext . data . Field ( use_vocab = False , dtype = torch . float , postprocessing = make_src , sequential = False ) def make_tgt ( data , vocab ) : """ ? """ tgt_size = max ( [ t . size ( 0 ) for t in data ] ) alignment = torch . zeros ( tgt_size , len ( data ) ) . long ( ) for i , sent in enumerate ( data ) : alignment [ : sent . size ( 0 ) , i ] = sent return alignment fields [ "alignment" ] = torchtext . data . Field ( use_vocab = False , dtype = torch . long , postprocessing = make_tgt , sequential = False ) fields [ "indices" ] = torchtext . data . Field ( use_vocab = False , dtype = torch . long , sequential = False ) return fields