code: def get_doc_lengths(
      doc_term_matrix: sp.csr_matrix,
      *,
      type_: Literal["linear", "sqrt", "log"] = "linear",
  ) -> np.ndarray:
      """
      Compute the lengths (i.e. number of terms) for all documents in a
      document-term matrix.
  
      Args:
          doc_term_matrix: M x N sparse matrix, where M is the # of docs, N is the #
              of unique terms, and values are the absolute counts of term n per doc m.
          type_: Scaling applied to absolute doc lengths.
              If 'linear', lengths are left as-is, since the sums are already
              linear; if 'sqrt', dl => sqrt(dl); if 'log', dl => log(dl) + 1.
  
      Returns:
          Array of document lengths, with length equal to the # of documents
          (i.e. # of rows) in ``doc_term_matrix``.
  
      Raises:
          ValueError: if ``type_`` isn't one of {"linear", "sqrt", "log"}.
      """
      dls = np.asarray(doc_term_matrix.sum(axis=1)).ravel()
      if type_ == "linear":
          return dls  # dls is already linear
      elif type_ == "sqrt":
          return np.sqrt(dls)
      elif type_ == "log":
          return np.log(dls) + 1.0
      else:
          raise ValueError(
              errors.value_invalid_msg(
                  "type_", type_, {"linear", "sqrt", "log"}
              )
          )
  
file_path: textacy/src/textacy/representations/matrix_utils.py
imports: from __future__ import annotations
  from typing import Literal, Optional
  import numpy
  import scipy.sparse
  from ..None import errors
label_desc: Use image node_id 4 for calling a global function with example usage: get_doc_lengths(doc_term_matrix) and returns: dls, np, unknown