class_docstr: A simple classifier model.
  
  This is an example of chain that wraps another chain. It computes the
  loss and accuracy based on a given input/label pair.
  
  Args:
      predictor (~chainer.Link): Predictor network.
      lossfun (callable):
          Loss function.
          You can specify one of loss functions from
          :doc:`built-in loss functions </reference/functions>`, or
          your own loss function (see the example below).
          It should not be an
          :doc:`loss functions with parameters </reference/links>`
          (i.e., :class:`~chainer.Link` instance).
          The function must accept two argument (an output from predictor
          and its ground truth labels), and return a loss.
          Returned value must be a Variable derived from the input Variable
          to perform backpropagation on the variable.
      accfun (callable):
          Function that computes accuracy.
          You can specify one of evaluation functions from
          :doc:`built-in evaluation functions </reference/functions>`, or
          your own evaluation function.
          The signature of the function is the same as ``lossfun``.
      label_key (int or str): Key to specify label variable from arguments.
          When it is ``int``, a variable in positional arguments is used.
          And when it is ``str``, a variable in keyword arguments is used.
  
  Attributes:
      predictor (~chainer.Link): Predictor network.
      lossfun (callable):
          Loss function.
          See the description in the arguments for details.
      accfun (callable):
          Function that computes accuracy.
          See the description in the arguments for details.
      y (~chainer.Variable): Prediction for the last minibatch.
      loss (~chainer.Variable): Loss value for the last minibatch.
      accuracy (~chainer.Variable): Accuracy for the last minibatch.
      compute_accuracy (bool): If ``True``, compute accuracy on the forward
          computation. The default value is ``True``.
  
  .. note::
      This link uses :func:`chainer.softmax_cross_entropy` with
      default arguments as a loss function (specified by ``lossfun``),
      if users do not explicitly change it. In particular, the loss function
      does not support double backpropagation.
      If you need second or higher order differentiation, you need to turn
      it on with ``enable_double_backprop=True``:
  
        >>> import chainer.functions as F
        >>> import chainer.links as L
        >>>
        >>> def lossfun(x, t):
        ...     return F.softmax_cross_entropy(
        ...         x, t, enable_double_backprop=True)
        >>>
        >>> predictor = L.Linear(10)
        >>> model = L.Classifier(predictor, lossfun=lossfun)
code: def __init__(
      self,
      predictor,
      lossfun=softmax_cross_entropy.softmax_cross_entropy,
      accfun=accuracy.accuracy,
      label_key=-1,
  ):
      if not (isinstance(label_key, (int, str))):
          raise TypeError(
              "label_key must be int or str, but is %s"
              % type(label_key)
          )
  
      super(Classifier, self).__init__()
      self.lossfun = lossfun
      self.accfun = accfun
      self.y = None
      self.loss = None
      self.accuracy = None
      self.label_key = label_key
  
      with self.init_scope():
          self.predictor = predictor
  
file_path: chainer/chainer/links/model/classifier.py
imports: from chainer.functions.evaluation import accuracy
  from chainer.functions.loss import softmax_cross_entropy
  from chainer import link
  from chainer import reporter
label_desc: Use image node_id 1 to create a new Classifier object from inherited base classes: link with example: obj = Classifier(predictor, lossfun, accfun, label_key)