code: def test_update():
      W = numpy.asarray([1.0, 0.0, 0.0, 1.0], dtype="f").reshape((2, 2))
      bias = numpy.asarray([0.0, 0.0], dtype="f")
  
      model = Linear(2, 2)
      model.set_param("W", W)
      model.set_param("b", bias)
      sgd = SGD(1.0, L2=0.0, grad_clip=0.0)
      sgd.averages = None
  
      ff = numpy.asarray([[0.0, 0.0]], dtype="f")
      tf = numpy.asarray([[1.0, 0.0]], dtype="f")
      ft = numpy.asarray([[0.0, 1.0]], dtype="f")  # noqa: F841
      tt = numpy.asarray([[1.0, 1.0]], dtype="f")  # noqa: F841
  
      # ff, i.e. 0, 0
      scores, backprop = model.begin_update(ff)
      assert_allclose(scores[0, 0], scores[0, 1])
      # Tell it the answer was 'f'
      gradient = numpy.asarray([[-1.0, 0.0]], dtype="f")
      backprop(gradient)
      for key, (param, d_param) in model.get_gradients().items():
          param, d_param = sgd(key, param, d_param)
          model.set_param(key[1], param)
          model.set_grad(key[1], d_param)
  
      b = model.get_param("b")
      W = model.get_param("W")
      assert b[0] == 1.0
      assert b[1] == 0.0
      # Unchanged -- input was zeros, so can't get gradient for weights.
      assert W[0, 0] == 1.0
      assert W[0, 1] == 0.0
      assert W[1, 0] == 0.0
      assert W[1, 1] == 1.0
  
      # tf, i.e. 1, 0
      scores, finish_update = model.begin_update(tf)
      # Tell it the answer was 'T'
      gradient = numpy.asarray([[0.0, -1.0]], dtype="f")
      finish_update(gradient)
      for key, (W, dW) in model.get_gradients().items():
          sgd(key, W, dW)
      b = model.get_param("b")
      W = model.get_param("W")
      assert b[0] == 1.0
      assert b[1] == 1.0
      # Gradient for weights should have been outer(gradient, input)
      # so outer([0, -1.], [1., 0.])
      # =  [[0., 0.], [-1., 0.]]
      assert W[0, 0] == 1.0 - 0.0
      assert W[0, 1] == 0.0 - 0.0
      assert W[1, 0] == 0.0 - -1.0
      assert W[1, 1] == 1.0 - 0.0
  
imports: import numpy
  import pytest
  from hypothesis import given, settings
  from mock import MagicMock
  from numpy.testing import assert_allclose
  from thinc.api import SGD, Dropout, Linear, chain
  from ..strategies import arrays_OI_O_BI
  from ..util import get_model, get_shape
label_desc: Use image node_id 14 for calling a global function with example usage: test_update() without return types