code: def _multinomial_loss(w, X, Y, alpha, sample_weight):
      """Computes multinomial loss and class probabilities.
  
      Parameters
      ----------
      w : ndarray, shape (n_classes * n_features,) or
          (n_classes * (n_features + 1),)
          Coefficient vector.
  
      X : {array-like, sparse matrix}, shape (n_samples, n_features)
          Training data.
  
      Y : ndarray, shape (n_samples, n_classes)
          Transformed labels according to the output of LabelBinarizer.
  
      alpha : float
          Regularization parameter. alpha is equal to 1 / C.
  
      sample_weight : array-like, shape (n_samples,) optional
          Array of weights that are assigned to individual samples.
          If not provided, then each sample is given unit weight.
  
      Returns
      -------
      loss : float
          Multinomial loss.
  
      p : ndarray, shape (n_samples, n_classes)
          Estimated class probabilities.
  
      w : ndarray, shape (n_classes, n_features)
          Reshaped param vector excluding intercept terms.
  
      Reference
      ---------
      Bishop, C. M. (2006). Pattern recognition and machine learning.
      Springer. (Chapter 4.3.4)
      """
      n_classes = Y.shape[1]
      n_features = X.shape[1]
      fit_intercept = w.size == (n_classes * (n_features + 1))
      w = w.reshape(n_classes, -1)
      sample_weight = sample_weight[:, np.newaxis]
      if fit_intercept:
          intercept = w[:, -1]
          w = w[:, :-1]
      else:
          intercept = 0
      p = safe_sparse_dot(X, w.T)
      p += intercept
      p -= logsumexp(p, axis=1)[:, np.newaxis]
      loss = -(sample_weight * Y * p).sum()
      loss += 0.5 * alpha * squared_norm(w)
      p = np.exp(p, p)
      return loss, p, w
  
imports: import numbers
  import warnings
  import numpy
  from scipy import optimize, sparse
  from .base import LinearClassifierMixin, SparseCoefMixin, BaseEstimator
  from .sag import sag_solver
  from ..feature_selection.from_model import _LearntSelectorMixin
  from ..preprocessing import LabelEncoder, LabelBinarizer
  from ..svm.base import _fit_liblinear
  from ..utils import check_array, check_consistent_length, compute_class_weight
  from ..utils import check_random_state
  from ..utils.extmath import logsumexp, log_logistic, safe_sparse_dot, softmax, squared_norm
  from ..utils.extmath import row_norms
  from ..utils.optimize import newton_cg
  from ..utils.validation import check_X_y
  from ..exceptions import NotFittedError
  from ..utils.fixes import expit
  from ..utils.multiclass import check_classification_targets
  from ..externals.joblib import Parallel, delayed
  from ..model_selection import check_cv
  from ..externals import six
  from ..metrics import SCORERS
label_desc: Use image node_id 5 for calling a global function with example usage: _multinomial_loss(w, X, Y, alpha, sample_weight) and returns: loss,  p,  w