code: def n_syllables_per_word(
      doc_or_tokens: types.DocOrTokens, *, lang: Optional[str] = None
  ) -> tuple[int, ...]:
      """
      Compute the number of syllables for each word in a document.
  
      Args:
          doc_or_tokens: If a spaCy ``Doc``, non-punctuation tokens (words) are extracted;
              if an iterable of spaCy ``Token`` s, all non-punct elements are used.
          lang: Standard 2-letter language code used to load hyphenator.
              If not specified and ``doc_or_tokens`` is a spaCy ``Doc`` ,
              the value will be gotten from ``Doc.lang_`` .
  
      Note:
          Identifying syllables is _tricky_; this method relies on hyphenation, which is
          more straightforward but doesn't always give the correct number of syllables.
          While all hyphenation points fall on syllable divisions, not all syllable
          divisions are valid hyphenation points.
  
          Also: This function is cached, since other functions rely upon its outputs
          to compute theirs. As such, ``doc_or_tokens`` must be hashable -- for example,
          it may be a ``Doc`` or ``tuple[Token, ...]`` , but not a ``List[Token]`` .
      """
      if lang is None:
          if isinstance(doc_or_tokens, Doc):
              lang = doc_or_tokens.lang_
          else:
              raise ValueError(
                  "`lang` must be specified when computing n syllables per word "
                  "from an iterable of tokens"
              )
      hyphenator = utils.load_hyphenator(lang=lang)
      words = utils.get_words(doc_or_tokens)
      return tuple(
          len(hyphenator.positions(word.lower_)) + 1 for word in words
      )
  
imports: from __future__ import annotations
  import functools
  import logging
  import math
  from typing import Optional
  import spacy.pipeline
  from cytoolz import itertoolz
  from spacy.tokens import Doc
  from ..None import types
  from .None import utils
label_desc: Use image node_id 7 for calling a global function with example usage: n_syllables_per_word(doc_or_tokens) and returns: tuple