<p>Clearly the additional references do put Metapath2vec into good use. Its a many to many ML relationship. Most catagorization/classification particularly in deep learning is many  to one. So thats the good thing about the technique you  are using, you've 25 catagories, which is quite large for machine learning(ML) and large for deep learning. The technique appears to be half way between supervised and unsupervised learning. The random walk establishes a zone (circle) of catagorisation.</p>
<p><strong>NLP Background</strong></p>
<p>The situation where it would work in NLP (natural language processing) is for example a spell checker, where you have one correct word and loads of possible typos, some of which you not observed in training. So what will happen is the random walk will pick up the local vacinity around the 'correct spelling' by the vectorization (converting a word into numbers) of the incorrect spelling will land it close to 'true spelling' in a 2D vectorization plot. The training following the random walk says  'yep you belong with me'.</p>
<p>The papers given talk about being able to identify the context of a word within a sentence which is a very NLP thing, one vectorisation being 'bags of words'. So here the sentence represents one of many categories of information, i.e. each is the central node within the graph, the vectorisation of the sentence places of meaning closer to one 'hub' than another and again the local vacinity is identified by the random walk. In training this 'random walk vacinity' is identified, so it will algorithmically recreate the 'random walk locality' so that sentences that have not been trained can have their meaning identified.</p>
<p>The central theory of deep learning, which not quite true of other ML, is any algorithm can be recreated through training. So like it will sort of recreate a 'random walk zone'</p>
<p><strong>Difference with drug discovery</strong></p>
<p>The papers you have map drugs to genes, but it means you have to have a &quot;true drug to gene&quot; relationship. The problem I see here is what is 'true' for a drug-protein interaction? With a spell-checker there is one 'true spelling', with a sentence there is pretty much one 'type of meaning', like a movie was great, average, terrible based on a ratings score and stuff like gender classification. If its not 'true' the random walk will get it wrong. So its a big assumption. If you have a circle and pick a point on the edge of the circle then try and draw a circle around the original circle, you can't unless the circle is so large it risks including stuff that is not part of the original circle. The problem the papers is how do they know what is the 'centre' of the circle? Its an a priori assumption and you need really good biological rationale.</p>
<p>With your stuff I agree its easier because adverse drug reaction, some drugs could be fatal or toxic (traditional cancer drugs or parasite drugs), so you'd pick the worst case adverse reaction. That then centres the definition around which everything else is relative. If however your 'true catagory' turned out to be an outlier its not going to work, because the random walk only works if its starts bang in the centre of the 'catagory'. Random walks form spheres, in case you are not aware. I can see this working as an advanced 'unsupervised learning' technique.</p>
<p>One very real advantage is if a drug doesn't have an adverse reaction it MIGHT (I'm guessing) not give a result, in which case you are good to go - that a good drug. If that is what happened that would be amazing because its not how ML, or particularly DL works. Traditional ML/DL will force a classification even if it doesn't fit. There are methods to accept some sort of &quot;half-classification&quot; but I don't know how to do it. This is one of the reaons you need lots of things to train.</p>
<p>I am assuming that vectorisation of your drug is fine because there is a huge history of this in drug-discovery going right back to the origins of the field.</p>
<p><strong>Summary</strong></p>
<p>So yeah I get the idea, I see the flaws and the advantages. The final issue is that most ML requires pretty large data sets and DL require huge data sets and when you've got 25 catagories. For DL approaches the data set size might need to be huge unless you can do 'transfer learning' (backing your training onto a pre-trained model). If your method resulted in a zero classification i.e. &quot;doesn't fit anything I've got&quot; - that would be cool and that is the key advantage I can see in the 'random walk' approach which is not available using traditional methods.</p>
<p>As long as you are aware, you do not have to use this algorithm to get a classification. This final point what appears missing in the papers is using a 'traditional' method by comparison. The ML before deep learning, stuff like random forests, routinely takes loads of catagories. If you are using a non-deep learning ML you would traditional use several different approaches to justify your result.</p>
<hr />
<p>My answer is a bit rambly but I think you'll get the gist. Peronally I would complement with a standard ML, but all methods have their flaws. Deep learning (DL) has a big history in drug discovery (alot of work was done via Tensorflow), but I'm not sure you've data set size for this.</p>

