AI in Medicine | Drug Discovery with GANs (TensorFlow Tutorial)

hello world it’s Suraj and drug discovery that’s the topic of this video as part of the AI for business series in this video we’re going to use AI to help solve the problem of drug discovery what specifically I’m talking about is the process of finding new drugs for diseases right this is what researchers in biomedicine do this is their full-time job right and when I say diseases we’re talking about cancer aids Alzheimer’s all these major major diseases out there that have to go through the medical pipeline right the clinical trial pipeline to go from research to production where these drugs are being sent out to Pete real people for use how do we do that right now that pipeline takes about 12 years that’s a very long time right in AI we just published papers just left and right right the field is moving like this but when it comes to biomedicine it’s a very slow process so we’re gonna learn in this video how to solve the problem of drug discovery using AI specifically the model we’re gonna look at is a generative adversarial Network I’ll talk about how all that works but first I want to start off with this very cool tool that was built in Python okay this is a tool built with Python in the flask web framework and what it does it’s a great tool if you want to try to tackle this problem what it does is it lists out a bunch of different drugs right these are the molecular compounds that all of these chemicals consist of and what we can do is we can see in this 3d graph what all of these features each of these accesses are features for these drugs and on the left you’ll see the the molecule for that drug show up right qu’atsu pam tiotropium etc psilocybin Theobroma theobromine I’m gonna I’m gonna mispronounce a lot of these but right so we could do that that’s one way we could visualize these molecules and another way is for us to just type them into this drop-down right there’s a there’s a bunch there are so many here dan drew dentro dantrolene right and so we could we could see these down here the ones that we select in the drop-down each of these chemicals right each of these molecules has an Associated data sheet that lists all of its features right there’s a whole tech sonna me an entire literature around how to classify these drugs into different groups the types of drugs their description their chemical structure synonyms for them what do they consist of what are their ingredients and what prescription products they’re in right now and and how do they get into the bodies of real people right so drug Bank has an amazing amazing list of these things and and the best way to access that I think is through this drug Explorer plot you’ll find a link to it in the video description by the way so I just want to start off with that as a supplementary tool eventually the code we’re gonna look at in this video that’s helping to solve this problem is a model called chem Gann okay so Chemical generative adversarial Network it’s off of a recent paper from last year and these researchers applied generative adversarial networks to the problem of drug discovery right so it’s very it’s a very recent application of AI and we’re gonna get there right so the first thing I have here is an image of a disease and then candidates for the for that drug right these are possible drugs that could cure the disease possibly and then we have this label here that says discriminator and the idea here is that we’re using again we’re gonna call gan Gann from now on for short again can be used to solve this problem the question is how right that’s that’s the question of the video but before we get there we got to talk about how drugs are discovered right now we can’t just we can’t just flip up the process without trying to you know see what the process is right we can’t disrupt to get technical so how are these drugs discovered right right now it’s going to take anywhere from six point five to twelve to fifteen years to get these drugs to the market right there’s this entire pipeline you can see here of drug discovery preclinical trials clinical trials and then the all all powerful FDA review and then finally you get an FDA approved drug if you’re in the u.s. different countries have different regulations around this so keep that in mind so also 90% of all I thought this was a very interesting statistic ninety percent of all chronic clinical trials in humans fail even after the molecules have been successfully tested in animals which is a it’s a huge number and there’s a huge room for improvement there so how does this process work let’s just get down into it it’s the first step right if you are a researcher in this field you study biomedicine you went through your undergraduate degree you did your graduate degree you did your postdoc and you’re ready you have studied 12 years to get to this point by the way I want to make one more I want to make one more short note here machine learning and AI technologies are the great democratizer of our time what I mean is here’s what I mean that normally they would take you 12 years to get to the point where you can make a valid contribution to this field and only those researchers could make drug discoveries when I say democratization I’m not just talking about special powers like classifying images and detecting credit card fraud and that this was only limited to fraud specialists now anybody who understands machine learning can do it anybody in the future who understands machine learning will be able to do literally anything as these models improve so what I’m saying is if you’re if you haven’t done 12 years in school studying to be a biomedical researcher if you understand machine learning you can just leap over that 12-year requirement because think of the training time for machines as a sped up version of having a human have to learn all this right we got it it takes us so long to learn anything right we gotta eat food we got to learn we got to go to sleep we got to take a break we got to get our you know special time on all this stuff so it’s a there’s a lot there’s a lot there and ideally we could speed all that up and that’s what machine learning is you don’t have to be a biomedical PhD you could be some kid in Tunisia and make an incredible drug discovery using these tools the datasets are online they’re publicly available and yeah you got this basically believe in yourself no one believes in themselves these days people are weak you got to believe in yourselves clearly I’ve been watching a lot of Gary Vee so oh man okay I love doing this anyway here we go step one is studying medical literature okay of this pipeline here they have to study all the different interactions between different drugs diseases what what has been done before right that’s the initial step that’s in any kind of research what has been done before and once they do that they can find out what the target for the drug should be ie what proteins should this drug bind with the next step is figuring out what all of those properties that I talked about before for the drug should be drugs have a whole bunch of different properties and once you know what the drug is that that’s your hypothesis you got to figure out what the properties of that drug should be right well soluble soluble should it be what are the specific structures for this drug should it treat this kind of cancer or this kind of cancer you got to figure it out and then step three is figuring out which molecules have those properties right so I know the type of drug I know what it should be going after which molecules that exist currently have those properties right and molecules are dynamic structures they can be complex they can consist of multiple chemicals it’s not an easy process so one standard this is serious go look this up a standard database for drugs that you’ll find publicly has over 72 million different molecules that’s a lot of different molecules complete with their formulas some properties etc etc does a certain molecule cure a certain disease that’s the research process look at the space of possibility 72 million don’t tell me this is not a problem for machine learning humans aren’t going to waste their time looking at 72 million different possibilities that’s just not that’s not human it’s machine learning okay step four once you’ve got this you have this basic idea of the molecule you have to start experimenting now this right now is not done in silico what I mean is on a computer it’s done in real life with real human or sometimes animal trials so check this out from zero to regulatory approval to the market eight to twelve years that’s a lot but they’re ideas these researchers call their ideas lead molecules are sent to the lab for experimental validation and in the lab that can test whether or not it works right does it work does it not work and a very small percentage of those drugs actually do work of small percentage and we need to be a need to be confident about what drugs will work and what drugs won’t work and right now we’re not eventually ideally we can get to the point and this would speed up the entire pipeline we’re in silico we could decide this is the best drug for humans and just go straight to market we don’t need to do any human clinical trial testing we could do this in simulation this is an open problem and someone who has the Moxie or the courage to do that should just do that I’m just saying all sorts of words today moxie what is that New York slang I would I lived in New York though yeah anyway the bio pharmaceutical research and development process is way way too long okay I’m just trying to drill that into both your head in my head is that it’s very long that’s why there is such a room for disruption when it comes to a profitable AI startup anything you can do to speed up that pain point for both for researchers for pharmaceutical companies for governments for consumers anything you can do you can say you know they say the best idea for a startup is one that can offer a 10x improvement if you could say I can give you the result in one year instead of ten there you go there’s your 10x improvement so check this out even if the goal even if the goal is to treat cancer there’s no hope to check the entire endless variation of small molecules in the lab 72 million is just the size of a specific database that all the way to 72 million but the total number of molecules is estimated to be between and this is scientific notation 10 to the 60th to ten to the two hundred different types that’s combining all those 72 million molecules basically a lot so synthesizing and testing a single new molecule check the cell here you go in a lab may cost thousands or tens of thousands of dollars there’s your there’s your 10x right there the early guessing stage is really important and this is where machine learning can come in we can use machine learning models to try and choose the molecules that are most likely to have the desired properties of what we think so when you have 72 million of something what kind of problem is it well it’s less of a classification problem which of these 72 million is the right one because there’s 72 million right this is not hot dog not hot dog this is 72 million and it starts becoming something more like a generation problem what do let’s generate something from these 72 million because there’s so many different classes out there so instead of looking for the needle in the haystack we’re going to design the perfect needle as in we’re gonna design the perfect drug so said dr. evil haha we’re gonna design the perfect drug right okay also AI can be used for good it can be used for evil it’s up to you to use it for good alright this is your responsibility you are the chosen one all right this is like Star Wars where you know obi-wan was like you were the chosen one Anakin you were supposed to use the right tools of AI for solving gun okay so history of ml in drug discovery what is the history of him what has been done here so that’s the question that I’m trying to ask here’s this paper that used recurrent networks okay I have a link to it we’re not gonna go over the whole paper we’re just gonna look at it a little bit generating focused molecule libraries for drug discovery with recurrent neural networks what they did was they consider this a classification problem where they had a database of drugs and whether or not they made a certain disease active or inactive right so in that way there’s a bunch of different ways that we can class this problem right we can say this is going to be a supervised problem we can say this is going to be an unsupervised problem we can say this is gonna be a generative generative problem a discriminative problem in this case they classified it meta as a classification supervised problem with labels so in their drug database they said what we know that these certain drugs made these diseases active or inactive so let’s learn that mapping and then given some new drug we’ll be able to predict whether or not it would work right so for for our target and what they used was a recurrent Network and the reason they used a recurrent Network is because recurrent networks are really good at predicting sequences and when we look at these drugs the fingerprint of these drugs can be broken down into a bunch of ones and zeros or different letters different chemicals right what is the sequence of chemicals that’s going to be ideal for curing this disease okay so they did that another effort and I’m just going to show you this one more before we get to our our real demo is this paper which use convolutional net works right so convolutional networks are good for detecting or for classifying images they call this atom net a deep convolutional net work for bioactivity prediction in structure based drug discovery so how can we claim frame this as an image classification problem right so if we look at this B right here what they did was they use this network to predict the bio activity of small molecules for drug discovery applications right so what we can see is an image using a microscope of the bio activity of a certain drug what are the patterns how are these molecules moving in which direction how are they interacting and we can see all of that and we can classify it and we can say well this is how the bio activity is and here is how it’s interacting with this specific disease let’s learn the mapping well let’s just keep doing that for all of these different diseases right and so then given a new image of a new type of drug it can learn the mapping of it all it’s likely to solve this so that’s what they did for that right they used an input layer multiple 3d convolutional layers fully connected layers and a logistic cost layer that’s just standard really when it comes to convolutional neural networks by the way I have an amazing video on convolutional networks if you search convolutional Network Siraj on youtube first link because I dominate this space on YouTube back to generative adversarial networks so here’s our here is our demo okay so ganz and I talked about these as well but just not in this like applicable real world you know use case ganz are awesome they were invented about two years ago by friend of mine in Goodfellow and what they are are two different neural networks and the idea is that they are adversaries right one network is the discriminator the other network is the generator let’s start with the generator the generators job is to generate some image based on some sample data set let’s just say you know in our case it’s a sample drug data set I’m just gonna the generator is just going to generate some novel drug and say oh here we go the discriminators job is to take that output from the generator and say is this a real drug is it is it really from the database you know a binary input output or is it a fake one and it’ll it’ll judge it and then it’ll keep going right so what’s happening and they’re both being updated via synth via gradient descent which is an optimization strategy over time watch my build a neural net and four minutes video to learn more about that also backpropagation in five minutes I have contests about every single word I’m talking about in video form anything you don’t understand just search Suraj and then the topic that literally I am that certain I have a video on everything when it comes to deep learning at this point so and I’ve tagged my video as well so you will find them the discriminator is learning and the generator is learning the generator is learning to get better and better at generating images or you know whatever drugs that look very real and the discriminator is getting better and better at detecting what’s real and what’s fake so they’re both getting better and better over time it’s like a minimax game like with the Nash equilibrium to get more technical I have a great video on Ganz as well we’re not gonna go into the the deep deep details here my point is that this is at a high level how it works we’ll get into the code at the end and what they did was these researchers for chem Gann they applied this to generate new drugs right so I didn’t I’m just I’m just like winging it from my brain like how this works but we’ve got this beautiful helper image here to add some clarification the generator is using random noise and that’s all it’s starting from as its input and then it’s generating an output and at first of course this outputs going to look like nothing but because both of these both of these networks are updated using back propagation the same gradient that’s used to update the generator is used to update to the discriminator so that random noise those layers that it has to go through over time those layers are gonna apply certain matrix operations to that input data such that the output is more likely to look like what the real sample data looks like and the same from the discriminator so tans have been used for all sorts of things from generating images of faces that look real but they’re not they’ve been used for generating music all sorts of different data types right so well what about molecule it’s right what about drugs can we use Gans to generate drugs well there’s a type of game that we could use that the people in this paper the researchers use called an adversarial auto-encoder right so here’s how it works the idea is to learn to generate objects from their latent distributions right so with when it comes to an autoencoder the output their input so you input an image and it’ll output that image you might be thinking why why is that useful what’s useful is not that output it is the learned latent representation right that is the compressed version of that image it represents the same image but in a compressed space right a latent space and once we have that space what they did was they use this light in space to Jen generate molecules from right so it looks like this so it will learn that latent representation which is a set of features that encode the input in such a way that afterwards the subsequent layers can decode that object back so they took this conditional auto encoder and trained it to generate fingerprints that’s just a collection of drugs of molecules using and serving desired properties as conditions these conditions are different features that are encoded as numbers that are then applied to the input by applied we’re using some kind of matrix multiplication right and then eventually it’s going to be able to generate drugs that look real but they’re actually fake and they’re new they’re they’re novel drugs that have never been applied to any of these use cases for these diseases and eventually we’ll be able to take that drug combination and apply it in clinical trials and then people can use it and it would work and this would speed up that whole first and second part of this process that I talked about by orders of magnitude and also also the the deep learning community took took note of this right so by the way a simple screening of the database can find molecules with the fingerprints most similar to the generated ones yoshua bengio yan laocoon these are the godfathers of deep learning they really really like this idea right so here’s that here’s the most interesting part they really like this idea and it didn’t work that well like it didn’t really work that well because there was some tweak that was missing so there basically there’s a lot of opportunity in this space ok so check this out Kim Yan let’s take a look at this in the model what do they got here they got ogun de pie again the pie okay so here’s their here’s one of their model they they had several models but we’re gonna look at a few of them okay so they’ve got hyper parameters for both the generator okay we got a number of hidden dimensions they’ve got hyper parameters for the discriminator by the way you can download all of these models from github in the readme they have instructions on how to install how to run them and you can run them just like that if not if you don’t want to run them on your local machine because you don’t have a GPU I don’t have a good one you can use a cloud service floyd hub it’s great i love it it’s a layer on top of AWS that takes takes away a lot of the complexity so you can very very quickly get started no they didn’t pay me i just think it’s very cool so it’s like Heroku for deep learning great tagline by the way so the key here is that they’re both neural networks we can build them with Karos we can build them with tensorflow but the idea is still the same and both of these networks you’ve got a generator you’ve got a discriminator we’ll train at the same time right so in this case they use tensorflow to do this and they said let’s define what the discriminator looks like and we’re gonna train the discriminator using bit samples generated right here on line 270 by the generator we’re gonna feed it those samples and notice that there are two loss functions right there’s a loss function for the generator there’s a loss function for the discriminator and they’re both being trained over time right both loss functions are being trained over time and eventually once this model is trained they’re gonna save it to disk as a binary file and they could use that model then they could serve it they’re using tensorflow here so they can serve it using tensorflow serving which is a great tool for serving test potential flow models in the cloud right tensorflow serving this is how you serve tangible in production you can also use tensorflow j/s it’s very simple to use even models trained in Python you could load up in j/s it’s amazing I have a video on that by the time you see this that videos gonna be released so check that out it’s a continuous training pipeline okay so there’s a lot of potential here I hope you found this video useful and yeah please subscribe for more programming videos and for now I’ve got to use tensorflow so thanks for watching


  1. thank you for healthcare video, do you like prof. john koza genetic programming (evolutionary algorithm) for new electrical circuit discovery?

  2. Thank you so much for this video. This is exactly what I was looking for 👍 please make more videos on how AI can disrupt the STEM field. No rush.

  3. it's even worse, many studies the last 20 years show that many new drugs aren't more effective than placebo. So the 90% statistics isn't totally accurate. I'm gonna disagree with the statement "you don't need a biomedical degree". A person might not need a degree, but they can partner with someone with the expertise. The medical field is so specialized treatment requires domain expertise. Testing molecules "in simulation" is nothing like a real medical trial and any biomedical researcher knows this. What DNN/ML can do is narrow the choices to reduce the time, but we don't have a good way to simulate how drugs actually work in the body. Until someone figures out an efficient way to simulate drug interaction in a human, the best we can do today is narrow the list of potential molecules. I'm hopefully eventually some one will figure out how to model drugs in simulation, but right now that's just not possible. The best we can do is compare new molecules to existing drugs as a first pass filter.

  4. PReP is already the affordable preventative drug for HIV. AIDS itself can only be cured with a bone marrow transplant from a donor expressing the rare genetic trait of having white blood cells with no protein coat (and thus no ‘door’ for the virus to get in).

  5. Idea: can use use the News (perhaps through sentiment analysis of CNN, etc twitter stream), to create the news (news that hasn’t happened yet)?

  6. Really nice video, thanks again for your inspiration! I have a request : could you make a video about dome adaptation in computer vision? Or about the maths of domain adaptation? It seems to be quite complicated, but at the same really useful in many fields of ML

  7. drugs are not healthcare, nature is already smarter than us or our artificial creations, for this topic we don't need more drugs, we don't need them at all

  8. This guy GETS it. I don't think people get it… even if he says it plain as day… people just don't get it…

  9. Hey Siraj, several leading doctors are already working on healing and preventing these disorders in a subspecialty of medicine called Lifestyle Medicine. There are already many successful clinical cases and many published scientific research. You will be amazed!

    It is well known that drugs work well in critical cases, but for chronic diseases, in prevention and reversal, the remedy is unfortunately not in the hands of such a powerful and profitable industry as pharmacists. Note that cases of death from stroke, heart attack, diabetes, cancer, etc., only increase, along with the amount of medication, that only act on the symptoms, but not on the causes. An interesting work on this topic is Dr. Michael Greger's book (and lectures on internet) "How Not to Die".

    And another excellent work, also by Dr. Greger, is the site whose proposal is to make public the scientific research that exists in the area of health and explain them for a thinking but not so techical audience.

    Fortunately, we are slowly getting the right way. The solution is much easier than we think and within everyone's reach. But it needs a lot of good people involved, helping to spread awareness, creating tools, making a true democratization of information, and any initiative that helps people to make good decisions for themselves and your loved ones. Practically nobody needs to suffer or see someone suffering from these diseases nowadays.

    It would be spectacular if you, and geniuses like you, become familiar with all of this revolution that doctors like T. Colin Campbell, John McDougal, Neal Bernard, Saray Stancic, Michael Greger, and many others are doing. It is a exciting time to live.

    I am a videomaker (a little webdev) and graduating in Nutrition here in Brazil.

    And sorry for the long text. I really like your work here on youtube and I thought it was worth being pushing a little bit.

  10. Such a video can change the world
    By giving ideas to those viewers
    They might do something in the future
    Some people got lots of money
    They don't know what to do with it

  11. Siraj, thank you. You are and incredible resource, and a huge inspiration. My #1 go-to for machine learning tutorials.

  12. Thank you Siraj for popularizing my paper 😉 To learn more about AI for drug discovery, everybody is invited to join this challenge:

  13. Maybe you Should give a Look at this

    She is ZINI – a Diagnostic & Empathic Virtual Intelligence.

  14. I think that this approach might make money for current farma companies and industry, but won't really and truly increase peoples health. In most cases when someone has several health problems and he goes to doctors they sell him more and more medicine and this approach eventually kills this person. And your AI drug generator will just offer more and more to sell. Doctors and pharma will never ever tell you that if you go raw food vegan and healthy, organic, as natural and as raw food as possible, without eating dead corpses , denaturated , destructed in heat, and that artificial sugars never never to eat, and that for example nature created garlic – and garlic has thousands of naturally synthesized molecules – and garlic is so strong , healthy and may cure so many diseases, and a scientist will never be able to create something like garlic – he might extract some molecules out of garlic or synthesis something similar but it will not be like a perfect match for best human health – only organic, created by nature plants, herbs, mushrooms, natural medicines will give you a perfect match like a perfect key to an incredibly complex door lock and unlock it and will heal any disease. Cancer and AIDS are cured – with organic medicine, without any farmcutical companies industries. They are all bullshiting everyone! They are not interested in your health and wellbeing!!! Remember that. Their goal is to make a slave out of you! An approach which I think will give full information for a health seeker is – on one web page you get several doctor AI chatbots – western medical school chatbot, eastern , Ayurvedic chatbot, AI chatbot which learnt on maybe famous youtube healer with a 1000 videos and gives advice according to him, and Hyppocrat chatbot, Avicena chatbot, Paracels chat bot, homeopathic medicine chatbot, naturapatic chatbot and so on. From one page you can get advices from different medical schools and approaches and easily get a really full picture. This is what I want.

  15. Hello Siraj I have little problem with dash it said cannot import name_graph_tools how to solve this thank you in advance.

  16. i heard the other year that the british drug developers try their novel drugs on your fellow Indians by hiring them to take the risks. from your vid, i see they're going to launch 10000x more trials. AI must solve that!!

  17. Love your vids man! Everytime I take a look at your channel, you are talking about something amazing. Thanks for sharing the knowledge!

  18. Hey man. I used to follow your videos and now pursuing AI research. And you’re clear to beginners and great and spreading AI knowledge.

    No offence but you sound really full of yourself in this video. The words, “I have a great video of __ “ came up so many times this video. Dude go back to the way you were originally. You got me interested in AI. But Don’t make me stop following you.

  19. i'm too slow to understand this. but hey i'm interested.guess you try it understand it randomly until you get a pattern.

  20. didn't even finish seeing video and I felt compelled to like it. this is an area I'm very interested in too! good work and keep it coming

  21. I work for Drug research and development company…Drug Discovery with GAN makes more sense. Thank you @siraj

  22. 6:22 omg dude this is why i support you on patreon … why do i always feel like you are speaking right to me … i fuckin love u dude no homo but i love u dude

  23. 11:42 "AI can be used for good,they can be used for evil, it's up to you to use it for good, it is your responsibility"… uncle Ben ?

  24. AI will be the great democratizer specially in the field of drug discovery. Thousands of human PHD’s take several years to make a most effective drug discovery, that a GAN like AI can do within one day. Our entire health care industry motivated by profit which makes it essentially corrupt. Most of the drugs used to treat the disease of the poor population are several decades old and redundant still the drug companies continue to push these drugs because there is no financial incentive for them to discover the better new drugs. AI in drug discover will change it all. Tech kids, startups from poor countries can discover better new drugs and make those big business go bankrupt if they don’t change. The democratization ushered by the AI technological progress will bring great equity in human society.
    My basic theory on this subject ,

  25. Hi Guys, I am currently creating an application to help medical professionals detect diseases/features from medical images, through deep learning, and would like some insight from the medical community, as it would immensely help with the design of the application. Here's the proposal website: and here is the survey form:

  26. There's more than just drugs to better make a whole person. My AI would focus on the whole patient. Save us from big ahem//

  27. Hello siraj I know that you had a robotic startup. Could you please make a short video for people who want to integrate robotics and machine learning thank you

  28. Hi Siraj. Thanks for the video. How would you go about performing faster clinical trials (possibly by using AI and ML instead of living organisms) to find out which of the new drugs are statistically significantly successful in fighting given diseases?

  29. Can an autoencoder do the same thing as a GAN?? Or are they too different and must be combined??

  30. Great video. It felt like a friend of mine explained to me possibilities of ML in drug discovery over a beer.

  31. @Siraj Raval

    can u make video for petrochemical synthetic discovery with GAN's?

    …or to use GANs to discovery what are the actually needs of the petrochemical companies/industry are/is?

  32. Siraj, I am learning AI so I will be watching your videos no matter what. But I wish you had spent more time on explaining the GAN for drug discovery because some of the things you said about how AI could help drug discovery are quite a stretch. Motivating people is a great thing but we need to have a sense of reality here.

  33. Hi Siraj…Im currently doing a research on cancer classification through multi-omics features using Generative Adversarial Network (GAN). But im slightly unsure about the application of this algorithm in my case. My dataset will comprise positive & negative cancer data, so does that mean i have to input 30% of my unprocessed positive & negative cancer data into discriminative model and expect the other 70% of data to be classified accordingly? Do i need to do pre-processing of biological data before implementing GAN?

  34. That was a such a help, I gave my presentation today referring to your video, Everyone liked it!! yay!! Thanks.
    Although ChemGAN paper has few things which are not covered in this video. but, still the video is the best material on youtube.

Leave a Reply

(*) Required, Your email will not be published