<jupyter_start><jupyter_text>Load and preprocess the data<jupyter_code>graph = load_dataset('data/cora.npz')
adj_matrix = graph['adj_matrix']
labels = graph['labels']

adj_matrix, labels = standardize(adj_matrix, labels)
n_nodes = adj_matrix.shape[0]<jupyter_output><empty_output><jupyter_text>Set hyperparameters<jupyter_code>n_flips = 1000
dim = 32
window_size = 5<jupyter_output><empty_output><jupyter_text>Generate candidate edge flips<jupyter_code>candidates = generate_candidates_removal(adj_matrix=adj_matrix)<jupyter_output><empty_output><jupyter_text>Compute simple baselines<jupyter_code>b_eig_flips = baseline_eigencentrality_top_flips(adj_matrix, candidates, n_flips)
b_deg_flips = baseline_degree_top_flips(adj_matrix, candidates, n_flips, True)
b_rnd_flips = baseline_random_top_flips(candidates, n_flips, 0)<jupyter_output><empty_output><jupyter_text>Compute adversarial flips using eigenvalue perturbation<jupyter_code>our_flips = perturbation_top_flips(adj_matrix, candidates, n_flips, dim, window_size)<jupyter_output><empty_output><jupyter_text>Evaluate classification performance using the skipgram objective<jupyter_code>for flips, name in zip([None, b_rnd_flips, b_deg_flips, None, our_flips],
                             ['cln', 'rnd', 'deg', 'eig', 'our']):
    
    if flips is not None:
        adj_matrix_flipped = flip_candidates(adj_matrix, flips)
    else:
        adj_matrix_flipped = adj_matrix
        
    embedding = deepwalk_skipgram(adj_matrix_flipped, dim, window_size=window_size)
    f1_scores_mean, _ = evaluate_embedding_node_classification(embedding, labels)
    print('{}, F1: {:.2f} {:.2f}'.format(name, f1_scores_mean[0], f1_scores_mean[1]))<jupyter_output>cln, F1: 0.81 0.78
rnd, F1: 0.80 0.77
deg, F1: 0.77 0.74
eig, F1: 0.81 0.78
our, F1: 0.72 0.69<jupyter_text>Evaluate classification performance using the SVD objective<jupyter_code>for flips, name in zip([None, b_rnd_flips, b_deg_flips, None, our_flips],
                             ['cln', 'rnd', 'deg', 'eig', 'our']):
    
    if flips is not None:
        adj_matrix_flipped = flip_candidates(adj_matrix, flips)
    else:
        adj_matrix_flipped = adj_matrix
        
    embedding, _, _, _ = deepwalk_svd(adj_matrix_flipped, window_size, dim)
    f1_scores_mean, _ = evaluate_embedding_node_classification(embedding, labels)
    print('{}, F1: {:.2f} {:.2f}'.format(name, f1_scores_mean[0], f1_scores_mean[1]))<jupyter_output>cln, F1: 0.82 0.80
rnd, F1: 0.81 0.79
deg, F1: 0.79 0.76
eig, F1: 0.82 0.80
our, F1: 0.76 0.74
{'fraction_non_alphanumeric': 0.11527832609553888, 'fraction_numerical': 0.03750493485984998, 'mean_word_length': 5.530927835051546, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '246460', 'license': 'MIT', 'n_tokens_mistral': 1038, 'n_tokens_neox': 971, 'n_words': 174, 'path': 'example.ipynb', 'repo_name': 'AndreamApp/node_embedding_attack', 'size': '2533'}