human
I wrote the below code

    n_features = X.shape[1]
    n_classes = Y.shape[1]
    fit_intercept = (w.size == (n_classes * (n_features + 1)))
    (loss, grad, p) = _multinomial_loss_grad(w, X, Y, alpha, sample_weight)
    sample_weight = sample_weight[:, np.newaxis]
    def hessp(v):
        v = v.reshape(n_classes, (-1))
        if fit_intercept:
            inter_terms = v[:, (-1)]
            v = v[:, :(-1)]
        else:
            inter_terms = 0
        r_yhat = safe_sparse_dot(X, v.T)
        r_yhat += inter_terms
        r_yhat += ((- p) * r_yhat).sum(axis=1)[:, np.newaxis]
        r_yhat *= p
        r_yhat *= sample_weight
        hessProd = np.zeros((n_classes, (n_features + bool(fit_intercept))))
        hessProd[:, :n_features] = safe_sparse_dot(r_yhat.T, X)
        hessProd[:, :n_features] += (v * alpha)
        if fit_intercept:
            hessProd[:, (-1)] = r_yhat.sum(axis=0)
        return hessProd.ravel()
    return (grad, hessp)

What's a good function header?
assistant
#Here's a good function header.

def _multinomial_grad_hess(w, X, Y, alpha, sample_weight):