|
| 1 | +# node2vec on spark |
| 2 | + |
| 3 | +This library is a implementation using scala for running on spark of *node2vec* as described in the paper: |
| 4 | +> node2vec: Scalable Feature Learning for Networks. |
| 5 | +> Aditya Grover and Jure Leskovec. |
| 6 | +> Knowledge Discovery and Data Mining, 2016. |
| 7 | +> <Insert paper link> |
| 8 | +
|
| 9 | +The *node2vec* algorithm learns continuous representations for nodes in any (un)directed, (un)weighted graph. Please check the [project page](https://snap.stanford.edu/node2vec/) for more details. |
| 10 | + |
| 11 | + |
| 12 | +### Building node2vec_spark |
| 13 | +**In order to build node2vec_spark, use the following:** |
| 14 | + |
| 15 | +``` |
| 16 | +$ git clone https://github.com/Skarface-/node2vec.git |
| 17 | +$ mvn clean package |
| 18 | +``` |
| 19 | + |
| 20 | +**and requires:**<br/> |
| 21 | +Maven 3.0.5 or newer<br/> |
| 22 | +Java 7+<br/> |
| 23 | +Scala 2.10 or newer. |
| 24 | + |
| 25 | +This will produce jar file in "node2vec_spark/target/" |
| 26 | + |
| 27 | +### Examples |
| 28 | +This library has two functions: *randomwalk* and *embedding*. <br/> |
| 29 | +These were described in these papers [node2vec: Scalable Feature Learning for Networks](http://arxiv.org/abs/1607.00653) and [Efficient Estimation of Word Representations in Vector Space](https://arxiv.org/abs/1301.3781). |
| 30 | + |
| 31 | +### Random walk |
| 32 | +Example: |
| 33 | + |
| 34 | + ./spark-submit --class com.navercorp.Main \ |
| 35 | + ./node2vec_spark/target/node2vec-0.0.1-SNAPSHOT.jar \ |
| 36 | + --cmd randomwalk --p 100.0 --q 100.0 --walkLength 40 \ |
| 37 | + --input <input> --output <output> |
| 38 | + |
| 39 | +#### Options |
| 40 | +Invoke a command without arguments to list available arguments and their default values: |
| 41 | + |
| 42 | +``` |
| 43 | +--cmd COMMAND |
| 44 | + Functions: randomwalk or embedding. If you want to execute all functions "randomwalk" and "embedding" sequentially input "node2vec". Default "node2vec" |
| 45 | +--input [INPUT] |
| 46 | + Input edgelist path. The supported input format is an edgelist: "node1_id_int node2_id_int <weight_float, optional>" |
| 47 | +--output [OUTPUT] |
| 48 | + Random paths path. |
| 49 | +--walkLength WALK_LENGTH |
| 50 | + Length of walk per source. Default is 80. |
| 51 | +--numWalks NUM_WALKS |
| 52 | + Number of walks per source. Default is 10. |
| 53 | +--p P |
| 54 | + Return hyperparaemter. Default is 1.0. |
| 55 | +--q Q |
| 56 | + Inout hyperparameter. Default is 1.0. |
| 57 | +--weighted Boolean |
| 58 | + Specifying (un)weighted. Default is true. |
| 59 | +--directed Boolean |
| 60 | + Specifying (un)directed. Default is false. |
| 61 | +--degree UPPER_BOUND_OF_NUMBER_OF_NEIGHBORS |
| 62 | + Specifying upper bound of number of neighbors. Default is 30. |
| 63 | +--indexed Boolean |
| 64 | + Specifying whether nodes in edgelist are indexed or not. Default is true. |
| 65 | +``` |
| 66 | + |
| 67 | +* If "indexed" is set to false, *node2vec_spark* index nodes in input edgelist, example: <br/> |
| 68 | + **unindexed edgelist:**<br/> |
| 69 | + node1 node2 1.0<br/> |
| 70 | + node2 node7 1.0<br/> |
| 71 | + |
| 72 | + **indexed:**<br/> |
| 73 | + 1 2 1.0<br/> |
| 74 | + 2 3 1.0<br/> |
| 75 | + |
| 76 | + 1 node1<br/> |
| 77 | + 2 node2<br/> |
| 78 | + 3 node7 |
| 79 | + |
| 80 | +#### Input |
| 81 | +The supported input format is an edgelist: |
| 82 | + |
| 83 | + node1_id_int node2_id_int <weight_float, optional> |
| 84 | + or |
| 85 | + node1_str node2_str <weight_float, optional>, Please set the option "indexed" to false |
| 86 | + |
| 87 | + |
| 88 | +#### Output |
| 89 | +The output file (number of nodes)*numWalks random paths as follows: |
| 90 | + |
| 91 | + src_node_id_int node1_id_int node2_id_int ... noden_id_int |
| 92 | + |
| 93 | + |
| 94 | +### Embedding random paths |
| 95 | +Example: |
| 96 | + |
| 97 | + ./spark-submit --class com.navercorp.Main \ |
| 98 | + ./node2vec_spark/target/node2vec-0.0.1-SNAPSHOT.jar \ |
| 99 | + --cmd embedding --dim 50 --iter 20 \ |
| 100 | + --input <input> --nodePath <node2id_path> --output <output> |
| 101 | + |
| 102 | +#### Options |
| 103 | +Invoke a command without arguments to list available arguments and their default values: |
| 104 | + |
| 105 | +``` |
| 106 | +--cmd COMMAND |
| 107 | + embedding. If you want to execute sequentially all functions: "randomwalk" and "embedding", input "node2vec". default "node2vec" |
| 108 | +--input [INPUT] |
| 109 | + Input random paths. The supported input format is an random paths: "src_node_id_int node1_id_int ... noden_id_int" |
| 110 | +--output [OUTPUT] |
| 111 | + word2vec model(.bin) and embeddings(.emb). |
| 112 | +--nodePath [NODE\_PATH] |
| 113 | + Input node2index path. The supported input format: "node1_str node1_id_int" |
| 114 | +--iter ITERATION |
| 115 | + Number of epochs in SGD. Default 10. |
| 116 | +--dim DIMENSION |
| 117 | + Number of dimensions. Default is 128. |
| 118 | +--window WINDOW_SIZE |
| 119 | + Context size for optimization. Default is 10. |
| 120 | +
|
| 121 | +``` |
| 122 | + |
| 123 | +#### Input |
| 124 | +The supported input format is an random paths: |
| 125 | + |
| 126 | + src_node_id_int node1_id_int ... noden_id_int |
| 127 | + |
| 128 | +#### Output |
| 129 | +The output files are **embeddings and word2vec model.** The embeddings file has the following format: |
| 130 | + |
| 131 | + node1_str dim1 dim2 ... dimd |
| 132 | + |
| 133 | +where dim1, ... , dimd is the d-dimensional representation learned by word2vec. |
| 134 | + |
| 135 | +the output file *word2vec model* has the spark word2vec model format. please reference to https://spark.apache.org/docs/1.5.2/mllib-feature-extraction.html#word2vec |
| 136 | + |
| 137 | +## References |
| 138 | +1. [node2vec: Scalable Feature Learning for Networks](http://arxiv.org/abs/1607.00653) |
| 139 | +2. [Efficient Estimation of Word Representations in Vector Space](https://arxiv.org/abs/1301.3781) |
0 commit comments