code: def visualize_doc(doc, language):
      """
      Takes in a Document and visualizes it using displacy.
  
      The document to visualize must be from the stanza pipeline.
  
      right-to-left languages such as Arabic are displayed right-to-left based on the language code
      """
      visualization_options = {
          "compact": True,
          "bg": "#09a3d5",
          "color": "white",
          "distance": 90,
          "font": "Source Sans Pro",
          "arrow_spacing": 25,
      }
      # blank model - we don't use any of the model features, just the viz
      nlp = spacy.blank("en")
      sentences_to_visualize = []
      for sentence in doc.sentences:
          words, lemmas, heads, deps, tags = [], [], [], [], []
          if is_right_to_left(
              language
          ):  # order of words displayed is reversed, dependency arcs remain intact
              sent_len = len(sentence.words)
              for word in reversed(sentence.words):
                  words.append(word.text)
                  lemmas.append(word.lemma)
                  deps.append(word.deprel)
                  tags.append(word.upos)
                  if (
                      word.head == 0
                  ):  # spaCy head indexes are formatted differently than that of Stanza
                      heads.append(sent_len - word.id)
                  else:
                      heads.append(sent_len - word.head)
          else:  # left to right rendering
              for word in sentence.words:
                  words.append(word.text)
                  lemmas.append(word.lemma)
                  deps.append(word.deprel)
                  tags.append(word.upos)
                  if word.head == 0:
                      heads.append(word.id - 1)
                  else:
                      heads.append(word.head - 1)
          document_result = Doc(
              nlp.vocab,
              words=words,
              lemmas=lemmas,
              heads=heads,
              deps=deps,
              pos=tags,
          )
          sentences_to_visualize.append(document_result)
  
      for (
          line
      ) in (
          sentences_to_visualize
      ):  # render all sentences through displaCy
          # If this program is NOT being run in a Jupyter notebook, replace displacy.render with displacy.serve
          # and the visualization will be hosted locally, link being provided in the program output.
          displacy.render(
              line, style="dep", options=visualization_options
          )
  
file_path: stanza/stanza/utils/visualization/dependency_visualization.py
imports: from stanza.models.common.constant import is_right_to_left
  import stanza
  import spacy
  from spacy import displacy
  from spacy.tokens import Doc
label_desc: Use image node_id 1 for calling a global function with example usage: visualize_doc(doc, language) without return types