2018-04-08 DeepWalk代码调试

代码地址:https://github.com/phanein/deepwalk

安装步骤:
1.cd deepwalk

2.pip install -r requirements.txt

3.python setup.py install

lijuncheng@lijunchengdeMacBook-Pro ~/Desktop/DeepWalk/代码/deepwalk/deepwalk (master*) $ cd ..
lijuncheng@lijunchengdeMacBook-Pro ~/Desktop/DeepWalk/代码/deepwalk (master*) $ pip install -r requirements.txt
Requirement already satisfied: wheel>=0.23.0 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from -r requirements.txt (line 1))
Requirement already satisfied: Cython>=0.20.2 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from -r requirements.txt (line 2))
Collecting argparse>=1.2.1 (from -r requirements.txt (line 3))
  Downloading argparse-1.4.0-py2.py3-none-any.whl
Collecting futures>=2.1.6 (from -r requirements.txt (line 4))
  Downloading futures-3.1.1.tar.gz
Requirement already satisfied: six>=1.7.3 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from -r requirements.txt (line 5))
Requirement already satisfied: gensim>=1.0.0 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from -r requirements.txt (line 6))
Requirement already satisfied: scipy>=0.15.0 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from -r requirements.txt (line 7))
Requirement already satisfied: psutil>=2.1.1 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from -r requirements.txt (line 8))
Requirement already satisfied: numpy>=1.11.3 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: smart-open>=1.2.1 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: boto3 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from smart-open>=1.2.1->gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: boto>=2.32 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from smart-open>=1.2.1->gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: requests in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from smart-open>=1.2.1->gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: bz2file in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from smart-open>=1.2.1->gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: botocore<1.11.0,>=1.10.2 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from boto3->smart-open>=1.2.1->gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from boto3->smart-open>=1.2.1->gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: s3transfer<0.2.0,>=0.1.10 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from boto3->smart-open>=1.2.1->gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from requests->smart-open>=1.2.1->gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: idna<2.7,>=2.5 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from requests->smart-open>=1.2.1->gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from requests->smart-open>=1.2.1->gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: certifi>=2017.4.17 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from requests->smart-open>=1.2.1->gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: python-dateutil<2.7.0,>=2.1 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from botocore<1.11.0,>=1.10.2->boto3->smart-open>=1.2.1->gensim>=1.0.0->-r requirements.txt (line 6))
Requirement already satisfied: docutils>=0.10 in /Users/lijuncheng/anaconda3/lib/python3.6/site-packages (from botocore<1.11.0,>=1.10.2->boto3->smart-open>=1.2.1->gensim>=1.0.0->-r requirements.txt (line 6))
Building wheels for collected packages: futures
  Running setup.py bdist_wheel for futures ... done
  Stored in directory: /Users/lijuncheng/Library/Caches/pip/wheels/ad/79/48/b32521764d59b16fd1bc0ffd5862f6d3bf770c7d73ea1fb12a
