Node embedding application. Given a graph, it embeds each node into a continuous vector representation. The learned embeddings can be used for many downstream tasks. e.g. **node classification**, **link prediction**, **node analogy**. The similarity between node embeddings can
| 242 | |
| 243 | |
| 244 | class GraphApplication(ApplicationMixin): |
| 245 | """ |
| 246 | Node embedding application. |
| 247 | |
| 248 | Given a graph, it embeds each node into a continuous vector representation. |
| 249 | The learned embeddings can be used for many downstream tasks. |
| 250 | e.g. **node classification**, **link prediction**, **node analogy**. |
| 251 | The similarity between node embeddings can be measured by cosine distance. |
| 252 | |
| 253 | Supported Models: |
| 254 | - DeepWalk (`DeepWalk: Online Learning of Social Representations`_) |
| 255 | - LINE (`LINE: Large-scale Information Network Embedding`_) |
| 256 | - node2vec (`node2vec: Scalable Feature Learning for Networks`_) |
| 257 | |
| 258 | .. _DeepWalk\: Online Learning of Social Representations: |
| 259 | https://arxiv.org/pdf/1403.6652.pdf |
| 260 | .. _LINE\: Large-scale Information Network Embedding: |
| 261 | https://arxiv.org/pdf/1503.03578.pdf |
| 262 | .. _node2vec\: Scalable Feature Learning for Networks: |
| 263 | https://www.kdd.org/kdd2016/papers/files/rfp0218-groverA.pdf |
| 264 | |
| 265 | Parameters: |
| 266 | dim (int): dimension of embeddings |
| 267 | gpus (list of int, optional): GPU ids, default is all GPUs |
| 268 | cpu_per_gpu (int, optional): number of CPU threads per GPU, default is all CPUs |
| 269 | float_type (dtype, optional): type of parameters |
| 270 | index_type (dtype, optional): type of graph indexes |
| 271 | |
| 272 | See also: |
| 273 | :class:`Graph <graphvite.graph.Graph>`, |
| 274 | :class:`GraphSolver <graphvite.solver.GraphSolver>` |
| 275 | """ |
| 276 | |
| 277 | def get_graph(self, **kwargs): |
| 278 | return graph.Graph(self.index_type) |
| 279 | |
| 280 | def get_solver(self, **kwargs): |
| 281 | if self.cpu_per_gpu == auto: |
| 282 | num_sampler_per_worker = auto |
| 283 | else: |
| 284 | num_sampler_per_worker = self.cpu_per_gpu - 1 |
| 285 | return solver.GraphSolver(self.dim, self.float_type, self.index_type, self.gpus, num_sampler_per_worker, |
| 286 | self.gpu_memory_limit) |
| 287 | |
| 288 | def set_parameters(self, model): |
| 289 | mapping = self.get_mapping(self.graph.id2name, model.graph.name2id) |
| 290 | self.solver.vertex_embeddings[:] = model.solver.vertex_embeddings[mapping] |
| 291 | self.solver.context_embeddings[:] = model.solver.context_embeddings[mapping] |
| 292 | |
| 293 | def node_classification(self, X=None, Y=None, file_name=None, portions=(0.02,), normalization=False, times=1, |
| 294 | patience=100): |
| 295 | """ |
| 296 | Evaluate node embeddings on node classification task. |
| 297 | |
| 298 | Parameters: |
| 299 | X (list of str, optional): names of nodes |
| 300 | Y (list, optional): labels of nodes |
| 301 | file_name (str, optional): file of nodes & labels |
nothing calls this directly
no outgoing calls
no test coverage detected