(self, data, c, m)
return (loss * m).sum() / data.size()[0]
Compute the cross entropy loss on the fixed discrete column.
Compute the cross entropy loss on the fixed discrete column.
Compute the cross entropy loss on the fixed discrete column .
def _cond_loss(self, data, c, m):
        """Compute the cross entropy loss on the fixed discrete column."""
        loss = []
        st = 0
        st_c = 0
        for column_info in self._transformer.output_info_list:
            for span_info in column_info:
                if len(column_info) != 1 or span_info.activation_fn != 'softmax':
                    # not discrete column
                    st += span_info.dim
                else:
                    ed = st + span_info.dim
                    ed_c = st_c + span_info.dim
                    tmp = functional.cross_entropy(
                        data[:, st:ed],
                        torch.argmax(c[:, st_c:ed_c], dim=1),
                        reduction='none'
                    )
                    loss.append(tmp)
                    st = ed
                    st_c = ed_c

        loss = torch.stack(loss, dim=1)  # noqa: PD013

        return (loss * m).sum() / data.size()[0]
def _cond_loss ( self , data , c , m ) : loss = [ ] st = 0 st_c = 0 for column_info in self . _transformer . output_info_list : for span_info in column_info : if len ( column_info ) != 1 or span_info . activation_fn != 'softmax' : # not discrete column st += span_info . dim else : ed = st + span_info . dim ed_c = st_c + span_info . dim tmp = functional . cross_entropy ( data [ : , st : ed ] , torch . argmax ( c [ : , st_c : ed_c ] , dim = 1 ) , reduction = 'none' ) loss . append ( tmp ) st = ed st_c = ed_c loss = torch . stack ( loss , dim = 1 ) # noqa: PD013 return ( loss * m ) . sum ( ) / data . size ( ) [ 0 ]