Successfully built futures
Installing collected packages: argparse, futures
Successfully installed argparse-1.4.0 futures-3.1.1
lijuncheng@lijunchengdeMacBook-Pro ~/Desktop/DeepWalk/代码/deepwalk (master*) $ python setup.py install
running install
running bdist_egg
running egg_info
creating deepwalk.egg-info
writing deepwalk.egg-info/PKG-INFO
writing dependency_links to deepwalk.egg-info/dependency_links.txt
writing entry points to deepwalk.egg-info/entry_points.txt
writing requirements to deepwalk.egg-info/requires.txt
writing top-level names to deepwalk.egg-info/top_level.txt
writing manifest file 'deepwalk.egg-info/SOURCES.txt'
reading manifest file 'deepwalk.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
writing manifest file 'deepwalk.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.7-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib
creating build/lib/deepwalk
copying deepwalk/graph.py -> build/lib/deepwalk
copying deepwalk/__init__.py -> build/lib/deepwalk
copying deepwalk/skipgram.py -> build/lib/deepwalk
copying deepwalk/walks.py -> build/lib/deepwalk
copying deepwalk/__main__.py -> build/lib/deepwalk
creating build/bdist.macosx-10.7-x86_64
creating build/bdist.macosx-10.7-x86_64/egg
creating build/bdist.macosx-10.7-x86_64/egg/deepwalk
copying build/lib/deepwalk/graph.py -> build/bdist.macosx-10.7-x86_64/egg/deepwalk
copying build/lib/deepwalk/__init__.py -> build/bdist.macosx-10.7-x86_64/egg/deepwalk
copying build/lib/deepwalk/skipgram.py -> build/bdist.macosx-10.7-x86_64/egg/deepwalk
copying build/lib/deepwalk/walks.py -> build/bdist.macosx-10.7-x86_64/egg/deepwalk
copying build/lib/deepwalk/__main__.py -> build/bdist.macosx-10.7-x86_64/egg/deepwalk
byte-compiling build/bdist.macosx-10.7-x86_64/egg/deepwalk/graph.py to graph.cpython-36.pyc
byte-compiling build/bdist.macosx-10.7-x86_64/egg/deepwalk/__init__.py to __init__.cpython-36.pyc
byte-compiling build/bdist.macosx-10.7-x86_64/egg/deepwalk/skipgram.py to skipgram.cpython-36.pyc
byte-compiling build/bdist.macosx-10.7-x86_64/egg/deepwalk/walks.py to walks.cpython-36.pyc
byte-compiling build/bdist.macosx-10.7-x86_64/egg/deepwalk/__main__.py to __main__.cpython-36.pyc
creating build/bdist.macosx-10.7-x86_64/egg/EGG-INFO
copying deepwalk.egg-info/PKG-INFO -> build/bdist.macosx-10.7-x86_64/egg/EGG-INFO
copying deepwalk.egg-info/SOURCES.txt -> build/bdist.macosx-10.7-x86_64/egg/EGG-INFO
copying deepwalk.egg-info/dependency_links.txt -> build/bdist.macosx-10.7-x86_64/egg/EGG-INFO
copying deepwalk.egg-info/entry_points.txt -> build/bdist.macosx-10.7-x86_64/egg/EGG-INFO
copying deepwalk.egg-info/not-zip-safe -> build/bdist.macosx-10.7-x86_64/egg/EGG-INFO
copying deepwalk.egg-info/requires.txt -> build/bdist.macosx-10.7-x86_64/egg/EGG-INFO
copying deepwalk.egg-info/top_level.txt -> build/bdist.macosx-10.7-x86_64/egg/EGG-INFO
creating dist
creating 'dist/deepwalk-1.0.3-py3.6.egg' and adding 'build/bdist.macosx-10.7-x86_64/egg' to it
removing 'build/bdist.macosx-10.7-x86_64/egg' (and everything under it)
Processing deepwalk-1.0.3-py3.6.egg
creating /Users/lijuncheng/anaconda3/lib/python3.6/site-packages/deepwalk-1.0.3-py3.6.egg
Extracting deepwalk-1.0.3-py3.6.egg to /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Adding deepwalk 1.0.3 to easy-install.pth file
Installing deepwalk script to /Users/lijuncheng/anaconda3/bin

