#NEWLINE# def grad( self , inp , grads ) : #NEWLINE# #INDENT# ( dy , sm ) = inp #NEWLINE# ( g , ) = grads #NEWLINE# tmp = ( g + tensor . neg ( tensor . sum ( ( g * sm ) , axis = 1 ) . dimshuffle ( ( 0 , 'x' ) ) ) ) #NEWLINE# g_dy = ( grads * sm ) #NEWLINE# tmp2 = tensor . sum ( ( dy * sm ) , axis = 1 ) . dimshuffle ( ( 0 , 'x' ) ) #NEWLINE# g_sm = ( ( tmp * dy ) - ( g * tmp2 ) ) #NEWLINE# return ( g_dy , g_sm )