(scores, batch, tgt_vocab, src_vocabs)
return scores
Given scores from an expanded dictionary
        corresponeding to a batch, sums together copies,
        with a dictionary word when it is ambigious.
Given scores from an expanded dictionary
        corresponeding to a batch, sums together copies,
        with a dictionary word when it is ambigious.
Given scores from an expanded dictionary corresponeding to a batch sums together copies with a dictionary word when it is ambigious .
def collapse_copy_scores(scores, batch, tgt_vocab, src_vocabs):
        """
        Given scores from an expanded dictionary
        corresponeding to a batch, sums together copies,
        with a dictionary word when it is ambigious.
        """
        offset = len(tgt_vocab)
        for b in range(batch.batch_size):
            blank = []
            fill = []
            index = batch.indices.data[b]
            src_vocab = src_vocabs[index]
            for i in range(1, len(src_vocab)):
                sw = src_vocab.itos[i]
                ti = tgt_vocab.stoi[sw]
                if ti != 0:
                    blank.append(offset + i)
                    fill.append(ti)
            if blank:
                blank = torch.Tensor(blank).type_as(batch.indices.data)
                fill = torch.Tensor(fill).type_as(batch.indices.data)
                scores[:, b].index_add_(1, fill,
                                        scores[:, b].index_select(1, blank))
                scores[:, b].index_fill_(1, blank, 1e-10)
        return scores
def collapse_copy_scores ( scores , batch , tgt_vocab , src_vocabs ) : offset = len ( tgt_vocab ) for b in range ( batch . batch_size ) : blank = [ ] fill = [ ] index = batch . indices . data [ b ] src_vocab = src_vocabs [ index ] for i in range ( 1 , len ( src_vocab ) ) : sw = src_vocab . itos [ i ] ti = tgt_vocab . stoi [ sw ] if ti != 0 : blank . append ( offset + i ) fill . append ( ti ) if blank : blank = torch . Tensor ( blank ) . type_as ( batch . indices . data ) fill = torch . Tensor ( fill ) . type_as ( batch . indices . data ) scores [ : , b ] . index_add_ ( 1 , fill , scores [ : , b ] . index_select ( 1 , blank ) ) scores [ : , b ] . index_fill_ ( 1 , blank , 1e-10 ) return scores