CC BY-SA 4.0
2020-11-12T18:23:56.607Z
It is all clear enough and I thank you for your precious answer.
So if I would like to classify drugs based on their ADRs I should give up on this approach and try out a standard ML classification algorithm, right?
I am quite confused about it, it is the first time working in this field and I don't really have much experience. If you could give me a more detailed explanation of how to achieve my goal, I would be grateful. @Michael
Cecilia
CC BY-SA 4.0
2020-11-12T18:48:49.747Z
I would do the two side by side. I think this approaches has merits. All I am pointing out is there are weaknesses in the approach, but you need to be aware that ML approaches, outside deep learning, give varying answers and there's no real way to say one is better than another. This method also might have advantages that 'traditional ML' does not have (possibly a 'zero classification'). The thing about this one is at least there is a known basis where it might not give the right answer.
M__
CC BY-SA 4.0
2020-11-10T18:33:43.057Z
2020-11-11T08:49:13.787Z
2020-11-11T08:49:13.787Z
M__
<p>I am new in this field and I am having some problems regarding a new project.</p>
<p>I built a graph using Drugbank Data connected to SIDER Adverse Reactions.
I used Organ- level Terms to classify the ADRs in 25 different groups.
I aim to use the algorithm Metapath2vec in order to cluster drugs based on the group of ADRs they lead to.
I am currently using the python package for Machine Learning on graphs Stellargraph and the related implementation of Metapath2vec.</p>
<p>I chose Clustering as downstream task with the resulting node embeddings, e.g. DBSCAN but the results are not promising.
I would like to have some clusters of drugs related to different adverse drug reaction.
Since I am new in this field everything I am trying is based on scientific literature but I don't know if this is the right approach for my objective.</p>
<p>This is the code related to the metapath2vec algorithm:</p>
<pre><code>walk_length = 100  # maximum length of a random walk to use throughout this notebook

# specify the metapath schemas as a list of lists of node types.
metapaths = [
    [&quot;drug&quot;, &quot;adr&quot;, &quot;drug&quot;],
    [&quot;drug&quot;, &quot;adr&quot;, &quot;drug&quot;, &quot;drug&quot;],
    [&quot;drug&quot;, &quot;drug&quot;],
    [&quot;drug&quot;, &quot;adr&quot;, &quot;group_adr&quot;, &quot;adr&quot;, &quot;drug&quot;],
    ]

# Create the random walker
rw = UniformRandomMetaPathWalk(graph)

walks = rw.run(
    nodes=list(graph.nodes()),  # root nodes
    length=walk_length,  # maximum length of a random walk
    n=1,  # number of random walks per root node
    metapaths=metapaths,  # the metapaths
)


from gensim.models import Word2Vec

model = Word2Vec(walks, size=128, window=5, min_count=0, sg=1, workers=2, iter=1)

</code></pre>
<p>Should I change approach?
what other algorithm for representation learning can I use in order to reach my goal?
what can I improve in the presented approach to have better node embeddings?</p>

