#NEWLINE# def check_forward( self , t_data , xs_data , l_length , x_length ) : #NEWLINE# #INDENT# x = tuple ( ( chainer . Variable ( x_data ) for x_data in xs_data ) ) #NEWLINE# t = chainer . Variable ( t_data ) #NEWLINE# args = ( x , t , self . blank_symbol ) #NEWLINE# if self . use_length : #NEWLINE# #INDENT# args += ( chainer . Variable ( x_length ) , chainer . Variable ( l_length ) ) #NEWLINE# #UNINDENT# loss = functions . connectionist_temporal_classification ( * args ) #NEWLINE# loss_value = float ( loss . data ) #NEWLINE# xp = cuda . get_array_module ( self . x ) #NEWLINE# xt = xp . swapaxes ( self . x , 0 , 1 ) #NEWLINE# for b in range ( xt . shape [ 0 ] ) : #NEWLINE# #INDENT# for t in range ( xt . shape [ 1 ] ) : #NEWLINE# #INDENT# xt [ b ] [ t ] = ( numpy . exp ( xt [ b ] [ t ] ) / numpy . sum ( numpy . exp ( xt [ b ] [ t ] ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# loss_expect = 0 #NEWLINE# batch_size = xt . shape [ 0 ] #NEWLINE# path_length = ( ( 2 * l_length ) + 1 ) #NEWLINE# for ( xtb , lb , xlb , plb ) in zip ( xt , self . l , x_length , path_length ) : #NEWLINE# #INDENT# loss_expect += ( - math . log ( ( self . alpha ( xtb , lb , int ( ( xlb - 1 ) ) , int ( ( plb - 1 ) ) ) + self . alpha ( xtb , lb , int ( ( xlb - 1 ) ) , int ( ( plb - 2 ) ) ) ) ) ) #NEWLINE# #UNINDENT# loss_expect /= batch_size #NEWLINE# self . assertAlmostEqual ( loss_expect , loss_value , places = 5 )