code: def _colorize(
      token,  # type: str
      weight,  # type: float
      weight_range,  # type: float
  ):
      # type: (...) -> str
      """Return token wrapped in a span with some styles
      (calculated from weight and weight_range) applied.
      """
      token = html_escape(token)
      if np.isclose(weight, 0.0):
          return (
              "<span "
              'style="opacity: {opacity}"'
              ">{token}</span>".format(
                  opacity=_weight_opacity(weight, weight_range),
                  token=token,
              )
          )
      else:
          return (
              "<span "
              'style="background-color: {color}; opacity: {opacity}" '
              'title="{weight:.3f}"'
              ">{token}</span>".format(
                  color=format_hsl(
                      weight_color_hsl(
                          weight, weight_range, min_lightness=0.6
                      )
                  ),
                  opacity=_weight_opacity(weight, weight_range),
                  weight=weight,
                  token=token,
              )
          )
  
imports: from __future__ import absolute_import
  from itertools import groupby
  from typing import List, Optional, Tuple
  import numpy
  from jinja2 import Environment, PackageLoader
  from eli5 import _graphviz
  from eli5.base import Explanation, TargetExplanation, FeatureWeights, FeatureWeight
  from eli5.utils import max_or_0
  from .utils import format_signed, format_value, format_weight, has_any_values_for_weights, replace_spaces, should_highlight_spaces
  from .None import fields
  from .features import FormattedFeatureName
  from .trees import tree2text
  from .text_helpers import prepare_weighted_spans, PreparedWeightedSpans
label_desc: Use image node_id 5 for calling a global function with example usage: _colorize(token, weight, weight_range) and returns: str, str