Prerequisite: Word2Vec
Word Embedding: It is a language modeling technique used for mapping words to vectors of real numbers. It represents words or phrases in vector space with several dimensions. Word embeddings can be generated using various methods like neural networks, co-occurrence matrix, probabilistic models, etc.
Word2Vec: It consists of models for generating word embedding.
Node2Vec: A node embedding algorithm that computes a vector representation of a node based on random walks in the graph. The neighborhood nodes of the graph is also sampled through deep random walks. This algorithm performs a biased random walk procedure in order to efficiently explore diverse neighborhoods.
It is based on a similar principle as Word2Vec but instead of word embeddings, we create node embeddings here.
Intuition:
Node2Vec framework is based on the principle of learning continuous feature representation for nodes in the graph and preserving the knowledge gained from the neighboring 100 nodes. Lets us understand how the algorithm works. Say we have a graph having a few interconnected nodes creating a network. So, Node2Vec algorithm learns a dense representation (say 100 dimensions/features) of every node in the network.
The algorithm suggests that if we plot these 100 dimensions of each node in a 2 dimensional graph by applying PCA, the distance of the two nodes in that low-dimensional graph would be same as their actual distance in the given network.
In this way, the framework maximizes the likelihood of preserving neighboring nodes even if you represent them in a low-dimensional space. (As shown in Fig 1)

Fig1 : Intuition
Real-Life Example:
Let us take an example of textual data given to us to understand its working in detail. The Node2Vec framework suggests that random walks through the series of nodes in the graph can be treated as sentences. Each node in this graph is treated like a unique, individual word and each random walk through the network is treated as a sentence.
By creating and using a “continuous bag of words model” on which the Node2Vec framework learns, it can predict the next possible set of words by searching the neighbours of the given word. This is the power of Node2Vec algorithm.
Node2Vec Algorithm:
node2vecWalk (Graph G' = (V, E, π), Start node u, Length l):
Initialize walk to [u]
for (walk_iter = 1 to l):
curr = walk[−1]
Vcurr = GetNeighbors(curr, G')
s = AliasSample(Vcurr, π)
Append s to walk
return walk
Learn_Features (Graph G = (V, E, W)):
Dimensions -> d
Walks per node -> r
Walk length -> l
Context size -> k
Return -> p
In-out -> q
π = PreprocessModifiedWeights (G, p, q)
G' = (V, E, π)
Initialize walks = 0
for (iter = 1 to r):
for (all nodes u ∈ V):
walk = node2vecWalk(G', u, l)
Append walk to walks
f = StochasticGradientDescent(k, d, walks)
return f
Applications:
- Social Media Network: Let’s consider each node in the network as a ‘USER’ and the neighboring nodes as the ‘FRIENDS’ of the that user. Each node has a set of features that involves their likes and dislikes. So, by using Node2Vec framework, we can identify which is the closest friend of the user easily.
- Recommendation System Network: The recommendation system gives two ‘USERS’ (nodes) the same recommendation of a product based on the similarity of their feature set. It this way, these recommendation systems give similar recommendations to a group of such similar nodes hence making it efficient.
Similar Reads
DeepWalk Algorithm
Graph Data Structure: In the real world, Networks are just the collection of interconnected nodes. To represent this type of network we need a data structure that is similar to it. Fortunately, we have a data structure that is the graph. The graph contains vertices (which represents the node in the
4 min read
Introduction to Beam Search Algorithm
In artificial intelligence, finding the optimal solution to complex problems often involves navigating vast search spaces. Traditional search methods like depth-first and breadth-first searches have limitations, especially when it comes to efficiency and memory usage. This is where the Beam Search a
5 min read
Spectral Co-Clustering Algorithm in Scikit Learn
Spectral co-clustering is a type of clustering algorithm that is used to find clusters in both rows and columns of a data matrix simultaneously. This is different from traditional clustering algorithms, which only cluster the rows or columns of a data matrix. Spectral co-clustering is a powerful too
4 min read
Computational Graph in PyTorch
PyTorch is a popular open-source machine learning library for developing deep learning models. It provides a wide range of functions for building complex neural networks. PyTorch defines a computational graph as a Directed Acyclic Graph (DAG) where nodes represent operations (e.g., addition, multipl
4 min read
ANN - Self Organizing Neural Network (SONN) Learning Algorithm
Prerequisite: ANN | Self Organizing Neural Network (SONN) In the Self Organizing Neural Network (SONN), learning is performed by shifting the weights from inactive connections to active ones. The neurons which were won are selected to learn along with their neighborhood neurons. If a neuron does not
3 min read
A* algorithm and its Heuristic Search Strategy in Artificial Intelligence
The A* (A-star) algorithm is a powerful and versatile search method used in computer science to find the most efficient path between nodes in a graph. Widely used in a variety of applications ranging from pathfinding in video games to network routing and AI, A* remains a foundational technique in th
8 min read
What are Graph Neural Networks?
Graph Neural Networks (GNNs) are a neural network specifically designed to work with data represented as graphs. Unlike traditional neural networks, which operate on grid-like data structures like images (2D grids) or text (sequential), GNNs can model complex, non-Euclidean relationships in data, su
13 min read
Spectral Clustering in Machine Learning
Prerequisites: K-Means Clustering In the clustering algorithm that we have studied before we used compactness(distance) between the data points as a characteristic to cluster our data points. However, we can also use connectivity between the data point as a feature to cluster our data points. Using
9 min read
Graph Representation Learning
In this article we are going to learn about Graph representation in Machine Learning (ML). Graph is basically a data structure which provide a mathematical model of representing information by the collection of nodes and edges connecting them. It is used in machine learning to solve the problem of r
8 min read
Uniform Cost Search (UCS) in AI
Uniform Cost Search (UCS) is a popular search algorithm used in artificial intelligence (AI) for finding the least cost path in a graph. It is a variant of Dijkstra's algorithm and is particularly useful when all edges of the graph have different weights, and the goal is to find the path with the mi
9 min read