class_docstr: Cross entropy loss.
  
  This is a generalization of logistic loss to multiple classes.
  
  Parameters
  ----------
  class_weight
      A dictionary that indicates what weight to associate with each class.
  
  Examples
  --------
  
  >>> from river import optim
  
  >>> y_true = [0, 1, 2, 2]
  >>> y_pred = [
  ...     {0: 0.29450637, 1: 0.34216758, 2: 0.36332605},
  ...     {0: 0.21290077, 1: 0.32728332, 2: 0.45981591},
  ...     {0: 0.42860913, 1: 0.33380113, 2: 0.23758974},
  ...     {0: 0.44941979, 1: 0.32962558, 2: 0.22095463}
  ... ]
  
  >>> loss = optim.losses.CrossEntropy()
  
  >>> for yt, yp in zip(y_true, y_pred):
  ...     print(loss(yt, yp))
  1.222454
  1.116929
  1.437209
  1.509797
  
  >>> for yt, yp in zip(y_true, y_pred):
  ...     print(loss.gradient(yt, yp))
  {0: -0.70549363, 1: 0.34216758, 2: 0.36332605}
  {0: 0.21290077, 1: -0.67271668, 2: 0.45981591}
  {0: 0.42860913, 1: 0.33380113, 2: -0.76241026}
  {0: 0.44941979, 1: 0.32962558, 2: -0.77904537}
  
  References
  ----------
  [^1]: [What is Softmax regression and how is it related to Logistic regression?](https://github.com/rasbt/python-machine-learning-book/blob/master/faq/softmax_regression.md)
class_docstr_tok: ["Cross","entropy","loss",".","This","is","a","generalization","of","logistic","loss","to","multiple","classes",".","Parameters","--","--","--","--","--","class_weight","A","dictionary","that","indicates","what","weight","to","associate","with","each","class",".","Examples","--","--","--","--",">",">",">","from","river","import","optim",">",">",">","y_true","=","[","0",",","1",",","2",",","2","]",">",">",">","y_pred","=","[","...","{","0",":","0.29450637",",","1",":","0.34216758",",","2",":","0.36332605","}",",","...","{","0",":","0.21290077",",","1",":","0.32728332",",","2",":","0.45981591","}",",","...","{","0",":","0.42860913",",","1",":","0.33380113",",","2",":","0.23758974","}",",","...","{","0",":","0.44941979",",","1",":","0.32962558",",","2",":","0.22095463","}","...","]",">",">",">","loss","=","optim.losses.CrossEntropy","(",")",">",">",">","for","yt",",","yp","in","zip","(","y_true",",","y_pred",")",":","...","print","(","loss","(","yt",",","yp",")",")","1.222454","1.116929","1.437209","1.509797",">",">",">","for","yt",",","yp","in","zip","(","y_true",",","y_pred",")",":","...","print","(","loss.gradient","(","yt",",","yp",")",")","{","0",":","-0.70549363",",","1",":","0.34216758",",","2",":","0.36332605","}","{","0",":","0.21290077",",","1",":","-0.67271668",",","2",":","0.45981591","}","{","0",":","0.42860913",",","1",":","0.33380113",",","2",":","-0.76241026","}","{","0",":","0.44941979",",","1",":","0.32962558",",","2",":","-0.77904537","}","References","--","--","--","--","--","[","^1","]",":","[","What","is","Softmax","regression","and","how","is","it","related","to","Logistic","regression","?","]","(","https",":","\/\/github.com\/rasbt\/python-machine-learning-book\/blob\/master\/faq\/softmax_regression.md",")"]
code: def gradient(self, y_true, y_pred):
      return {
          label: (
              self.class_weight.get(label, 1.0)
              * (
                  clamp_proba(y_pred.get(label, 0.0))
                  - (y_true == label)
              )
          )
          for label in {*y_pred.keys(), y_true}
      }
  
imports: from __future__ import annotations
  import math
  import numpy
  from scipy import special
  from river import base, utils
  from river.optim.base import Loss
label_desc: Use image node_id 3 for calling the CrossEntropy obj's underlying member method code with example usage: obj.gradient(y_true, y_pred) and returns: unknown