code: def _mtld_run(words: Iterable[Token], min_ttr: float) -> float:
      n_factors = 0.0
      n_factor_words = 0
      factor_types = set()
      for n, word in enumerate(words):
          n_factor_words += 1
          factor_types.add(word.lower)
          ttr = len(factor_types) / n_factor_words
          if ttr < min_ttr:
              n_factors += 1.0
              n_factor_words = 0
              factor_types.clear()
      n_words = n + 1
      # do we have a partial factor left over? don't throw it away!
      # instead, add a fractional factor value corresponding to how far TTR is from 1.0
      # compared to how far min_ttr is from 1.0
      if n_factor_words > 0:
          n_factors += (1.0 - ttr) / (1 - min_ttr)
      # to avoid ZeroDivisionError in case of a single, partial factor with TTR == 1.0
      # we add a small constant; but tbh this is a weird case
      return n_words / (n_factors + 1e-6)
  
file_path: textacy/src/textacy/text_stats/diversity.py
imports: from __future__ import annotations
  import logging
  import math
  import statistics
  from typing import Iterable, Literal
  from scipy.stats import hypergeom
  from spacy.tokens import Token
  from toolz import itertoolz
  from ..None import errors, types
  from .None import utils
label_desc: Use image node_id 5 for calling a global function with example usage: _mtld_run(words, min_ttr) and returns: unknown