code: def load_conllu(file):
      # pylint: disable=too-many-locals
      # pylint: disable=too-many-branches
      # pylint: disable=too-many-statements
  
      # Internal representation classes
      class UDRepresentation:
          # pylint: disable=too-few-public-methods
          def __init__(self):
              # Characters of all the tokens in the whole file.
              # Whitespace between tokens is not included.
              self.characters = []
              # List of UDSpan instances with start&end indices into `characters`
              self.tokens = []
              # List of UDWord instances.
              self.words = []
              # List of UDSpan instances with start&end indices into `characters`
              self.sentences = []
  
      class UDSpan:
          # pylint: disable=too-few-public-methods
          def __init__(self, start, end):
              self.start = start
              # Note that self.end marks the first position **after the end** of
              # span, so we can use characters[start:end] or range(start, end).
              self.end = end
  
      class UDWord:
          # pylint: disable=too-few-public-methods
          def __init__(self, span, columns, is_multiword):
              # Span of this word (or MWT, see below) within
              # ud_representation.characters.
              self.span = span
              # 10 columns of the CoNLL-U file: ID, FORM, LEMMA,...
              self.columns = columns
              # is_multiword==True means that this word is part of a multi-word
              # token.
              # In that case, self.span marks the span of the whole multi-word
              # token.
              self.is_multiword = is_multiword
              # Reference to the UDWord instance representing the HEAD (or None
              # if root).
              self.parent = None
              # Let's ignore language-specific deprel subtypes.
              self.columns[DEPREL] = columns[DEPREL].split(":")[0]
  
      ud = UDRepresentation()
  
      # Load the CoNLL-U file
      index, sentence_start = 0, None
      while True:
          line = file.readline()
          if not line:
              break
          line = line.rstrip("\r\n")
  
          # Handle sentence start boundaries
          if sentence_start is None:
              # Skip comments
              if line.startswith("#"):
                  continue
              # Start a new sentence
              ud.sentences.append(UDSpan(index, 0))
              sentence_start = len(ud.words)
          if not line:
              # Add parent UDWord links and check there are no cycles
              def process_word(word):
                  if word.parent == "remapping":
                      raise UDError("There is a cycle in a sentence")
                  if word.parent is None:
                      head = int(word.columns[HEAD])
                      if head > len(ud.words) - sentence_start:
                          raise UDError(
                              "HEAD '{}' points outside of the sentence".format(
                                  word.columns[HEAD]
                              )
                          )
                      if head:
                          parent = ud.words[sentence_start + head - 1]
                          word.parent = "remapping"
                          process_word(parent)
                          word.parent = parent
  
              for word in ud.words[sentence_start:]:
                  process_word(word)
  
              # Check there is a single root node
              if (
                  len(
                      [
                          word
                          for word in ud.words[sentence_start:]
                          if word.parent is None
                      ]
                  )
                  != 1
              ):
                  raise UDError(
                      "There are multiple roots in a sentence"
                  )
  
              # End the sentence
              ud.sentences[-1].end = index
              sentence_start = None
              continue
  
          # Read next token/word
          columns = line.split("\t")
          if len(columns) != 10:
              raise UDError(
                  "The CoNLL-U line does not contain 10 tab-separated columns: "
                  "'{}'".format(line)
              )
  
          # Skip empty nodes
          if "." in columns[ID]:
              continue
  
          # Delete spaces from FORM  so gold.characters == system.characters
          # even if one of them tokenizes the space.
          columns[FORM] = columns[FORM].replace(" ", "")
          if not columns[FORM]:
              raise UDError(
                  "There is an empty FORM in the CoNLL-U file"
              )
  
          # Save token
          ud.characters.extend(columns[FORM])
          ud.tokens.append(UDSpan(index, index + len(columns[FORM])))
          index += len(columns[FORM])
  
          # Handle multi-word tokens to save word(s)
          if "-" in columns[ID]:
              try:
                  start, end = list(map(int, columns[ID].split("-")))
              except Exception:
                  raise UDError(
                      "Cannot parse multi-word token ID '{}'".format(
                          columns[ID]
                      )
                  )
  
              for _ in range(start, end + 1):
                  word_line = file.readline().rstrip("\r\n")
                  word_columns = word_line.split("\t")
                  if len(word_columns) != 10:
                      raise UDError(
                          "The CoNLL-U line does not contain 10 tab-separated "
                          "columns: '{}'".format(word_line)
                      )
                  ud.words.append(
                      UDWord(
                          ud.tokens[-1], word_columns, is_multiword=True
                      )
                  )
          # Basic tokens/words
          else:
              try:
                  word_id = int(columns[ID])
              except Exception:
                  raise UDError(
                      "Cannot parse word ID '{}'".format(columns[ID])
                  )
              if word_id != len(ud.words) - sentence_start + 1:
                  raise UDError(
                      "Incorrect word ID '{}' for word '{}', expected"
                      " '{}'".format(
                          columns[ID],
                          columns[FORM],
                          len(ud.words) - sentence_start + 1,
                      )
                  )
  
              try:
                  head_id = int(columns[HEAD])
              except Exception:
                  raise UDError(
                      "Cannot parse HEAD '{}'".format(columns[HEAD])
                  )
              if head_id < 0:
                  raise UDError("HEAD cannot be negative")
  
              ud.words.append(
                  UDWord(ud.tokens[-1], columns, is_multiword=False)
              )
  
      if sentence_start is not None:
          raise UDError("The CoNLL-U file does not end with empty line")
  
      return ud
  
file_path: nlp-architect/nlp_architect/models/bist/eval/conllu/conll17_ud_eval.py
imports: import os
  import sys
label_desc: Use image node_id 1 for calling a global function with example usage: load_conllu(file) and returns: ud