code: def test_forward(self, backend_config):
      sampler = make_sampler(backend_config, self.label_size)
      x_data = backend_config.get_array(self.x)
      t_data = backend_config.get_array(self.t)
      w_data = backend_config.get_array(self.w)
      batch_size = len(self.t)
      x = chainer.Variable(x_data)
      t = chainer.Variable(t_data, requires_grad=False)
      w = chainer.Variable(w_data)
  
      # return_samples=False
      y = functions.negative_sampling(
          x, t, w, sampler, self.sample_size, reduce=self.reduce
      )
      assert y.dtype == self.dtype
  
      # return_samples=True
      y_, samples = functions.negative_sampling(
          x,
          t,
          w,
          sampler,
          self.sample_size,
          reduce=self.reduce,
          return_samples=True,
      )
  
      xp = chainer.backend.get_array_module(x)
      assert isinstance(samples, xp.ndarray)
      assert samples.dtype == numpy.int32
      assert samples.shape == (batch_size, self.sample_size + 1)
  
      # Sampler is deterministic, so y and y_ should equal.
      assert y.dtype == y_.dtype
      cpu_device = CpuDevice()
      numpy.testing.assert_array_equal(
          cpu_device.send(y.array), cpu_device.send(y_.array)
      )
  
      assert y.shape == self.gy.shape
  
      samples = cpu_device.send(samples)
  
      loss = numpy.empty((len(self.x),), self.dtype)
      for i in six.moves.range(len(self.x)):
          ix = self.x[i]
          it = self.t[i]
          if it == -1:
              loss[i] = 0
          else:
              iw = self.w[samples[i]]
  
              f = iw.dot(ix)
              # first one is positive example
              f[0] *= -1
              loss[i] = numpy.logaddexp(f, 0).sum()
  
      if self.reduce == "sum":
          loss = loss.sum()
  
      assert y.dtype == loss.dtype
      testing.assert_allclose(
          y.data, loss, **self.check_forward_options
      )
  
imports: import unittest
  import numpy
  import pytest
  import six
  import chainer
  from chainer.backend import CpuDevice
  from chainer.backends import cuda
  from chainer import functions
  from chainer.functions.loss import negative_sampling
  from chainer import gradient_check
  from chainer import testing
  from chainer.testing import attr
label_desc: Use image node_id 2 for calling the TestNegativeSamplingFunction obj's underlying member method code with example usage: obj.test_forward(backend_config) without return types