(n_src_features, n_tgt_features)
return fields
Args:
            n_src_features (int): the number of source features to
                create `torchtext.data.Field` for.
            n_tgt_features (int): 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 (int): the number of source features to
                create `torchtext.data.Field` for.
            n_tgt_features (int): the number of target features to
                create `torchtext.data.Field` for.
Args : n_src_features ( int ) : the number of source features to create torchtext . data . Field for . n_tgt_features ( int ) : the number of target features to create torchtext . data . Field for .
def get_fields(n_src_features, n_tgt_features):
        """
        Args:
            n_src_features (int): the number of source features to
                create `torchtext.data.Field` for.
            n_tgt_features (int): 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 = {}


        fields["src"] = torchtext.data.Field(
            pad_token=PAD_WORD,
            include_lengths=True)


        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):
            """ ? """
            #pdb.set_trace()
            src_size = max([t.size(0) for t in data])
            
            src_vocab_size = int(max([t.max() for t in data])) + 1
            
            try:
                alignment = torch.zeros(src_size, len(data), src_vocab_size)
            except:

                print(src_size)
                print(len(data))
                print(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)

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

            for i, sent in enumerate(data):
                alignment[i,:sent.size(0)] = sent
            return alignment

        fields["src_sents"] = torchtext.data.Field(
            use_vocab=False, dtype=torch.long, postprocessing=make_sents,sequential=False)
        fields["tgt_sents"] = torchtext.data.Field(
            use_vocab=False, dtype=torch.long, postprocessing=make_sents,sequential=False)

        return fields
def get_fields ( n_src_features , n_tgt_features ) : fields = { } fields [ "src" ] = torchtext . data . Field ( pad_token = PAD_WORD , include_lengths = True ) 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 ) : """ ? """ #pdb.set_trace() src_size = max ( [ t . size ( 0 ) for t in data ] ) src_vocab_size = int ( max ( [ t . max ( ) for t in data ] ) ) + 1 try : alignment = torch . zeros ( src_size , len ( data ) , src_vocab_size ) except : print ( src_size ) print ( len ( data ) ) print ( 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 ) def make_sents ( data , vocab ) : """ ? """ tgt_size = max ( [ t . size ( 0 ) for t in data ] ) alignment = torch . zeros ( len ( data ) , tgt_size ) . long ( ) for i , sent in enumerate ( data ) : alignment [ i , : sent . size ( 0 ) ] = sent return alignment fields [ "src_sents" ] = torchtext . data . Field ( use_vocab = False , dtype = torch . long , postprocessing = make_sents , sequential = False ) fields [ "tgt_sents" ] = torchtext . data . Field ( use_vocab = False , dtype = torch . long , postprocessing = make_sents , sequential = False ) return fields