CC BY-SA 4.0
2020-11-08T23:56:35.103Z
Interesting, will be a while before I answer. I'm not 100% sure, intuititively the algorithm you propose appears to be a vectorisation. However, you are using random walks ... I've seen random walks in Monte Carlo yes .... but classification no. Could you explain the purpose of the random walk? Are you doing a simulation to assess the classification then applying to real data?
M__
CC BY-SA 4.0
2020-11-09T00:05:09.490Z
The meta-path-based random walk strategy ensures that the semantic relationships between different types of nodes can be properly incorporated into skip-gram.
A better explanation is taken from this paper: [link](http://library.usc.edu.ph/ACM/KKD%202017/pdfs/p135.pdf).
I didn't take into account any simulation to assess the classification, do you have any suggestion? @Michael
Cecilia
CC BY-SA 4.0
2020-11-09T08:20:07.107Z
Thanks,  I get the idea its for 1:1 relationships. This appears to be for natural language processing rather than drugs and  will affect vectorisation. I'll respond towards the end of the week. I need to get my head around the biology of your stuff
M__
CC BY-SA 4.0
2020-11-09T12:10:56.253Z
@MIchael It would be great, thanks .
I provide you some papers I have been referring to for this project: [link](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6079268/) [link](https://www.worldscientific.com/doi/abs/10.1142/S0218213020500013)
I hope it's quite clear what's my goal.
Cecilia
<networks><machine-learning><deep-learning><pytorch>
Metapath2vec on Drug-ADR Heterogeneous Graph
# Metapath2vec on Drug-ADR Heterogeneous Graph

(Asked by: username_0 on 2020-11-08)

I am new in this field and I am having some problems regarding a new project.
I built a graph using Drugbank Data connected to SIDER Adverse Reactions.
I used Organ- level Terms to classify the ADRs in 25 different groups.
I aim to use the algorithm Metapath2vec in order to cluster drugs based on the group of ADRs they lead to.
I am currently using the python package for Machine Learning on graphs Stellargraph and the related implementation of Metapath2vec.
I chose Clustering as downstream task with the resulting node embeddings, e.g. DBSCAN but the results are not promising.
I would like to have some clusters of drugs related to different adverse drug reaction.
Since I am new in this field everything I am trying is based on scientific literature but I don't know if this is the right approach for my objective.
This is the code related to the metapath2vec algorithm:
walk_length = 100  # maximum length of a random walk to use throughout this notebook

# specify the metapath schemas as a list of lists of node types.
metapaths = [
    ["drug", "adr", "drug"],
    ["drug", "adr", "drug", "drug"],
    ["drug", "drug"],
    ["drug", "adr", "group_adr", "adr", "drug"],
    ]

# Create the random walker
rw = UniformRandomMetaPathWalk(graph)

walks = rw.run(
    nodes=list(graph.nodes()),  # root nodes
    length=walk_length,  # maximum length of a random walk
    n=1,  # number of random walks per root node
    metapaths=metapaths,  # the metapaths
)


from gensim.models import Word2Vec

model = Word2Vec(walks, size=128, window=5, min_count=0, sg=1, workers=2, iter=1)


Should I change approach?
what other algorithm for representation learning can I use in order to reach my goal?
what can I improve in the presented approach to have better node embeddings?

**Tags:** networks, machine-learning, deep-learning, pytorch
> **Comments:**
> **username_1**: Interesting, will be a while before I answer. I'm not 100% sure, intuititively the algorithm you propose appears to be a vectorisation. However, you are using random walks ... I've seen random walks in Monte Carlo yes .... but classification no. Could you explain the purpose of the random walk? Are you doing a simulation to assess the classification then applying to real data?  
> **username_0**: The meta-path-based random walk strategy ensures that the semantic relationships between different types of nodes can be properly incorporated into skip-gram. A better explanation is taken from this paper: [link](http://library.usc.edu.ph/ACM/KKD%202017/pdfs/p135.pdf). I didn't take into account any simulation to assess the classification, do you have any suggestion? @Michael  
> **username_1**: Thanks,  I get the idea its for 1:1 relationships. This appears to be for natural language processing rather than drugs and  will affect vectorisation. I'll respond towards the end of the week. I need to get my head around the biology of your stuff  
> **username_0**: @MIchael It would be great, thanks . I provide you some papers I have been referring to for this project: [link](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6079268/) [link](https://www.worldscientific.com/doi/abs/10.1142/S0218213020500013) I hope it's quite clear what's my goal.  

---

## 1 answers

### Answer by username_1 on 2020-11-10. Score: 1

Clearly the additional references do put Metapath2vec into good use. Its a many to many ML relationship. Most catagorization/classification particularly in deep learning is many to one. So thats the good thing about the technique you are using, you've 25 catagories, which is quite large for machine learning(ML) and large for deep learning. The technique appears to be half way between supervised and unsupervised learning. The random walk establishes a zone (circle) of catagorisation.

**NLP Background**

The situation where it would work in NLP (natural language processing) is for example a spell checker, where you have one correct word and loads of possible typos, some of which you not observed in training. So what will happen is the random walk will pick up the local vacinity around the 'correct spelling' by the vectorization (converting a word into numbers) of the incorrect spelling will land it close to 'true spelling' in a 2D vectorization plot. The training following the random walk says 'yep you belong with me'.

The papers given talk about being able to identify the context of a word within a sentence which is a very NLP thing, one vectorisation being 'bags of words'. So here the sentence represents one of many categories of information, i.e. each is the central node within the graph, the vectorisation of the sentence places of meaning closer to one 'hub' than another and again the local vacinity is identified by the random walk. In training this 'random walk vacinity' is identified, so it will algorithmically recreate the 'random walk locality' so that sentences that have not been trained can have their meaning identified.

The central theory of deep learning, which not quite true of other ML, is any algorithm can be recreated through training. So like it will sort of recreate a 'random walk zone'

**Difference with drug discovery**

The papers you have map drugs to genes, but it means you have to have a "true drug to gene" relationship. The problem I see here is what is 'true' for a drug-protein interaction? With a spell-checker there is one 'true spelling', with a sentence there is pretty much one 'type of meaning', like a movie was great, average, terrible based on a ratings score and stuff like gender classification. If its not 'true' the random walk will get it wrong. So its a big assumption. If you have a circle and pick a point on the edge of the circle then try and draw a circle around the original circle, you can't unless the circle is so large it risks including stuff that is not part of the original circle. The problem the papers is how do they know what is the 'centre' of the circle? Its an a priori assumption and you need really good biological rationale.

With your stuff I agree its easier because adverse drug reaction, some drugs could be fatal or toxic (traditional cancer drugs or parasite drugs), so you'd pick the worst case adverse reaction. That then centres the definition around which everything else is relative. If however your 'true catagory' turned out to be an outlier its not going to work, because the random walk only works if its starts bang in the centre of the 'catagory'. Random walks form spheres, in case you are not aware. I can see this working as an advanced 'unsupervised learning' technique.

One very real advantage is if a drug doesn't have an adverse reaction it MIGHT (I'm guessing) not give a result, in which case you are good to go - that a good drug. If that is what happened that would be amazing because its not how ML, or particularly DL works. Traditional ML/DL will force a classification even if it doesn't fit. There are methods to accept some sort of "half-classification" but I don't know how to do it. This is one of the reaons you need lots of things to train.

I am assuming that vectorisation of your drug is fine because there is a huge history of this in drug-discovery going right back to the origins of the field.

**Summary**

So yeah I get the idea, I see the flaws and the advantages. The final issue is that most ML requires pretty large data sets and DL require huge data sets and when you've got 25 catagories. For DL approaches the data set size might need to be huge unless you can do 'transfer learning' (backing your training onto a pre-trained model). If your method resulted in a zero classification i.e. "doesn't fit anything I've got" - that would be cool and that is the key advantage I can see in the 'random walk' approach which is not available using traditional methods.

As long as you are aware, you do not have to use this algorithm to get a classification. This final point what appears missing in the papers is using a 'traditional' method by comparison. The ML before deep learning, stuff like random forests, routinely takes loads of catagories. If you are using a non-deep learning ML you would traditional use several different approaches to justify your result.

---

My answer is a bit rambly but I think you'll get the gist. Peronally I would complement with a standard ML, but all methods have their flaws. Deep learning (DL) has a big history in drug discovery (alot of work was done via Tensorflow), but I'm not sure you've data set size for this.

> **Comments:**
> **username_0**: It is all clear enough and I thank you for your precious answer. So if I would like to classify drugs based on their ADRs I should give up on this approach and try out a standard ML classification algorithm, right? I am quite confused about it, it is the first time working in this field and I don't really have much experience. If you could give me a more detailed explanation of how to achieve my goal, I would be grateful. @Michael  
> **username_1**: I would do the two side by side. I think this approaches has merits. All I am pointing out is there are weaknesses in the approach, but you need to be aware that ML approaches, outside deep learning, give varying answers and there's no real way to say one is better than another. This method also might have advantages that 'traditional ML' does not have (possibly a 'zero classification'). The thing about this one is at least there is a known basis where it might not give the right answer.  

---

