hello and welcome to my channel to this new video on graph embeddings now graph databases enjoy white enthusiasm and adoption of analytics of integrated data potentially from various sources however in most machine learning algorithms they work on vector form data and therefore to unlock this powerful toolbox we need a way to map our graph structure to a vector form and that's what i'm very excited about because i studied the notoric algorithm and i'm excited about how straightforwardly and concise the approach is formulated and how well it works if you apply it to the right data
in this video we will walk through all the important details we are going to start with the basic motivation why should we care about mapping graph structures to vectors secondly where we're talking about the problem so how do we define this problem what's the context of a node and um what's the overall objective and finally we will walk through the math and here lies the key to the beauty and the simplicity of the approach because once we understand the last bit of the equation the novelty of the approach becomes obvious to us so stay curious
it's going to be a pleasure and so rewarding to understand this get a coffee lean back and let's do it all right part one the motivation why should we care about graph embeddings so we are trying to find a vector representation for our graph structure and we are not talking about the directly associated features of each of the nodes but rather we want to map the structure of the data meaning the relationships between the data points to an embedding space so that we can feed this into an machine learning algorithm there is a strong relationship
to the word to back algorithm which is a word embedding algorithm so it maps words to an embedding space which share a similar context however if we look at a sentence we can tell that it's a one-dimensional array where each word has a fixed position and two direct neighbors meaning the word after it and the word before it however if we look at a graph it's represented as an adjacency matrix so for each node in the graph we get an entire vector of direct neighbors so even though the approaches are similar as the name suggests
we need a slightly different approach for mapping nodes to vectors let's go ahead and formulate the general objective of our optimization problem we want to map nodes with a similar context meaning they connect to the same notes close in an embedding space where they are represented as vectors now because you're following so attentive two questions popped up in your head first what does similar contexts mean and second what does close and the embedding space mean so you're going to be relieved as i tell you that we are going to be talking about exactly about these
two questions let's have a look at the context of a note so the context of a note is simply defined by notes in the neighborhood of that note they access two orthogonal approaches how to explore the context of a node in a graph and i'm pretty sure you're aware of both of them because they are tightly linked to breadth first and depth first search the first similarity matrix is homophily it's derived from a sociological concept stating that similar people tend to interact close with each other meaning that similar people have direct relationships and you can
already tell why it's related to a breadth-first algorithm because this algorithm first explores the direct context of a node before it goes more into depth the second metric is called structural equivalence and it tries to detect the role of a node from a wider perspective so a rollover node in the network would be for example so like in human networks would be for example an influencer or someone who connects communities or something like that so we're not only looking at the direct relationships of a node but rather we follow up on multiple relationships potentially multiple
hops to go into depth to see which other nodes our source node is connected to this in the graph context is closely related to a depth first algorithm because there we also we follow one relationship of our source note and then we follow up on this relationship to see okay whom else can we see if we follow this one relationship and only if we have exploited that one path into depth we will move on to the next direct relationship of our source node now i'm pretty sure that you are familiar with depth first and breadth
first search on a graph but i will walk you through quickly here on a slide all right let's start with the depth first algorithm which is the orange annotation here in this slide so we start in source node one and we would explore all its relationships into depth first before we move on to the next direct relationship so for example we start with the relationship 1 and we end up in node 2 and explore along the path until we cannot find any other node more into the depth but here we would have to jump back
to node 2. so we don't do that but but rather we go back in this path and see that in node 2 we have more relationships to explore so we follow through on here and from the 5 we don't jump back to the node 1 but rather we explore all the other relationships of 5 so we would continue with note 6 down here and once we have explored this entire path here into depth um we would jump back to node 1 and then explore its other relationships we wouldn't take the relationship to note 5 and
because we have already explored note 5 but rather we jump to node 3 and explore this relationship in turn into depth okay the second approach is a breadth first algorithm here we are again start in node one and we explore all the direct relationships first so we would jump to two node two five and three in the first three steps and then we see we don't have any more direct relationships so we explore nodes in the distance level of two so we jump to node two and and go to all the direct relationships from there
so we would end up in nodes nine and eight and seven and then we jump to five and go to node six and then to three and go to node four so here we have the context of node one using the depth first algorithm and here we have the context of node one using the breadth first algorithm now having these contacts we could already calculate how much these nodes contexts are overlapping and therefore we would use the jacquard similarity which i have visualized down here so here's the context of node u which is the red
circle and then we have the context of node v which is the orange circle and in the intersection there are these four nodes and in total we have these four plus three so seven in total so we have 4 over 7 would be our similarity of these two nodes okay now we know what the context of a node means however we usually we cannot take into account the entire context of a node because that would eventually lead to capturing the entire graph therefore we have to introduce a sampling strategy which is basically a strategy to
approximate the context of a node in the notorivec algorithm they introduce a sampling strategy which basically is a fixed number of random walks starting in each of the notes and exploring the context now the context exploring is also parametrized which is basically a trade-off between the breadth first and depth first algorithm so it's a trade-off between homophily and structural equivalence because in each step of a random walk the algorithm decides based on the parameter whether the algorithm should move one distance level away from the source node which would be similar to structural equivalence or whether
it should stay close to the source node which would be related to homophily or a more breadth-first algorithm now with applying the sampling strategy at a source node in the graph we can obtain the neighborhood of u giving given sampling strategy s which is the context of a node which we are going to take into account and which which will be denoted like this for the rest of the video and also in the paper now having the context of each of the nodes we want to find a vector representation such that nodes with a similar
context are mapped close in the embedding space now the second question was what does close in the embedding space mean and that's answered pretty easily because it's the dot product between our two vectors which is basically the angle between the two so the smaller the angle the more similar our vectors are now in that formulation we want to map nodes with a similar context close in the embedding space is the foundation of our optimization problem and in the next step we are going to formulate it from a mathematical perspective and explore how notovex solves this
optimization problem it's getting interesting now okay i want to start with a single node in our graph which would be node u and that one we pick in our graph to be our source node for which we want to find a graph embedding for example now if we explore the context of source node u in the graph we can find easily the neighborhood of source node u given the sampling strategy s and that is the subject strategy we talked about previously so we have a parameter which decides how to exploit the surrounding of the node
u and we end up with a set of nodes these are the orange ones here in the context of our neighbor of our source node u now i want to define node v as being an element of the context of our node u okay having these things at hand we want to find a mapping function which we call f and which basically maps a node to a vector of d dimensions so f of u is a vector of the dimensions all right having this function f at hand which are two vectors we can easily calculate
the similarity between two nodes because we just take the two nodes and generate the vector with a generating function f or the mapping function f and then we take the dot product as discussed previously which we can think of the similarity score in the embedding space so we can think of the dot product as being the anchor between the two vectors so if not v is in the context of u we want this similarity to be large so the the anchor between the two vectors should be small now having the dot product as a similarity
score in the embedding space we want to transform that score into probabilities and that we can do by applying a soft max because the soft max basically normalizes our score into a probability because it squashes the numbers into an interval of 0 to 1 and all the numbers for node u so all the combinations of v and u that we can potentially find in the graph have a sum that equals one so that's the softmax if you not if you're not familiar with the softmax and please research that on your own now having the probability
we can actually write this as a conditional probability so we say the probability that given node u which was our source node what's the probabilities for seeing node v and that we calculate over the function f which makes a vector out of nodes and then over the m dot product and we apply the softmax and we arrive at that probability which we want to optimize because as we know that node v is in the context of node u we want this to be large so we want to maximize this probability and that's how the relationship
is formed between context of nodes and similarities in the embedding space however having that at hand we on we don't want to do that only for one node b in the context of u but rather for the entire context of u so we start from a source node u and we want to find the probability for all the nodes in the context of u so the probability for having this entire context given node u um is in turn a conditional probability if we applied it to the entire context of u and if we assumed independence
of the nodes in the sample of the context of u we can write this pretty easily as simply a product over all nodes in the context of u and we take the conditional probability which we saw earlier so we take probability given node u seeing one of the nodes in the context of u and that's an entire product over all of these samples and where we arrive is basically this up here so we we get the probability for seeing that all of the nodes in the context of u of the sample context given that we
start in node u now this formula is still very easy and if we go ahead and apply this now to all nodes in the graph simultaneously so we not only start from one node u but rather we start from all nodes in the graph a fixed number of um random walks so we sample each context of each node and the graph and then we apply this in our equation we would add up at the following equation which is basically the final final equation for finding graph embeddings so or here we have the probability for seeing
um the context uh the sample context of node u given we start in one node u which is basically this term up here and then we we sum these probabilities up over all nodes in our graph so every node becomes the node u and that's the entire score for our embedding we found and we of course we want to maximize this equation so we take this equation which is the total probability score which we want to maximize so we want this to be maximized which would be our best graph embedding we could find because nodes
which would appear in the context of a node would have a close or a high probability in the embedding space and that's what we want to find so we update the f function up here which we use to generate a vector out of a node and maximize for this probability using stochastic gradient descent and that's basically it it's it's that simple i really like um how straightforwardly it is formulated and how um easily it is understandable and not to say that it's easily calculated because there are some challenges in calculating these terms so there are
some optimizations and approximations used to calculate this equation here efficiently on large data sets but you can look them up in the paper as well but the basic idea is actually that simple and that's that's the amazing thing because that's all there is it's very easily and intuitive formulated it's a very concise description of the problem we are trying to solve and it's very simple math and still it works so well for many use cases so if you like this video hit the like button if you have questions leave them in the comments and make
sure you subscribe for the next video where i'm gonna be talking about i don't know yet but we will see see you then bye bye