def node_label_as_feature(dataset: LegacyTUDataset, mode="concat", save=True):
    """
    Description
    -----------
    Add node labels to graph node features dict

    Parameters
    ----------
    dataset : LegacyTUDataset
        The dataset object
    concat : str, optional
        How to add node label to the graph. Valid options are "add",
        "replace" and "concat".
        - "add": Directly add node_label to graph node feature dict.
        - "concat": Concatenate "feat" and "node_label"
        - "replace": Use "node_label" as "feat"
        Default: :obj:`"concat"`
    save : bool, optional
        Save the result dataset.
        Default: :obj:`True`
    """
    # check if node label is not available
    if (
        not os.path.exists(dataset._file_path("node_labels"))
        or len(dataset) == 0
    ):
        logging.warning("No Node Label Data")
        return dataset

    # check if has cached value
    check_mark_name = "node_label_as_feature"
    check_mark_path = os.path.join(
        dataset.save_path, "info_{}_{}.json".format(dataset.name, dataset.hash)
    )
    check_mark = _load_check_mark(check_mark_path)
    if (
        check_mark_name in check_mark
        and check_mark[check_mark_name]
        and not dataset._force_reload
    ):
        logging.warning("Using cached value in node_label_as_feature")
        return dataset
    logging.warning(
        "Adding node labels into node features..., mode={}".format(mode)
    )

    # check if graph has "feat"
    if "feat" not in dataset[0][0].ndata:
        logging.warning("Dataset has no node feature 'feat'")
        if mode.lower() == "concat":
            mode = "replace"

    # first read node labels
    DS_node_labels = dataset._idx_from_zero(
        np.loadtxt(dataset._file_path("node_labels"), dtype=int)
    )
    one_hot_node_labels = dataset._to_onehot(DS_node_labels)

    # read graph idx
    DS_indicator = dataset._idx_from_zero(
        np.genfromtxt(dataset._file_path("graph_indicator"), dtype=int)
    )
    node_idx_list = []
    for idx in range(np.max(DS_indicator) + 1):
        node_idx = np.where(DS_indicator == idx)
        node_idx_list.append(node_idx[0])

    # add to node feature dict
    for idx, g in zip(node_idx_list, dataset.graph_lists):
        node_labels_tensor = torch.tensor(one_hot_node_labels[idx, :])
        if mode.lower() == "concat":
            g.ndata["feat"] = torch.cat(
                (g.ndata["feat"], node_labels_tensor), dim=1
            )
        elif mode.lower() == "add":
            g.ndata["node_label"] = node_labels_tensor
        else:  # replace
            g.ndata["feat"] = node_labels_tensor

    if save:
        check_mark[check_mark_name] = True
        _save_check_mark(check_mark_path, check_mark)
        dataset.save()
    return dataset

    Description
    -----------
    Add node labels to graph node features dict

    Parameters
    ----------
    dataset : LegacyTUDataset
        The dataset object
    concat : str, optional
        How to add node label to the graph. Valid options are "add",
        "replace" and "concat".
        - "add": Directly add node_label to graph node feature dict.
        - "concat": Concatenate "feat" and "node_label"
        - "replace": Use "node_label" as "feat"
        Default: :obj:`"concat"`
    save : bool, optional
        Save the result dataset.
        Default: :obj:`True`
    
examples/pytorch/gxn/data_preprocess.py