def test_model(model, data_loader, loss_func, ctx):
    """
    Test model.
    """
    acc = 0.
    loss = 0.
    for _, example in enumerate(data_loader):
        s1, s2, label = example
        s1 = s1.as_in_context(ctx)
        s2 = s2.as_in_context(ctx)
        label = label.as_in_context(ctx)
        output = model(s1, s2)
        loss += loss_func(output, label).mean().asscalar()
        pred = output.argmax(axis=1)
        acc += (pred == label.astype(np.float32)).mean().asscalar()
    acc /= len(data_loader)
    loss /= len(data_loader)
    return loss, acc
def test_model ( model , data_loader , loss_func , ctx ) : acc = 0. loss = 0. for _ , example in enumerate ( data_loader ) : s1 , s2 , label = example s1 = s1 . as_in_context ( ctx ) s2 = s2 . as_in_context ( ctx ) label = label . as_in_context ( ctx ) output = model ( s1 , s2 ) loss += loss_func ( output , label ) . mean ( ) . asscalar ( ) pred = output . argmax ( axis = 1 ) acc += ( pred == label . astype ( np . float32 ) ) . mean ( ) . asscalar ( ) acc /= len ( data_loader ) loss /= len ( data_loader ) return loss , acc
Test model.