code: def attach_dependencies(doc, response):
      if len(doc.sentences) != len(response.conversions):
          raise ValueError(
              "Sent %d sentences but got back %d conversions"
              % (len(doc.sentences), len(response.conversions))
          )
      for sent_idx, (sentence, conversion) in enumerate(
          zip(doc.sentences, response.conversions)
      ):
          graph = conversion.graph
  
          # The deterministic conversion should have an equal number of words and one fewer edge
          # ... the root is represented by a word with no parent
          if len(sentence.words) != len(graph.node):
              raise ValueError(
                  "Sentence %d of the conversion should have %d words but got back %d nodes in the graph"
                  % (sent_idx, len(sentence.words), len(graph.node))
              )
          if len(sentence.words) != len(graph.edge) + 1:
              raise ValueError(
                  "Sentence %d of the conversion should have %d edges (one per word, plus the root) but got back %d edges in the graph"
                  % (sent_idx, len(sentence.words) - 1, len(graph.edge))
              )
  
          expected_nodes = set(range(1, len(sentence.words) + 1))
          targets = set()
          for edge in graph.edge:
              if edge.target in targets:
                  raise ValueError(
                      "Found two parents of %d in sentence %d"
                      % (edge.target, sent_idx)
                  )
              targets.add(edge.target)
              # -1 since the words are 0 indexed in the sentence,
              # but we count dependencies from 1
              sentence.words[edge.target - 1].head = edge.source
              sentence.words[edge.target - 1].deprel = edge.dep
          roots = expected_nodes - targets
          assert len(roots) == 1
          for root in roots:
              sentence.words[root - 1].head = 0
              sentence.words[root - 1].deprel = "root"
          sentence.build_dependencies()
  
file_path: stanza/stanza/server/dependency_converter.py
imports: import stanza
  from stanza.protobuf import DependencyConverterRequest, DependencyConverterResponse
  from stanza.server.java_protobuf_requests import send_request, build_tree, JavaProtobufContext
label_desc: Use image node_id 4 for calling a global function with example usage: attach_dependencies(doc, response) without return types