code: def cosine_similarity(X, Y=None, dense_output=True):
      """Compute cosine similarity between samples in X and Y.
  
      Cosine similarity, or the cosine kernel, computes similarity as the
      normalized dot product of X and Y:
  
          K(X, Y) = <X, Y> / (||X||*||Y||)
  
      On L2-normalized data, this function is equivalent to linear_kernel.
  
      Read more in the :ref:`User Guide <cosine_similarity>`.
  
      Parameters
      ----------
      X : ndarray or sparse array, shape: (n_samples_X, n_features)
          Input data.
  
      Y : ndarray or sparse array, shape: (n_samples_Y, n_features)
          Input data. If ``None``, the output will be the pairwise
          similarities between all samples in ``X``.
  
      dense_output : boolean (optional), default True
          Whether to return dense output even when the input is sparse. If
          ``False``, the output is sparse if both input arrays are sparse.
  
          .. versionadded:: 0.17
             parameter ``dense_output`` for dense output.
  
      Returns
      -------
      kernel matrix : array
          An array with shape (n_samples_X, n_samples_Y).
      """
      # to avoid recursive import
  
      X, Y = check_pairwise_arrays(X, Y)
  
      X_normalized = normalize(X, copy=True)
      if X is Y:
          Y_normalized = X_normalized
      else:
          Y_normalized = normalize(Y, copy=True)
  
      K = safe_sparse_dot(
          X_normalized, Y_normalized.T, dense_output=dense_output
      )
  
      return K
  
imports: import itertools
  import numpy
  from scipy.spatial import distance
  from scipy.sparse import csr_matrix
  from scipy.sparse import issparse
  from ..utils import check_array
  from ..utils import gen_even_slices
  from ..utils import gen_batches
  from ..utils.fixes import partial
  from ..utils.extmath import row_norms, safe_sparse_dot
  from ..preprocessing import normalize
  from ..externals.joblib import Parallel
  from ..externals.joblib import delayed
  from ..externals.joblib import cpu_count
  from .pairwise_fast import _chi2_kernel_fast, _sparse_manhattan
label_desc: Use image node_id 18 for calling a global function with example usage: cosine_similarity(X, Y, dense_output) and returns: K