Installed /Users/lijuncheng/anaconda3/lib/python3.6/site-packages/deepwalk-1.0.3-py3.6.egg
Processing dependencies for deepwalk==1.0.3
Searching for psutil==5.4.0
Best match: psutil 5.4.0
Adding psutil 5.4.0 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for scipy==0.19.1
Best match: scipy 0.19.1
Adding scipy 0.19.1 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for gensim==3.4.0
Best match: gensim 3.4.0
Adding gensim 3.4.0 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for six==1.11.0
Best match: six 1.11.0
Adding six 1.11.0 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for futures==3.1.1
Best match: futures 3.1.1
Adding futures 3.1.1 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for argparse==1.4.0
Best match: argparse 1.4.0
Adding argparse 1.4.0 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for Cython==0.26.1
Best match: Cython 0.26.1
Adding Cython 0.26.1 to easy-install.pth file
Installing cygdb script to /Users/lijuncheng/anaconda3/bin
Installing cython script to /Users/lijuncheng/anaconda3/bin
Installing cythonize script to /Users/lijuncheng/anaconda3/bin

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for wheel==0.30.0
Best match: wheel 0.30.0
Adding wheel 0.30.0 to easy-install.pth file
Installing wheel script to /Users/lijuncheng/anaconda3/bin

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for smart-open==1.5.7
Best match: smart-open 1.5.7
Adding smart-open 1.5.7 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for numpy==1.14.0
Best match: numpy 1.14.0
Adding numpy 1.14.0 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for boto3==1.7.2
Best match: boto3 1.7.2
Adding boto3 1.7.2 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for bz2file==0.98
Best match: bz2file 0.98
Adding bz2file 0.98 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for boto==2.48.0
Best match: boto 2.48.0
Adding boto 2.48.0 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for requests==2.18.4
Best match: requests 2.18.4
Adding requests 2.18.4 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for s3transfer==0.1.13
Best match: s3transfer 0.1.13
Adding s3transfer 0.1.13 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for botocore==1.10.2
Best match: botocore 1.10.2
Adding botocore 1.10.2 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for jmespath==0.9.3
Best match: jmespath 0.9.3
Adding jmespath 0.9.3 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for certifi==2018.1.18
Best match: certifi 2018.1.18
Adding certifi 2018.1.18 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for urllib3==1.22
Best match: urllib3 1.22
Adding urllib3 1.22 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for idna==2.6
Best match: idna 2.6
Adding idna 2.6 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for chardet==3.0.4
Best match: chardet 3.0.4
Adding chardet 3.0.4 to easy-install.pth file
Installing chardetect script to /Users/lijuncheng/anaconda3/bin

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for docutils==0.14
Best match: docutils 0.14
Adding docutils 0.14 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Searching for python-dateutil==2.6.1
Best match: python-dateutil 2.6.1
Adding python-dateutil 2.6.1 to easy-install.pth file

Using /Users/lijuncheng/anaconda3/lib/python3.6/site-packages
Finished processing dependencies for deepwalk==1.0.3
lijuncheng@lijunchengdeMacBook-Pro ~/Desktop/DeepWalk/代码/deepwalk (master*) $

修改两处代码

#from . import graph
import deepwalk.graph as graph
#from . import walks as serialized_walks
import deepwalk.walks as serialized_walks
from gensim.models import Word2Vec
from .skipgram import Skipgram

测试运行:

lijuncheng@lijunchengdeMacBook-Pro ~/Desktop/DeepWalk/代码/deepwalk (master*) $
deepwalk --help
usage: deepwalk [-h] [--debug] [--format FORMAT] --input [INPUT] [-l LOG]
                [--matfile-variable-name MATFILE_VARIABLE_NAME]
                [--max-memory-data-size MAX_MEMORY_DATA_SIZE]
                [--number-walks NUMBER_WALKS] --output OUTPUT
                [--representation-size REPRESENTATION_SIZE] [--seed SEED]
                [--undirected UNDIRECTED] [--vertex-freq-degree]
                [--walk-length WALK_LENGTH] [--window-size WINDOW_SIZE]
                [--workers WORKERS]

optional arguments:
  -h, --help            show this help message and exit
  --debug               drop a debugger if an exception is raised. (default:
                        False)
  --format FORMAT       File format of input file (default: adjlist)
  --input [INPUT]       Input graph file (default: None)
  -l LOG, --log LOG     log verbosity level (default: INFO)
  --matfile-variable-name MATFILE_VARIABLE_NAME
                        variable name of adjacency matrix inside a .mat file.
                        (default: network)
  --max-memory-data-size MAX_MEMORY_DATA_SIZE
                        Size to start dumping walks to disk, instead of
                        keeping them in memory. (default: 1000000000)
  --number-walks NUMBER_WALKS
                        Number of random walks to start at each node (default:
                        10)
  --output OUTPUT       Output representation file (default: None)
  --representation-size REPRESENTATION_SIZE
                        Number of latent dimensions to learn for each node.
                        (default: 64)
  --seed SEED           Seed for random walk generator. (default: 0)
  --undirected UNDIRECTED
                        Treat graph as undirected. (default: True)
  --vertex-freq-degree  Use vertex degree to estimate the frequency of nodes
                        in the random walks. This option is faster than
                        calculating the vocabulary. (default: False)
  --walk-length WALK_LENGTH
                        Length of the random walk started at each node
                        (default: 40)
  --window-size WINDOW_SIZE
                        Window size of skipgram model. (default: 5)
  --workers WORKERS     Number of parallel processes. (default: 1)

最坑的是每次都要重新编译

推荐阅读更多精彩内容