<s> import numpy <EOL> from chainer import cuda <EOL> from chainer import function <EOL> from chainer . utils import type_check <EOL> class Accuracy ( function . Function ) : <EOL> def check_type_forward ( self , in_types ) : <EOL> type_check . expect ( in_types . size ( ) == <NUM_LIT:2> ) <EOL> x_type , t_type = in_types <EOL> type_check . expect ( <EOL> x_type . dtype == numpy . float32 , <EOL> x_type . ndim >= <NUM_LIT:2> , <EOL> t_type . dtype == numpy . int32 , <EOL> t_type . ndim == <NUM_LIT:1> , <EOL> t_type . shape [ <NUM_LIT:0> ] == x_type . shape [ <NUM_LIT:0> ] , <EOL> ) <EOL> for i in range ( <NUM_LIT:2> , x_type . ndim . eval ( ) ) : <EOL> type_check . expect ( x_type . shape [ i ] == <NUM_LIT:1> ) <EOL> def forward ( self , inputs ) : <EOL> xp = cuda . get_array_module ( * inputs ) <EOL> y , t = inputs <EOL> y = y . reshape ( len ( y ) , - <NUM_LIT:1> ) <EOL> pred = y . argmax ( axis = <NUM_LIT:1> ) <EOL> return xp . asarray ( ( pred == t ) . mean ( dtype = '<STR_LIT:f>' ) ) , <EOL> def accuracy ( y , t ) : <EOL> """<STR_LIT>""" <EOL> return Accuracy ( ) ( y , t ) </s>
