Implementation and experiments of graph embedding algorithms.
Go to file
2020-07-21 11:15:22 -07:00
data Add flight data 2019-02-14 21:22:18 +08:00
examples add rejection sampling for node2vec 2020-05-24 16:29:52 +08:00
ge Fix KeyError seen during node2vec by allowing walker to initialize both directions of non-directed graph edges. 2020-07-21 11:15:22 -07:00
pics no message 2020-05-30 13:07:36 +08:00
.gitattributes Initial commit 2019-02-12 00:25:52 +08:00
.gitignore Initial commit 2019-02-12 00:25:52 +08:00
LICENSE Initial commit 2019-02-12 00:25:52 +08:00
README.md update 2019-11-04 02:26:53 +08:00
setup.py Update setup.py 2019-07-21 13:11:24 +08:00

GraphEmbedding

Method

Model Paper Note
DeepWalk [KDD 2014]DeepWalk: Online Learning of Social Representations 【Graph Embedding】DeepWalk算法原理实现和应用
LINE [WWW 2015]LINE: Large-scale Information Network Embedding 【Graph Embedding】LINE算法原理实现和应用
Node2Vec [KDD 2016]node2vec: Scalable Feature Learning for Networks 【Graph Embedding】Node2Vec算法原理实现和应用
SDNE [KDD 2016]Structural Deep Network Embedding 【Graph Embedding】SDNE算法原理实现和应用
Struc2Vec [KDD 2017]struc2vec: Learning Node Representations from Structural Identity 【Graph Embedding】Struc2Vec算法原理实现和应用

How to run examples

  1. clone the repo and make sure you have installed tensorflow or tensorflow-gpu on your local machine.
  2. run following commands
python setup.py install
cd examples
python deepwalk_wiki.py

DisscussionGroup

  • 公众号:浅梦的学习笔记 wechat ID: deepctrbot wechat

Usage

The design and implementation follows simple principles(graph in,embedding out) as much as possible.

Input format

we use networkxto create graphs.The input of networkx graph is as follows: node1 node2 <edge_weight>

DeepWalk

G = nx.read_edgelist('../data/wiki/Wiki_edgelist.txt',create_using=nx.DiGraph(),nodetype=None,data=[('weight',int)])# Read graph

model = DeepWalk(G,walk_length=10,num_walks=80,workers=1)#init model
model.train(window_size=5,iter=3)# train model
embeddings = model.get_embeddings()# get embedding vectors

LINE

G = nx.read_edgelist('../data/wiki/Wiki_edgelist.txt',create_using=nx.DiGraph(),nodetype=None,data=[('weight',int)])#read graph

model = LINE(G,embedding_size=128,order='second') #init model,order can be ['first','second','all']
model.train(batch_size=1024,epochs=50,verbose=2)# train model
embeddings = model.get_embeddings()# get embedding vectors

Node2Vec

G=nx.read_edgelist('../data/wiki/Wiki_edgelist.txt',
                        create_using = nx.DiGraph(), nodetype = None, data = [('weight', int)])#read graph

model = Node2Vec(G, walk_length = 10, num_walks = 80,p = 0.25, q = 4, workers = 1)#init model
model.train(window_size = 5, iter = 3)# train model
embeddings = model.get_embeddings()# get embedding vectors

SDNE

G = nx.read_edgelist('../data/wiki/Wiki_edgelist.txt',create_using=nx.DiGraph(),nodetype=None,data=[('weight',int)])#read graph

model = SDNE(G,hidden_size=[256,128]) #init model
model.train(batch_size=3000,epochs=40,verbose=2)# train model
embeddings = model.get_embeddings()# get embedding vectors

Struc2Vec

G = nx.read_edgelist('../data/flight/brazil-airports.edgelist',create_using=nx.DiGraph(),nodetype=None,data=[('weight',int)])#read graph

model = model = Struc2Vec(G, 10, 80, workers=4, verbose=40, ) #init model
model.train(window_size = 5, iter = 3)# train model
embeddings = model.get_embeddings()# get embedding vectors