Comments (6)
No, I wouldn't go this way
Training is okay, but for testing you do not need Node2Vec
. The algorithm outputs embeddings in a known format, once you're done creating them, you don't need the algorithm again.
So just use
from gensim.models import KeyedVectors
space = KeyedVectors.load_word2vec_format(EMBEDDING_FILENAME)
then too look up vectors, see the gensim docs
from node2vec.
Thanks for the reference, following your suggestion is this a valid approach?
Does it make sense to save both the wor and model file? Should I just keep the model file only?
Why the edges fails to load (see last line) with an error?
NODE_WORD_FILENAME = "word2vec.emb"
NODE_MODEL_FILENAME = "word2vec.model"
EDGES_WORD_FILENAME = "edges2vec.emb"
if args.method=="train":
# Precompute probabilities and generate walks
node2vec = Node2Vec(G, dimensions=64, walk_length=30, num_walks=200,workers=4) # Use temp_folder for big graphs
# Embed nodes
model = node2vec.fit(window=10, min_count=1, batch_words=4) # Any keywords acceptable by gensim.Word2Vec can be passed, `dimensions` and `workers` are automatically passed (from the Node2Vec constructor)
# Save embeddings for later use
model.wv.save_word2vec_format(NODE_WORD_FILENAME)
# Save model for later use
model.save(NODE_MODEL_FILENAME)
edges_embs = HadamardEmbedder(keyed_vectors=model.wv)
# Get all edges in a separate KeyedVectors instance - use with caution could be huge for big networks
edges_kv = edges_embs.as_keyed_vectors()
# Save embeddings for later use
edges_kv.save_word2vec_format(EDGES_WORD_FILENAME)
if args.method == "test":
import re
model = Word2Vec.load(NODE_MODEL_FILENAME)
# this generates an error: could not convert string to float
edges_kv = KeyedVectors.load_word2vec_format(EDGES_WORD_FILENAME)
from node2vec.
Last error:
File "/home/robomotic/DevOps/gitlab/ava-prod-ai/venv/lib/python3.11/site-packages/gensim/models/keyedvectors.py", line 1980, in <listcomp>
word, weights = parts[0], [datatype(x) for x in parts[1:]]
from node2vec.
Which line failes? the edges_kv =
or the model =
?
from node2vec.
Yes is the the keyed vector odd:
this generates an error: could not convert string to float
edges_kv = KeyedVectors.load_word2vec_format(EDGES_WORD_FILENAME)
from node2vec.
I can see why this happens, because these are edges embedding
If you want to use edges embedding why not do it this way
node_embeddings = KeyedVectors.load_word2vec_format(NODE_WORD_FILENAME)
edges_embs = HadamardEmbedder(keyed_vectors=node_embeddings)
# Get all edges in a separate KeyedVectors instance - use with caution could be huge for big networks
edges_kv = edges_embs.as_keyed_vectors()
from node2vec.
Related Issues (20)
- How can node2vec use GPU HOT 1
- too slow and stuck for some reason HOT 9
- reproducability HOT 2
- failing simple clustering of synthetic networks HOT 2
- Error in model creation node2vec HOT 1
- Cannot import Node2Vec HOT 5
- A faster implement HOT 1
- networkx>3.0 support? HOT 2
- There may be a small problem with the walking length. HOT 1
- Interpretation of weights HOT 2
- model save and loading examples HOT 2
- Are there any ways to initialize node vector using pretrained embeddings? HOT 1
- Crash when edges are not initialised with a weight attribute HOT 8
- can same temp directory be used for different graphs in for loop training? HOT 4
- _precompute_probabilities parallel execution HOT 2
- import error HOT 3
- segmentation fault HOT 5
- Error installing gensim in poetry env on mac m1 HOT 3
- How to set parameters for a collection small disconnected graphs HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node2vec.