def raw_data_to_graph_to_output_example(self, raw_data):
    # pylint: disable=line-too-long
    """Convert raw data to the unified GraphToOutputExample data structure.

    The Code2Seq raw data contains the target function name, and the sampled
    AST paths. Each AST path starts and ends with a token, and a series of
    AST nodes that connects the two tokens. We use _construct_token_subtree
    to build the token subtree and _construct_ast_nodes_subtree to build the
    AST nodes subtree. Then, all AST paths' nodes are connected to a AST root
    node.
    All AST root nodes are connected to a single code2seq root node.
    https://drive.google.com/file/d/1-cH0FzYIMikgTkUpzVkEZDGjoiqBB9C1/view?usp=sharing
    shows an example of such a graph and the original AST path.

    Args:
      raw_data: A dictionary with 'split', 'target_label' and 'ast_paths' as keys.
        The value of the 'split' field is the split (train/valid/test) that the
        data belongs to. The value of the 'target_label' field is the function
        name. The value of the 'ast_paths' field is a list of AST paths.

    Raises:
      GraphToOutputExampleNotValidError if the GraphToOutputExample is not
      valid.

    Returns:
      A dictionary with keys 'split' and 'GraphToOutputExample'. Values are the
      split(train/validation/test) the data belongs to, and the
      GraphToOutputExample instance.
    """
    # pylint: enable=line-too-long
    split = raw_data['split']
    target_label = raw_data['target_label']
    ast_paths = raw_data['ast_paths']
    graph_to_output_example = GraphToOutputExample()

    cur_node_id = 0
    ast_path_root_node_ids = []

    # This is the root node of all AST path nodes.
    graph_to_output_example.add_node(cur_node_id, 'C2C_ROOT', 'C2C_ROOT')
    c2c_root_node_id = cur_node_id
    cur_node_id += 1

    for ast_path in ast_paths:
      # The start_token subtree
      start_token = ast_path[0]
      graph_to_output_example, cur_node_id, start_token_node_id = (
          self._construct_token_subtree(
              graph_to_output_example, start_token, cur_node_id, 'START_TOKEN'))

      # The ast_nodes subtree
      ast_nodes = ast_path[1]
      graph_to_output_example, cur_node_id, ast_node_ids = (
          self._construct_ast_nodes_subtree(
              graph_to_output_example, ast_nodes, cur_node_id))

      # The end_token subtree
      end_token = ast_path[2]
      graph_to_output_example, cur_node_id, end_token_node_id = (
          self._construct_token_subtree(
              graph_to_output_example, end_token, cur_node_id, 'END_TOKEN'))

      # Connects the start_token root node with the first node in the
      # ast_nodes subtree.
      graph_to_output_example.add_edge(
          start_token_node_id, ast_node_ids[0], 'START_AST_PATH')
      # Connects the end_token root node with the last node in the
      # ast_nodes subtree.
      graph_to_output_example.add_edge(
          end_token_node_id, ast_node_ids[-1], 'END_AST_PATH')

      # Add a root AST path node representing the AST path.
      graph_to_output_example.add_node(
          cur_node_id, 'ROOT_AST_PATH', 'ROOT_AST_PATH')
      ast_path_root_node_id = cur_node_id
      ast_path_root_node_ids.append(ast_path_root_node_id)
      cur_node_id += 1

      # Connects the root AST path node with the start_token and end_token
      # subtree.
      graph_to_output_example.add_edge(
          ast_path_root_node_id, start_token_node_id, 'START_TOKEN')
      graph_to_output_example.add_edge(
          ast_path_root_node_id, end_token_node_id, 'END_TOKEN')
      # Connects the root AST path node with all nodes in the ast_nodes subtree.
      for node_id in ast_node_ids:
        graph_to_output_example.add_edge(ast_path_root_node_id, node_id,
                                         'AST_NODE')

    # Connects the code2seq root node with all AST path root node.
    for ast_path_root_node_id in ast_path_root_node_ids:
      graph_to_output_example.add_edge(c2c_root_node_id, ast_path_root_node_id,
                                       'AST_PATH')

    for subtoken in target_label.split('|'):
      graph_to_output_example.add_token_output(subtoken)

    for transformation_fn in self.transformation_funcs:
      graph_to_output_example = transformation_fn(graph_to_output_example)

    if not graph_to_output_example.check_if_valid():
      raise GraphToOutputExampleNotValidError(
          'Invalid GraphToOutputExample found {}'.format(
              graph_to_output_example))

    for filter_fn in self.filter_funcs:
      if not filter_fn(graph_to_output_example):
        graph_to_output_example = None
        break

    return {'split': split, 'GraphToOutputExample': graph_to_output_example}