[Python] Node/edge attributed directed graph embedding

Discussão em 'Python' iniciado por Stack, Março 14, 2025.

  1. Stack

    Stack Membro Participativo

    What is the format of node features that graph2vec and GL2vec in karateclub require? It does mention that there should be no string features but with or without it I am running into an error with the following code:

    import networkx as nx
    import karateclub as kc
    import matplotlib.pyplot as plt

    G = nx.DiGraph()

    G.add_node(0, label = "A", feature=[0.5])
    G.add_node(1, label = "B", feature=[1.2])
    G.add_node(2, label = "C", feature=[0.8])

    G.add_edge(0, 1)
    G.add_edge(0, 2)
    G.add_edge(1, 2)

    nx.draw_networkx(G, with_labels=True)
    plt.show()

    graphs = [G]

    model = kc.graph_embedding.Graph2Vec()
    model.fit(graphs)
    embeddings = model.get_embedding()
    print(embeddings)


    Error: RuntimeError: you must first build vocabulary before training the model

    I saw an option to build_vocab in word2vec, but how do I do it for graph2vec?

    Are there any alternate packages, preferably with simpler implementations like karateclub, that I can use to generate embeddings for a list of directed node/edge attributed networkx graphs without the need to define training/test sets?

    Continue reading...

Compartilhe esta Página