# GraphEmbedding
[![GitHub Issues](https://img.shields.io/github/issues/shenweichen/graphembedding.svg
)](https://github.com/shenweichen/graphembedding/issues)
![CI status](https://github.com/shenweichen/graphembedding/workflows/CI/badge.svg)
[![codecov](https://codecov.io/gh/shenweichen/graphembedding/branch/master/graph/badge.svg)](https://codecov.io/gh/shenweichen/graphembedding)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/c46407f5931f40048e28860dccf7dabc)](https://www.codacy.com/gh/shenweichen/GraphEmbedding/dashboard?utm_source=github.com&utm_medium=referral&utm_content=shenweichen/GraphEmbedding&utm_campaign=Badge_Grade)
[![Disscussion](https://img.shields.io/badge/chat-wechat-brightgreen?style=flat)](./README.md#disscussiongroup--related-projects)
[comment]: <> ([![License](https://img.shields.io/github/license/shenweichen/graphembedding.svg)](https://github.com/shenweichen/graphembedding/blob/master/LICENSE))
# Method
| Model | Paper | Note |
| :-------: | :------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------ |
| DeepWalk | [KDD 2014][DeepWalk: Online Learning of Social Representations](http://www.perozzi.net/publications/14_kdd_deepwalk.pdf) | [【Graph Embedding】DeepWalk:算法原理,实现和应用](https://zhuanlan.zhihu.com/p/56380812) |
| LINE | [WWW 2015][LINE: Large-scale Information Network Embedding](https://arxiv.org/pdf/1503.03578.pdf) | [【Graph Embedding】LINE:算法原理,实现和应用](https://zhuanlan.zhihu.com/p/56478167) |
| Node2Vec | [KDD 2016][node2vec: Scalable Feature Learning for Networks](https://www.kdd.org/kdd2016/papers/files/rfp0218-groverA.pdf) | [【Graph Embedding】Node2Vec:算法原理,实现和应用](https://zhuanlan.zhihu.com/p/56542707) |
| SDNE | [KDD 2016][Structural Deep Network Embedding](https://www.kdd.org/kdd2016/papers/files/rfp0191-wangAemb.pdf) | [【Graph Embedding】SDNE:算法原理,实现和应用](https://zhuanlan.zhihu.com/p/56637181) |
| Struc2Vec | [KDD 2017][struc2vec: Learning Node Representations from Structural Identity](https://arxiv.org/pdf/1704.03165.pdf) | [【Graph Embedding】Struc2Vec:算法原理,实现和应用](https://zhuanlan.zhihu.com/p/56733145) |
# 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
```bash
python setup.py install
cd examples
python deepwalk_wiki.py
```
## DisscussionGroup & Related Projects
<html>
<table style="margin-left: 20px; margin-right: auto;">
<tr>
<td>
公众号:<b>浅梦学习笔记</b><br><br>
<a href="https://github.com/shenweichen/GraphEmbedding">
<img align="center" src="./pics/code.png" />
</a>
</td>
<td>
微信:<b>deepctrbot</b><br><br>
<a href="https://github.com/shenweichen/GraphEmbedding">
<img align="center" src="./pics/deepctrbot.png" />
</a>
</td>
<td>
<ul>
<li><a href="https://github.com/shenweichen/AlgoNotes">AlgoNotes</a></li>
<li><a href="https://github.com/shenweichen/DeepCTR">DeepCTR</a></li>
<li><a href="https://github.com/shenweichen/DeepMatch">DeepMatch</a></li>
<li><a href="https://github.com/shenweichen/DeepCTR-Torch">DeepCTR-Torch</a></li>
</ul>
</td>
</tr>
</table>
</html>
# Usage
The design and implementation follows simple principles(**graph in,embedding out**) as much as possible.
## Input format
we use `networkx`to create graphs.The input of networkx graph is as follows:
`node1 node2 <edge_weight>`
![](./pics/edge_list.png)
## DeepWalk
```python
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
```python
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
```python
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
```python
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
```python
G = nx.read_edgelist('../data/flight/brazil-airports.edgelist',create_using=nx.DiGraph(),nodetype=None,data=[('weight',int)])#read graph
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
```
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
GraphEmbedding-master.zip (44个子文件)
GraphEmbedding-master
GraphEmbedding-master
ge
utils.py 1KB
__init__.py 21B
walker.py 10KB
models
__init__.py 207B
deepwalk.py 2KB
struc2vec.py 14KB
sdne.py 6KB
node2vec.py 2KB
line.py 7KB
classify.py 3KB
alias.py 1KB
setup.py 818B
.github
workflows
ci.yml 2KB
.gitattributes 66B
data
flight
usa-airports.edgelist 159KB
labels-europe-airports.txt 2KB
labels-usa-airports.txt 9KB
labels-brazil-airports.txt 687B
brazil-airports.edgelist 6KB
europe-airports.edgelist 39KB
wiki
wiki_labels.txt 16KB
Wiki_edgelist.txt 158KB
Wiki_category.txt 16KB
LICENSE 1KB
tests
__init__.py 0B
deepwalk_test.py 396B
sdne_test.py 459B
Wiki_edgelist.txt 19B
line_test.py 391B
struct2vec_test.py 370B
node2vec_test.py 596B
examples
deepwalk_wiki.py 1KB
node2vec_wiki.py 2KB
struc2vec_flight.py 2KB
node2vec_flight.py 2KB
line_wiki.py 1KB
sdne_wiki.py 1KB
alias.py 690B
pics
edge_list.png 26KB
deepctrbot.png 21KB
code.png 29KB
weichennote.png 69KB
.gitignore 1KB
README.md 6KB
共 44 条
- 1
资源评论
追光者♂
- 粉丝: 2w+
- 资源: 516
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功