From 01600b59cf50ab936aa67a9a03db30c719dce8bc Mon Sep 17 00:00:00 2001 From: raminqaf Date: Wed, 31 Mar 2021 11:31:05 +0200 Subject: [PATCH 1/5] check gensim version and set param name --- node2vec/node2vec.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/node2vec/node2vec.py b/node2vec/node2vec.py index 1ef1693..22f5bd0 100644 --- a/node2vec/node2vec.py +++ b/node2vec/node2vec.py @@ -5,6 +5,7 @@ import numpy as np import networkx as nx import gensim +import pkg_resources from joblib import Parallel, delayed from tqdm.auto import tqdm @@ -170,12 +171,13 @@ def fit(self, **skip_gram_params) -> gensim.models.Word2Vec: :type skip_gram_params: dict :return: A gensim word2vec model """ + size = 'size' if pkg_resources.get_distribution("gensim").version < '4.0.0' else size = 'vector_size' if 'workers' not in skip_gram_params: skip_gram_params['workers'] = self.workers if 'size' not in skip_gram_params: - skip_gram_params['size'] = self.dimensions + skip_gram_params[size] = self.dimensions if 'sg' not in skip_gram_params: skip_gram_params['sg'] = 1 From e228334befe8075d1fdc1f250b2805cde8edb393 Mon Sep 17 00:00:00 2001 From: raminqaf Date: Wed, 31 Mar 2021 11:39:08 +0200 Subject: [PATCH 2/5] add version to variable --- node2vec/node2vec.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/node2vec/node2vec.py b/node2vec/node2vec.py index 22f5bd0..5fde366 100644 --- a/node2vec/node2vec.py +++ b/node2vec/node2vec.py @@ -171,7 +171,8 @@ def fit(self, **skip_gram_params) -> gensim.models.Word2Vec: :type skip_gram_params: dict :return: A gensim word2vec model """ - size = 'size' if pkg_resources.get_distribution("gensim").version < '4.0.0' else size = 'vector_size' + gensim_version = pkg_resources.get_distribution("gensim").version + size = 'size' if gensim_version < '4.0.0' else 'vector_size' if 'workers' not in skip_gram_params: skip_gram_params['workers'] = self.workers From 35e13e6b70da893b8fa3eb4f8e0727029c138d42 Mon Sep 17 00:00:00 2001 From: elior Date: Fri, 2 Apr 2021 09:27:27 +0300 Subject: [PATCH 3/5] Naming of size also applicable to the skip_gram_params dict --- node2vec/node2vec.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/node2vec/node2vec.py b/node2vec/node2vec.py index 5fde366..7baff73 100644 --- a/node2vec/node2vec.py +++ b/node2vec/node2vec.py @@ -171,13 +171,14 @@ def fit(self, **skip_gram_params) -> gensim.models.Word2Vec: :type skip_gram_params: dict :return: A gensim word2vec model """ - gensim_version = pkg_resources.get_distribution("gensim").version - size = 'size' if gensim_version < '4.0.0' else 'vector_size' if 'workers' not in skip_gram_params: skip_gram_params['workers'] = self.workers - if 'size' not in skip_gram_params: + # Figure out gensim version, naming of output dimensions changed from size to vector_size in v4.0.0 + gensim_version = pkg_resources.get_distribution("gensim").version + size = 'size' if gensim_version < '4.0.0' else 'vector_size' + if size not in skip_gram_params: skip_gram_params[size] = self.dimensions if 'sg' not in skip_gram_params: From bbcf376e8d20cf612832a7fd2b66f0958cea9544 Mon Sep 17 00:00:00 2001 From: elior Date: Fri, 2 Apr 2021 09:29:08 +0300 Subject: [PATCH 4/5] Update fit docstring --- node2vec/node2vec.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/node2vec/node2vec.py b/node2vec/node2vec.py index 7baff73..c44e1de 100644 --- a/node2vec/node2vec.py +++ b/node2vec/node2vec.py @@ -1,10 +1,10 @@ -import random import os +import random from collections import defaultdict -import numpy as np -import networkx as nx import gensim +import networkx as nx +import numpy as np import pkg_resources from joblib import Parallel, delayed from tqdm.auto import tqdm @@ -167,7 +167,8 @@ def _generate_walks(self) -> list: def fit(self, **skip_gram_params) -> gensim.models.Word2Vec: """ Creates the embeddings using gensim's Word2Vec. - :param skip_gram_params: Parameteres for gensim.models.Word2Vec - do not supply 'size' it is taken from the Node2Vec 'dimensions' parameter + :param skip_gram_params: Parameters for gensim.models.Word2Vec - do not supply 'size' / 'vector_size' it is + taken from the Node2Vec 'dimensions' parameter :type skip_gram_params: dict :return: A gensim word2vec model """ From d61531db86d80fc1f9ca05472abba36abc1a90a3 Mon Sep 17 00:00:00 2001 From: elior Date: Fri, 2 Apr 2021 09:30:13 +0300 Subject: [PATCH 5/5] Bump version --- node2vec/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/node2vec/__init__.py b/node2vec/__init__.py index 3748862..93d47d6 100644 --- a/node2vec/__init__.py +++ b/node2vec/__init__.py @@ -1,4 +1,4 @@ from . import edges from .node2vec import Node2Vec -__version__ = '0.4.1' +__version__ = '0.4.2' diff --git a/setup.py b/setup.py index df4868d..ddcf802 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='node2vec', packages=['node2vec'], - version='0.4.1', + version='0.4.2', description='Implementation of the node2vec algorithm.', author='Elior Cohen', author_email='elior.cohen.p@gmail.com',