Let's Build a Quantum Classifier! LIVE
Key Takeaways
The video demonstrates building a quantum classifier using the Penny Lane library and explores concepts like quantum entanglement, superposition, and Shor's algorithm for prime factorization. It also discusses the basics of quantum machine learning, quantum neural networks, and the application of quantum computing in cryptography and optimization problems.
Full Transcript
two one and we are live hello world it's siraj and welcome to this live game show in this episode we are going to build a quantum classifier together and that's what you're seeing right here next to me this is a simple quantum classifier that i built using the penny lane library this is a quantum neural network free library that anybody can use it's available on the internet and i'm going to show you exactly how to use that to build your own custom quantum neural network now i know that this might seem a little daunting but it's not trust me it's actually pretty easy we just have to go through a few concepts before that and guess what someone's going to win 500 in the next hour if they can answer all three of my questions but in order to answer my questions they have to pay attention to this all right so we're going to go through a lot of concepts in a short amount of time and guys my internet is kind of spotty today so if anything goes wrong trust me i will create another version of this video this information is far too valuable fully edited and without any hiccups all right so if something goes wrong during this live stream don't worry i've got you all right we're gonna create the world's most valuable esport over the next five to ten years slowly by creating these winners people who win my games one by one for cash prizes where i'm really focused on the cash prizes for you guys i want to reward you guys for having subscribed to this youtube channel all right so where do we begin with quantum classifiers i mean there's so much theory behind quantum computing there's so much theory behind machine learning and how are we expected to combine these two ideas together well i want to start with a very application focused problem for you okay we're just going to focus on one thing i'm not going to go into what's a qubit a qubit is a one and a zero at the same time what everybody does i'm not gonna do that we're not gonna rehash quantum mechanics and stuff we're gonna focus on a simple problem that you and i can sit here and solve together and that problem is we want to break bitcoin mic drop we want to take all of the bitcoin from satoshi nakamoto the creator of bitcoin from his account that's our job today in this live stream and we're going to use quantum machine learning to break the entire bitcoin network let's see if we can do that together all right so how are we going to break bitcoin that's our task for the next hour we're going to try to break bitcoin and bitcoin is one of the most powerful networks in existence now i literally wrote a book on this right so i'm not going to sit here and talk about all the details of bitcoin but i will talk about one part of bitcoin that is relevant to us and that part of bitcoin is the public private key pair generation so any time that you create a bitcoin wallet you know your own bank account right on your phone or laptop you get two sets of numbers and letters those are called your public and your private key pair now with your public key pair anybody can send you money so i want to if i want to give you my public uh key pair those 25 characters down here then you can just send me as many bitcoin as you want but if i give you my private key pair then then you can steal my bitcoin so i don't want to give you my private key pair now that's the basic idea behind bitcoin security your public key pair people can send you funds your private key pair uh you never want to give that out and those those two key pairs are generated using an algorithm now what algorithm is bitcoin using to generate the public and the private key pair well it's called the rsa algorithm now i know that there's a lot of text right next to me and guess what i don't want you to care about any of that don't look at any of that all i want you to look at is the first line that's all we care about so rsa is the algorithm that bitcoin uses to generate a public and a private key pair and rsa stands for the initials of the inventors of the algorithm i think it's like ramir shamir something like that it doesn't matter but the first part of the rsa algorithm is to start with two large prime numbers now recall prime numbers are numbers that don't have any factors the only factors it has are 1 and itself nothing else it has no multiples 2 doesn't divide into it 3 doesn't divide into it nothing divides into it so what's a prime number seven is the prime number because what divides into seven one and seven what's not a prime number eight because what divides into eight two four and eight you see what i'm saying that's what a prime number is so the rsa algorithm generates a public and a private key pair starting with two large prime numbers so we don't know what those prime numbers are we just know what satoshi's private key is but assume we did know assume we knew what those two initial prime numbers were then we could reverse engineer the rsa algorithm to find out what the private key pair is that's that's the idea if we can find what those two prime numbers are then we could reverse engineer and find that private key from satoshi now that is a really exciting idea um the the idea of being able to find out what the private key is for such a valuable bitcoin address now if we figure out how to do this we're going to immediately give this solution to the bitcoin core developers so they can patch it because we want a quantum resistant bitcoin blockchain because we love bitcoin we don't want to destroy bitcoin actually we want to security test it so we need to find out what those prime numbers are given a private key how do we do that well this is you know a big part of this problem of finding out what those two initial prime numbers are is the prime factorization problem that's a huge part of that problem so we're going to focus on that part of the problem so f prime factorization means can we find all the prime numbers in a given sequence of numbers so let's say give me all the prime numbers um up to 10. let's see 1 uh 2 3 5 7 that's it right those are the only numbers without multiples now give me all the prime numbers up to 1 million you can't do that using mental math right so we can we need an algorithm to do that so let's look up an algorithm that's going to help us find all the prime numbers all the prime factors of a given number let's go look this up so the first thing we want to do is we want to go and find an algorithm that does this i mean there's so many potential algorithms that could help with this but there's one in particular that i really like and you may or may not have heard of it it's called the sieve of aristostanies so i want you to say that again sieve of aristos ancient greek beautiful language in fact it's an ancient algorithm algorithms can be ancient too algorithms are all around us you know just computing is one way of making them repeatable and letting us engineer them but we are not in control of all algorithms some algorithms are outside of our control back to this so the sea of aristocenes consists of five steps and we're going to write out the code for this in python together we're going to write out simple sieve of aristocene's code for prime factorization because we want to break bitcoin because we love bitcoin the first step is to create a list of consecutive integers two through n so let's say n is ten so two three four five six seven eight nine ten the second step is to initially let p equal two the smallest prime number so okay p equals two that's it the third step is enumerate the multiples of p by counting in increments of p from 2 p to n so that goes 2 p 3 p 4 p 5 p 6 p 7 p so if p is 2 what are those numbers 2 4 6 8 10 12 all the way up to all the multiples of 2 up to n number four is to find the smallest number in the list greater than p that is not marked if there was no such number stop otherwise let p now equal this new number which is the next prime and repeat from step three when the algorithm terminates the numbers remaining not marked in the list are all the primes below n so that might seem kind of confusing to you but luckily for us wikipedia has this other way of explaining uh the sieve of aristocenes and it's right above me i want you to read this together it's a little poem it says the sift sift the twos and sift the threes the sieve of aristostanis when the multiple sublime the numbers that remain are prime now that is a beautiful poem i love that poem and i i see some smoke coming in my backyard hopefully nothing's on fire okay we're fine if anything on fire doesn't matter we're we have a live stream priorities people so um that's the sieve of aristocenes basically we're looking for all the multiples of two and three up till n and then we want to slowly increment and and find all of those prime numbers up till n using two and three and if we can do that then we will find all the primes up to n so that's the idea so let's let's code this out using a google code laboratory which is a essentially a python notebook a jupyter notebook uh in the browser which is very very simple and easy for us to use so our first attempt here is going to be to program the sieve of aristos so let's just program the steve of aristocenes together and we'll see if it works out so the first thing we're going to do is we're going to import sys simple library and we're going to define all of what makes this bigger we're going to define all okay we're going to define all of our code here so this is a factorizer remember this is a part of the big problem of breaking bitcoin so everything's going to go in this factorizer function so the first thing we're going to do in the factorizer function is we're going to say given n n is our number that we want to find all the prime factors of we're going to start with an empty list so this empty list we're going to start off with the number and we're going to typecast it using uh int and then we're going to create an empty uh char array which we're going to fill with all the prime factors in a second so let's do our first for loop so in our first for loop we're going to go through a thousand numbers let's just say arbitrarily a thousand numbers we can increase this in a second but we're going to go through a thousand numbers and we're going to initialize those as empty numbers that's our first step our next step is to create a list of all the multiples of two so remember in that c of aristoceny pseudocode that we just read we want to find p we want to define p p is going to be two and then we want to find all the multiples of two so one by one by one by one by one we will define all the multiples of two and then we're going to divide all the multiples of of two one by one so while k times j is less than or equal to n and we're going to continually multiply k by j where j is going to increment in factors of 2. k plus equals 1. right because we're going to increment slowly and there's one more loop we have to do and then we're done with the sieve of aristocenes and that is now that we have all of those multiples of two um let's print out all the prime numbers that were not multiples of two or three and the reason is because prime numbers are unique in that they are not multiples of two or three every other number is a multiple of two of three except for prime numbers and so we have now printed all that out and we can return the total of course there's going to be there's going to be a an error here um make sure that that's all visible of course there's going to be an error here there's no error so that's great so let's let's try out our algorithm what do you say what do you think this is going to work let's see if it works so if n equals 9 what are all the prime factors same while i print this out hopefully this works hopefully the sieve works factorizer n here we go here's our algorithm what l is not defined um factorizer n line 20 uh that's i not l that's what that is that's what that is okay now what's the problem l is not defined okay i see it l again i don't know why i'd put l i should put i all right now let's try it two three five seven there you go i mean i put i should have put spaces between each of those charts but those are the prime numbers up till nine now let's switch this up let's say that instead of remember in rsa rsa is not using the number nine rsa is using two very large prime numbers like giant prime numbers so if we want to find the prime factors of giant prime numbers let's put in 9 million 9 trillion whatever what's going to happen is we're going to have a stack overflow list assignment index out of range which means that we have to increase this 1000 up to a really big amount and even then it's going to take a long long long long long long long long long extremely long time that's going to take longer than the age of the universe if if it's a big enough number like a really big number so we have a problem here like the sieve of aristocenes is not going to work for us we are screwed in terms of the sieve of varicosity so we need to figure out what to do instead and so i have a better solution than the sieve of aristocenes now i'm going to need your help for this better solution so in order to find the better solution i'm going to ask you a question and the question is the question is um ah where's my thing what is one way we could possibly improve the time complexity of our prime factorization algorithm i'm not sure why i'm not seeing this overlay like it always should um if that's the case that's fine i'll just figure out hacky solution here give me one second guys we're gonna get these questions up for you i want you guys to see people putting the answers in um okay here you go so so the question is what is one way we could possibly imp what is one way we could possibly improve the time complexity of our prime factorization algorithm should we use linear regression should we use quantum should we use blockchain or should we use k means clustering how should we improve the sieve of aristocities like we want to break bitcoin how are we going to do that i see that most people are answering one question here most people are answering a single question a single answer so but one person answers something else so i think most people have the right answer here uh which is good and meanwhile while you guys answer these questions let me answer any questions if you guys have any i'm not seeing any super relevant questions right now um but meanwhile i can't believe this uh overlay didn't work this time that's sad you know live streams not everything always works perfectly but that's okay we could still see this so let's see the answer now guys um i'll give you guys 30 more seconds while i talk a little bit more about what we're going to do now so we tried out the sieve of aristocenes that wasn't good enough and so we want to improve it now we're going to use one specific technology to improve our prime factorization problem because we care about real-world applications there's one question that i am seeing right now that seems relevant too i'm going to answer those and then we're going to move on is this the algorithm you wrote the paper for no no it's not this is not the algorithm i wrote the paper for uh that was a bunch of google translate and it's been a year since then and autocorrect and like complicated hilbert space complicated is not a word it's complex hilbert space we actually will be talking about that in this live stream um what else did i get wrong in that paper that became a meme um there was like a complicated helper space it should be complex oh logic uh doors it should not be logic doors they're logic gates and that's actually what the song at the end is going to be about when i freestyle for the winner in tribute um the mind is a muscle and so you break logic doors that's the line so a hershey related title said python syntax good to see you again related title he said python syntax always confuses me look you know really you know because i think of it as more readable but i will keep that in mind if i see enough people complaining about python we'll just switch over to c i am language agnostic guys we care about algorithms we are not um we are not some kind of tribe for a language or anything we care about algorithms and the most efficient way uh to write them okay so let's see what the answer was now that we have um like 35 people who have answered this the answer was b quantum that's what we're going to use to solve this okay quantum is the answer always always so if you got that right good job hopefully that wasn't too loud let me lower that volume sorry guys if that was too loud okay so we're gonna have to use quantum to solve this so um let's use quantum to solve this together all right so uh oh my god there's so much i need to tell you now about quantum okay how are we going to solve this well well well well i have some math for you people i hope you're ready for some math um but before we get to the math i just want to very briefly show you shore's algorithm this guy sure what a g um in 1994 in 1994 um shaw was trying to solve this problem as well he was trying to solve the problem of prime factorization how do we efficiently calculate all the prime numbers up to a given number and he made this wonderful algorithm in seven steps called shore's algorithm and he called it shorts algorithm we're going to talk about shore's algorithm in detail especially the quantum aspects of it and why quantum computing is necessary for short's algorithm to work properly and i know this might seem a little mystical so we're going to go through this kind of slowly but i first before we get into the math i just want to read out the seven steps of shore's algorithm with you here together and i'm going to make them a little bigger because i really want you to get get this part so shore's algorithm has seven parts the first part is to pick a random number we can do that right let's say we want to factor all the prime numbers up till n so up till n and n is 10. so what the first step is to pick up random number let's say i don't know 6. um then the next step is to compute the greatest common denominator of that number and n so um 6 and 10. now there's a lot of ways to do this but the one way to do this that shore uses is the euclidean algorithm and we could just treat that as a black box but assume that we found the greatest common denominator of both of those numbers that is the biggest number that divides into both both that random number and our number in question n the third step is to say well if the greatest common denominator is not equal to one we're done we found all the prime factors otherwise we're going to use this function this magical period finding function to find all the prime factors and we're just going to call it this magical magical magical magical function it's a black box we don't care about it it's step four we're gonna go right to step five six and seven and then we're done step five is to check the outputs of that period that's that wave that sinusoidal function that fourier like function uh number five is if it's if r is odd if one of the outputs is odd return back to step one number step six if a r divided by two equals negative one mod n go back to step one again just a random series of operations number seven the last step if the factors of n are the greatest common denominator of these two uh values we are done so essentially it's a bunch of operations that are being applied to our number n and a random number that we generate the greatest common denominator function is just embedded inside of this algorithm as a euclidean algorithm but the real key of shore's algorithm the real mystery the black box of shore's algorithm is this period finding routine right here a to the x mod n okay now that seems very very very confusing because what does a period have to do and i'm so excited to explain this part to you because i understand this and i can and that's only because i think the only reason that i fully understand this is because i've been looking at machine learning for so long and quantum computing and all this stuff and so i'm going to explain exactly what this period finding algorithm does as best as i can this is going to be quite a challenge but i am ready this is the kind of challenge that i love so let's get our markers ready and let's bring up the math cam let's bring up the math cam okay all right so so so so so so so what do i want to show you here well where do we even start the place i want to start is with probability theory because we love probability and machine learning right so assume that assume that we want to find the probability of um we want to find the probability of a coin flip let's start with a coin flip the probability of a coin flip um is going to be equal to probability of heads plus probability of tails um so that's like a really simple way of measuring probability right we're just writing out probability uh in that way which is pretty simple um but there's other ways of writing out probability like uh we don't have to write out probability in that way we can write out probability as a series of states so we can say that that we want to find the probability of i might be getting some questions here in a second um you know probably you know we can write probability what else can we write we can write out we can write out so first of all let me talk about the math that we're about to use we're going to use linear algebra we're going to use probability and we're going to use eventually calculus but that's for the gradient-based optimization part at the very end right now we're just focused on probability right i just showed you a little bit of probability now i want to show you some linear algebra so if we have some scalar number m okay we have a scalar number m we might want to multiply m by a vector and this vector is going to contain a bunch of numbers 1 2 and 3. okay so that's m times 1 2 and 3 is going to be equal to another vector and we're going to call the outputs of this vector vector a b and c and so we have m times 1 2 3 equals abc this is a matrix operation we're performing a a multiplication operation between two vectors these are groups of numbers together and the great thing about linear algebra one of the great things about linear algebra is that it provides us with this set of operations that we can use hold on it's gonna be black for a second it provides us with a set of operations we can use to multiply groups of numbers together not just single numbers but groups of numbers together and that's really powerful because we can say things like 1 0 1 0 you know times i'm going to make this really straight time 0 1 1 0. we can actually do that with linear algebra right so it's like this part times this part and then it's like it's like this part times this part and then this part times this part and then this part times this part and the result is gonna be a 2 by 2 matrix that's linear algebra so i just want to really briefly like show you define linear algebra and probability theory for you for the next part of this because we're going to use linear algebra and probability theory for this part which is what i'm going to show you right now okay so that's linear algebra and probability theory now why does that matter to us well there is this idea called the fourier transform and if you don't know what the fourier transform is it looks like a sinusoidal wave it's like a wave like this and it's going to be a function a sinusoidal function like cosine of x or sine of x you know it could be anything like that so let's just say that this one is called sine of x what the fourier transform does is it helps us define the parameters that we're going to need for short's algorithm um it's it's essentially a linear transformation on this function um all of deep learning is essentially a bunch of linear algebraic operations and that that that idea of linear algebraic multiplication addition we're going to apply to quantum computing so now that i've talked about um probability i talked about what linear algebra is i defined what a sinusoidal function looks like now we can finally talk about all of that in the context of shore's algorithm so in the context of random drawing in the context of shore's algorithm here's what that means steps one one two and three were just normal find the greatest common denominator remember step four was that weird part we wanted to define this uh transformation function now what we can do is we can define this transformation function as what's called a quantum gate and a quantum gate is essentially think of a logic a normal boolean logic gate it's got a true or false statement a quantum gate isn't just true or false so a normal logic gate is going to be you have some data and it's flowing through this graph and then you hit this boolean logic gate and it's going to say true let's just say in this case it's going to say true and then it's going to hit true and it's going to output something it's going to be true that's normal boolean logic right but in quantum computing a quantum gate isn't just true or false it's going to be something else it's going to be a block black box that's going to have a set of values that's essentially all it is it's just numbers numbers are in here numbers one zero zero whatever the numbers are but we call these numbers one of two things they're either in a super imposed state so superposition or entangled those those those are the two primary um those are the two primitives superposition and entanglement that we are adding to our programming vocabulary for short's algorithm now which part which of those two applies to schwarz algorithm we're not even going to worry about entanglement that's not even in this video all we care about is superposition the idea is that if we take whatever some input is and we perform a certain linear algebraic operation on it then the result will be a superposition of possibilities now that's what i want to talk about right now that's the weird part that's the almost unbelievable part like what i what here's the idea we have some possibility space of answers for what the prime factors could be okay they exist right the all numbers exist somewhere in the universe and so we have this possibility space of numbers one 500 five five five five six seven eight nine you know all these numbers exist 32 and we have to predict what the prime factors are going to be right we because we live in a deterministic world that and we think in terms of quantum mechanics like force equals ma right newton's laws but at the smallest scales of reality these two this this idea of superposition applies and you know the word simultaneously is thrown around by every pop-sci youtube video or every pop-sci article but it's more than just simultaneously it's not just one and zero simultaneously it's it's accessing parallelized across different spaces to compute what the prediction should be essentially what a superposition does is it's like a web of possibilities that we can pre-compute before we even find the answer fully but these are all like waves like there's a 30 percent chance the answer is gonna be one there's a 20 percent chance that there's gonna be five five five there's a 32 percent chance your answer is going to be six seven eight that's what quantum computing is going to spit out for us and then we have to pick the highest probability one so you might be thinking how the is it able to predict what the answer could be all the possibilities is this some kind of time traveling machine no it is not a time traveling machine it's accessing parallelized timelines to compute this now on a simulator it's not actually doing this because you need what are called qubits that are using superposition in hardware to compute this but we can simulate the idea of superposition using um classical mechanics you know transistor-based classical computing uh the same way in that the result isn't going to be the true um the true amplitudes the words or amplitudes um i'm just gonna keep talking you're gonna get this stuff eventually um it's gonna it's it's not gonna output the true amplitudes because there's no way to predict that without true hardware superposition it's going to predict what the amplitudes could be so they're just random number generators so a true so quantum simulators are fun for research but if you actually have access to quantum hardware with enough stable qubits and i say stable because that's where the idea of entanglement comes in we want to uh minimize the coherence and that's really hard that involves quantum error correction we want to keep a quantum computing system stable you know super cooling has to be there there's a lot of techniques to make sure that quantum computing is stable and that's an area for the future does quantum computing work right now not no no it does not but could it work for the future to make machine learning algorithms more data efficient uh require less energy require less power become more accurate become more robust to perturbations yes absolutely i believe that and lots and lots of money is being thrown in that direction so back to this there's actually a possibility space of answers that schwarz algorithm can look at for all the possible prime factors and what the period the quantum fourier transform that's one of the um functions that's the key part of uh the offshore's algorithm it's a quantum fourier transform what it does is it finds r it estimates r and r is the period it's kind of like a clock it's looking at along this period that essentially the best way i like to think about it is that it's accessing parallels timelines across different spaces so i guess i have the many worlds interpretation of quantum mechanics as i'm using the penny lane quantum computing library because that's what makes the most sense for me because i don't think this is doing time travel i think that there are multiple spaces across reality and through superposition we can actually retrieve scalar values as crazy as that sounds from these parallel timelines and then use those scalar values instantly to improve the predictions of our models and so the quantum fourier transform is giving is spitting us back all of those r's those r values the possible prime factors of our number n and then we have to decide uh smartly using our algorithm which is the most likely now that's the idea so sure let me let me go back to me now because i have a lot more to talk about so shore actually proved in 1994 this idea of a quantum algorithm that we could code this out on a classical computer we could do that you and i but and it would work and you know it would compute properly but if we want to simulate if we want to use the magic of superposition and we want to actually find the answer in not n cubed time not in n squared time but in something really fast in say log n time then i think schwarz algorithm is long log n correct me if i'm wrong it's definitely faster than the sieve of and you know there arithmetic be an algorithm that's faster than chores but the point is that the point is that um we're going to talk for five more minutes and then we're going to code out this uh um algorithm uh shore's algorithm so um the point is that shor's algorithm it uses this idea of a quantum gate which is essentially a software construct a a quantum gate is something we built with software and it has nothing to do with hardware there's nothing mystical about it it's essentially just a set of math operations and normally with linear algebra we just multiply matrices and neural networks but when we apply linear algebra to quantum data that means data that's in a superposition data that has um imaginary numbers in it then we call that a complicated no a complex hilbert space it's a complex hilbert space so it's a specific type of linear algebra that we're using um to repeatedly apply a chain of our operations across quantum gates and so quantum gates use a specific type of linear algebra like involving hilbert hilbert algebraics what it's called um to make computations we can run that we can run those computations on classical machines which we're about to and they can work but if we really want if we really want um if we really want uh the best results we need to run some quantum hardware so all that is to say that we now need to code this i know what you guys like to see we got to code this guys so let's get back to the code we are now going to code out short's algorithm together and we're going to code out short's algorithm using no quantum computing because again i just want to show you that we don't need a quantum computer to do quantum computing quantum computing is orthogonal it is unrelated to quantum hardware that's just helps us get the speed up we need but quantum computing is essentially a theoretical branch of computer science that involves using linear algebra in complex spaces involving imaginary numbers that's really the key bit imaginary numbers are what we're adding to our jumble of linear algebra when we are doing deep learning that's at the very end we're going to combine quantum computing and neural networks together but let's now let's now code out um this this algorithm and then i'm gonna ask you some questions about what the next step is for us we're gonna i'm gonna ask you about imaginary numbers so i hope you're ready for that part all right so the next step is for us to write out some code here so let's write out some code for short's algorithm um in numpy make sure this is big enough for us because we are trying to break bitcoin guys we we love bitcoin we want to break bitcoin because we love it security testing so the first thing we're going to do is we're going to import numpy of course that's it and uh now that we have numpy we are going to um we're gonna think about what the answer is for this one um hold on there's some really great questions here so i'm just gonna actually show you my code rather than typing it out um quantum fourier transform i want to answer some questions that i want to make sure we have enough time so here is the here's the code for the quant here's the code for short's algorithm hold on make sure this is all in line i don't want to read out this code to you it's only 50 lines of code which is totally doable you ready to read this together guys so um in the first step in the first step in the first part of this code a lot of things we might want to do wow this kind of like froze hold on why this freeze hold on okay there we go in the first part of this code i feel like this is like broken or something hold on why is this not working hold on um guys we might have an issue i think we're fine we're fine here we go um if you look in my gists on github they're private right now i'm going to make them public don't worry i'm going to make them public so we start off with this hadamard gate i know that seems like a complicated word don't worry about it again it's a quantum gate remember all we care about is that a quantum gate is a logic gate we know what boolean logic gates are true or false they've got some set of math operations like quantum gate uses a uses quantum mechanics and specifically it's going to use a specific type of linear algebra hilbert algebra and what a hadamard gate is it's essentially just a matrix of values that when applied so that when i say applied i'm talking about matrix multiplication when applied to some vector it's going to turn it into a superimposed state so a superimposed state of numbers so it's essentially just a matrix times matrix it's just matrix multiplication like we're used to with deep learning except that terminology is different and the type of of multiplication is different because the type of vectors are different because they're quantum state vectors which contain data which represents superposition which is a possibility space superposition is a possibility space of different values across timelines i really hate to even say that across timelines it sounds so sci-fi i really can't think of a better way of saying it though i mean scott i've been reading scott aronson's blog post wonderful blog posts on quantum computing for the past few days a professor of quantum computing at university of texas probably the biggest thought leader in this space and so so essentially we take our input data right that's the number n we apply a hadamard gate to it so um and so then that's going to give us a possibility space of the period for that quantum fourier transform of what all of those possible values are are and then using those we can find all the prime factors um and so that's essentially what it is is this the quantum fourier transform applied to us some quantum input vector using numpy defined with numpy the quantum fourier transform is what uses the hadamard gate um to compute the superposition and that is the basic idea behind shore's algorithm now hadamard is one word you're going to keep saying over and over again because basically any number uh any vector if you if you multiply it by the hadamard gate it's going to go into superposition and we often need superposition to find out what multiple multiple predictions could be so now that we did that i want to get to this question two now before we get to the last part which is quantum neural networks i know what you guys want to see so on to the next question i'm going to begin accepting answers for the next question right now and the next question you can see right here what is it's a math input question what is the square root of negative nine this might seem totally random for you but it's not it's going to be related to what we're just about to talk about what is the square root of nine seems like a simple question right it's totally related to what we're going to talk about so the square root of 9 of negative 9. let's see what people are going to say for all this we're going to most people have a an idea of what the answer could be so let me start answering some amazing questions some amazing questions are coming in right now someone's going to win 500 by the end of this by the way um harshit quantum entanglement to reduce state space quantum entanglement doesn't reduce state space it can actually increase state space as well is entanglement a form of dimensionality reduction you know i don't know the answer to that question but i think that's such an interesting area of research guys if i was going to do like a phd in machine learning i promise you it would be in quantum machine learning and it would be with like generative adversarial networks using superposition to here's gonna be the crazy part predict what oh um quantum language models that's what i would build you guys know what i would build a quantum language model what if we could use superposition to predict what someone's going to say a word prediction engine that's not just predicting next words based on the previous words it's predicting the next words based on the quantum state vector of what's learned throughout time so it's looking through timelines to predict what the next best word could be is that even possible great um idea switch to rust evas evas you know just because you've been here and you're regular i might just switch to rust i will really consider that just program python is amazing except how slow it is true that i agree with you um neil patel that sounds from fortnite victory royale that's correct i love fortnite um fortnight is a phenomenon and it's a modern phenomenon of attention and engagement and and glory and fun and i want to use the concepts of fortnite to evolve computer science education guys we are going to create the most valuable esport on the planet it's a 10-year plan that i have and i'm really just getting you ready for this most valuable esport called code royale by giving you guys cash prizes and just showing you how the hardest problems in computer science can be gamified and that you should study them and just say on the path no matter what happens stay on the path two more questions and then we're gonna answer this question move on to quantum neural networks um boise data science meetup shout out to boise says i want to see a quantum comic by siraj nell that might happen in the future when i have more um uh i'll turn i'll make a video comic um period is a distance from crest to crest or from troph trojdatro uh it is oh my god i forgot isn't it both isn't it a generalized uh variable related title can you share the jupiter notebook um yeah i'm going to add it to the video description right after this sudan can you apply quantum ml to reinforcement learning yes of course sudanva i think that would be really fun for unity machine learning integrating that with the penny lane library which is the one that we're going to integrate right now let's now see the answer 24 people picked one answer for the square root of negative nine seems pretty seems pretty easy right square root of negative nine type it into your uh calculator you'll probably get the wrong answer so let's now see what the answer is for the square root of negative nine finish and reveal the answer was 3i i don't know who put negative 9 to the one half but the answer was 3i most people got that that's what i like to see most people got that so that's good and so now we have one more question that we're going to move on to i don't want to spoil it so let's get back to this um what's next guys the next and last part are quantum neural networks i have been waiting to talk to you about quantum neural networks let me tell you quantum neural networks we just saw short's algorithm when we saw how short's algorithm used the period finding algorithm the quantum fourier transform to predict a possibility space for what the prime factors could be using the super position linear the linear algebraic idea of superposition encoded in a state vector again vector multiplication that's it we're using different terms here quantum superposition hilbert complex but still just matrix multiplication applied to probabilities now what does this look like in the context of neural networks my favorite topic and let me also run the victory royale um sound effect for those who got the answer to that correctly good job what does it look like in the context of quantum neural networks and that is what we're going to answer with a little bit of math and just a little bit of math so let's put a little bit of math up there a little bit of this a little bit of that bada bing bada boom we got some uh you know some quantum bada bing bada boom you know hey okay so quantum math quantum neural networks okay so quantum neural networks so remember how i said how we have to use this specific type of linear algebra for this quantum state vector that encode superpositions well there's actually a way to think about that that is really useful and the way to think about that is that we have some input vector so we've input vector f we have a quantum circuit qc and then we have an output f g now you're going to see this these like curly bracket notation it's called ket notation it's used a lot in quantum computing but essentially what we want to do is we want to create a quantum state vector we want to create a quantum circuit um a quantum circuit is something we could do we actually just did that for the um for sure's algorithm the quantum circuit was the quantum fourier transform this quantum circuit could be anything this box it could be superposition it could be entanglement anything that uses a math from quantum mechanics essentially imaginary numbers now one of the simplest types of quantum systems is the qubit now again everybody and their mother has talked about what qubits are it's one and zero at the same time but essentially one way to think about the qubit is that it's operating in this three-dimensional space um of imaginary numbers so one dimension are imaginary numbers and the other dimension are real numbers and so it's like this 3d space and we can call it a block sphere and so we're trying to find the values in that possibility space of the qubit using superposition inside of this quantum circuit now what else looks like a quantum circuit you might recall that there's this funny little idea that called deep learning where you have some input vector f so i or we'll call it i and you feed it to this neural network and what this neural network is going to do is this neural network is going to spit out an output now what are all these nodes in the neural network those are all scalar values in matrix multiplication all the lines are matrix multiplication operations so if input times weight add a bias activate repeat input times weight add a bias activate that's it it's just repeating the same set of math operations over and over and over and over again those layers those what's inside the neural network now that's the topic of many many phds what are inside all of these layers well they're just matrix multiplication operations now what if we just learn about quantum circuits what are inside of quantum circuits inside of quantum circuits are matrix operations that apply to quantum data do neural networks apply to quantum data do we look at neural networks as do we look at neural networks as the as the um quantum function approximators as they are not necessarily not normally um one more idea that i want to show you before i tie literally everything in this stream together into one beautiful aha moment for you a nice little you know eureka moment for you and okay we talked about deep learning we talked about quantum circuits there's one more idea and that's the idea of the kernel method so in machine learning there's this idea of the kernel method where you have some high dimensional data with like a million data points and it's just going all over the place the kernel method you know we we have data in 15 million dimensions and let's just you know a bunch of colors for different dimensions that's our data what we want to do is we want to turn it into linearly separable data so we can run a simple support vector machine or some simple function on it and so the way to get there from high dimensional data to linearly separable data is the kernel method now there's a lot of ways of doing that and i just wanted to briefly mention that so i can talk about the last last part of this and the last part of this um is this and that's the idea of a quantum neural network the idea behind a quantum neural network borrows from ideas from deep learning and from quantum circuits and from kernel methods the idea is that we start off with an input i that's our starting input we then give it to a quantum gate so let's just say it's q okay um and then it's got an output o okay inside the quantum gate are quantum parameters normally we optimize those parameters using gradient descent using neural networks but um and and that's exactly what we're gonna do right now normally we run all this on a classical computer but in this case we're gonna optimize using a classical computer we're gonna optimize uh quantum parameters so this is a differentiable function and optimization opt is going to happen classically on the quantum circuit so the quantum data the quantum structure that there's no gradient descent happening um with that quantum map the gradient descent is being computed using the classical computer but it's updating our quantum circuit so it's like a hybrid quantum classical neural network if that makes sense and it probably doesn't make sense because there's a lot that's still to make sense i mean there's so much theory to go into when we're talking about quantum neural networks but luckily for both you and i i have this wonderful library called pennylane that i'm about to show you um that was created by xanadu dot ai um so let's let's let me show you the penny lane library penny lane penny lane obviously named after the beatles song um and it's basically a way to get started on your quantum machine learning journey what i really love are all the applications the documentation they have amazing stuff i love to see that um and they've got all sorts of examples and i just love to see that so penny lane is essentially a python library built on other quantum computing libraries like q q i skit from ibm um tensorflow quantum from google um d-wave one of my previous clients i'll probably work with them again at some point in the future love d-wade shout out to d-wave um yeah i mean this this is awesome you could sit here and learn this stuff all day and basically what i did is i just i basically hacked together this really simple 37 line um quantum circuit and basically we can run it right now let's just make sure that it runs as you can see the cost function it's minimizing the cost over time optimizing two parameters what this is doing is it's saying make it bigger bigger bigger cancel okay um what it's doing is saying import penny lane and then import numpy it's got they've got their own version of numpy and then we create this quantum machine learning device all right which is going to be this simulated qubit because we don't have an actual qubit this is running on a gpu then we create a quantum circuit now inside the api there are all sorts of quantum circuits the poly circuit you've got the hadamard these are all quantum logic gates and there's about like 10 or 12 of them about a dozen of them a lot of them are reused some of them are you know reusable because you use them for things like putting some values into superposition which you will need often in quantum computing or to rotate a certain set of qubits across blocks face um hilbert space or something like that and so nothing really spec
Original Description
Quantum Machine Learning may sounds daunting to most people, but it's way more fun to learn about than Classical Machine Learning. Creative algorithms that leverage concepts like quantum entanglement and superposition are already being studied by various teams to enable new solutions in fields like Chemistry, Finance, Supply Chain, and Energy. In this 1 hour game show, i'm going to attempt to build a quantum classifier that predicts input output pairs using the PennyLane python library. But I'll need your help! I'll ask for your help throughout the stream, and you'll have to interactively answer my questions. Together, let's see if we can build something somewhat useful. Oh, and at end one winner gets $500 cash, a song tribute by me, and early access to the Code Royale mobile and PC game. See you then
Please Subscribe! And Like. And Comment. That's what keeps me going.
Answer live questions here:
https://itempool.com/llsourcell/live
Read through PennyLane's Quantum Machine Learning docs to prepare yourself and come Friday, let the games begin:
https://pennylane.ai/qml/
Learn Machine Learning in 3 Months for free:
https://www.youtube.com/watch/Cr6VqTRO1v0 Join my AI community: http://chatgptschool.io/ Sign up for my AI Sports betting Bot, WagerGPT! (500 spots available):
https://www.wagergpt.co
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Siraj Raval · Siraj Raval · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
What is Bitcoin?
Siraj Raval
5 Ways to Use Bitcoin
Siraj Raval
BTC Fever - Siraj [Music Video]
Siraj Raval
5 Reasons to Build Decentralized Apps
Siraj Raval
The Interplanetary File System
Siraj Raval
How to Build a Dapp in 3 min
Siraj Raval
Life Before Smartphones
Siraj Raval
4 Ways to Use Smart Contracts
Siraj Raval
3 Dapps You HAVE to See
Siraj Raval
Char's Life as a BitTorrent Engineer
Siraj Raval
4 Reasons AlphaGo is a Huge Deal
Siraj Raval
Build a Neural Net in 4 Minutes
Siraj Raval
Sentiment Analysis in 4 Minutes
Siraj Raval
The Hackathon Life
Siraj Raval
Your First ML App - Machine Learning for Hackers #1
Siraj Raval
Build an AI Composer - Machine Learning for Hackers #2
Siraj Raval
Build a Game AI - Machine Learning for Hackers #3
Siraj Raval
Build a Movie Recommender - Machine Learning for Hackers #4
Siraj Raval
Build an AI Artist - Machine Learning for Hackers #5
Siraj Raval
Build a Chatbot - ML for Hackers #6
Siraj Raval
Build an AI Reader - Machine Learning for Hackers #7
Siraj Raval
Build an AI Writer - Machine Learning for Hackers #8
Siraj Raval
Build a Chatbot w/ an API - ML for Hackers #9
Siraj Raval
One-Shot Learning - Fresh Machine Learning #1
Siraj Raval
Generative Adversarial Nets - Fresh Machine Learning #2
Siraj Raval
Tone Analysis - Fresh Machine Learning #3
Siraj Raval
Generate Rap Lyrics - Fresh Machine Learning #4
Siraj Raval
Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Siraj Raval
Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Siraj Raval
Build an Antivirus in 5 Min - Fresh Machine Learning #7
Siraj Raval
TensorFlow in 5 Minutes (tutorial)
Siraj Raval
Build a Recurrent Neural Net in 5 Min
Siraj Raval
Build a Simulation in 5 Min
Siraj Raval
Build a TensorFlow Image Classifier in 5 Min
Siraj Raval
Tensorboard Explained in 5 Min
Siraj Raval
Generate Music in TensorFlow
Siraj Raval
Build a Game Bot (LIVE)
Siraj Raval
Deep Learning Frameworks Compared
Siraj Raval
Introduction - Learn Python for Data Science #1
Siraj Raval
Build a Neural Network (LIVE)
Siraj Raval
Twitter Sentiment Analysis - Learn Python for Data Science #2
Siraj Raval
Recommendation Systems - Learn Python for Data Science #3
Siraj Raval
Predicting Stock Prices - Learn Python for Data Science #4
Siraj Raval
Pong Neural Network (LIVE)
Siraj Raval
Deep Dream in TensorFlow - Learn Python for Data Science #5
Siraj Raval
Visualizing Data with D3.js (LIVE)
Siraj Raval
Genetic Algorithms - Learn Python for Data Science #6
Siraj Raval
Enter Siraj [Music Video]
Siraj Raval
Build a Web Scraper (LIVE)
Siraj Raval
Why is P vs NP Important?
Siraj Raval
How to Make a Neural Network (LIVE)
Siraj Raval
How to Make an Amazing Tensorflow Chatbot Easily
Siraj Raval
How to Make an Amazing Video Game Bot Easily
Siraj Raval
How to Make a Tensorflow Neural Network (LIVE)
Siraj Raval
How to Make a Simple Tensorflow Speech Recognizer
Siraj Raval
Joel Shor - Really Quick Questions with an Awesome Google Engineer
Siraj Raval
How to Make a Path Planning Algorithm Easily (LIVE)
Siraj Raval
The Best Way to Prepare a Dataset Easily
Siraj Raval
Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Siraj Raval
How to Make a Tic Tac Toe Neural Network Easily (LIVE)
Siraj Raval
More on: LLM Foundations
View skill →Related Reads
📰
📰
📰
📰
Building Your First Model Context Protocol (MCP) Server with TypeScript and Zod
Dev.to AI
Beyond Code Generation: How OmniSVG Rethinks Vector Graphics with Vision-Language Models
Dev.to · Shrijith Venkatramana
LangGraph Checkpointing: Three Production Rewrites to Stop Losing State
Dev.to · Elena Revicheva
AI builder essentials: tokens, context windows and RAG 101
Dev.to · Tilde A. Thurium
🎓
Tutor Explanation
DeepCamp AI