How ChatGPT and GitHub Copilot work and How to Use them for Programming

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
when we program we give instructions to a computer in order to solve a problem or to make some discovery maybe we want to build a website or maybe we want to analyze some data sets so then we write some code using some programming language to then instruct the computer to either build us a website or to analyze some data sets now as we pass these instructions to the computer the computer will automate the building of the website or it will automate the analysis of the data set so we can say that programming is really all about automation we don't want to do things ourselves if we can instruct your computer to do them in significantly less time and also more accurately now to give instructions to our computer we could for example write python code the thing is that a computer by itself actually cannot read python code because the only thing that a computer or rather a CPU can understand is machine code so zeros and once now obviously we don't want to write our instructions in machine codes because that would take forever and so what's actually happening in the background is that our python code as we run it gets translated into machine codes so that also the computer can understand and execute our instructions and we can say that this translation is also a form of automation so in order to automate some instructions we write python codes the python codes gets automatically translated to machine codes and then the machine code makes the computer automate our instructions now what if we added another layer of automation what if we couldn't just automatically write machine code what if we could automatically write python codes what if we could automate our Automation and that's where large language models come in they allow us to automatically generate code based on natural language now what are these large language models and how are they able to generate code in the world of machine learning a model is something that can learn patterns from data and so a language model is a model that learns language patterns to learn these patterns we train the model on large amounts of text to predict a word that follows some context through this training the model is able to pick up the general structure of the natural language by learning statistical patterns and relationships and then once it's trained it can also use these patterns to generate natural language so we give our model some input text and it will return to us the word with the highest likelihood given our inputs we can say that natural language and programming languages are actually quite similar so we can also train our model to predict code instead of natural language and then when we input code to the trained model it will also be able to generate code which it thinks is the most likely continuation of our input code training our model to predict natural language and code is not something we have to do separately so for example we might take our training data from stack Overflow and this data would then be a mix of natural language and code and so then the model can learn that sometimes the most likely continuation to natural language might not be more natural language but instead code or the other way around okay so our language models can generate natural language and they can generate code one way of improving these models is to Simply give them more parameters and more data to train on this huge number of parameters that they have and the enormous size of their data sets is why we call them large language models now having in mind how we describe the training of these models so far let's ask them a question explain to us how to sort a list in Python and the large language model might respond with the following please also provide codes that is nicely commented so the model didn't respond to our instruction and that makes a lot of sense because we trained it to just continue our inputs with whatever it thinks is most likely and these two sentences are actually very likely to follow each other as they could for example appear in an exam so that means we have to go back to training and teach the model how to properly follow our instructions for this training step we first build up a data set of optimal conversations where humans act as a chatbots and give answers that we would want an optimal chatbot to give with this data set we then fine tune our original model so we give it some part of these conversations and then the models task is to predict what the optimal response would be through this training step we teach our model to become a good chatbot and in similar fashion we can also teach our model to become a good programming assistant there are also some further training steps that can improve the model even more some of which involve reinforcement learning and if you're interested in that you can check out some links in the description and so now with this training step done if we were to ask again explain how to assert a list in Python the large language model would probably give us a short explanation and then some fitting code okay so much about what large language models are and how they're trained today we will look at two large language models Jet gbt and GitHub copilot and we will ask the question of how we can program these models such that they program for us or assist us while we are programming but first how can we even use these tools for chat CBT we simply go to chat.openai.com and then we can sign up using either an email address or a Microsoft account or Google account or Apple account I will sign in with Google we have to acknowledge that chatjebt might produce incorrect or misleading information and we also have to acknowledge that our data will be collected but this is actually something that we can opt out of on the left side here is our chat history which we can also turn off by going to the settings data controls and then clicking here which will stop our chat history from being saved and used for training purposes we can also change the theme to dark and then we are ready to ask any questions okay now on to GitHub co-pilots to work with GitHub copilot we start by opening Visual Studio code in Visual Studio codes we go to the extensions tab on the left side and we search for copilots we click on GitHub co-pilots and then we click install for me it also says reloads required so let's quickly take care of that and this will also prompt me to sign into GitHub and the reason for that is that if we're students we can sign up for the GitHub student developer pack and use copilot for free and not just for a 30 days trial and so from here we click sign up for student developer pack we select students then sign up with our GitHub credentials and this will take us to the site where we can apply for the benefits and my account is already verified but for you this should also be a very easy step what is important is to select your University email and then once that is all set up we go back to vs code and then sign into GitHub we press open Let's test if everything was successful so if you write for I in range then copile this already giving us some suggestions that we can accept by pressing tab okay so now that we have both tools set up we can come back to the question of how we can program these tools or the underlying large language models we can program a computer by for example writing python codes to program large language models we can simply use natural language the input that we give to the models with natural language we also call prompts designing these prompts in such a way that the model does exactly what we want is what we call Prompt engineering and so as we go through the different use cases of chatgpt and GitHub copilot we will look at different kinds of prompt patterns that will help us achieve our desired output most of the prompt patterns we will take from this research paper but some also come from other sources as programmers we are often confronted with the unknown maybe the program we want to write requires us to understand a new complex math concept or maybe we have to use a new library a good way to start this journey into the unknown can be to ask Chachi BT the most important Concepts that one should know about the topic or area so for example we could ask what are the most important concepts of linear algebra for machine learning and then from there we can dive deeper into the different concepts when we ask for the most important Concepts we should be careful not to limit the number of Concepts that we request because we wouldn't want to miss out on anything important of course if the output of Chaturbate is too long for our current needs we can still limit the response being new to a topic means that sometimes it can even be challenging to ask the right questions and this brings us to our first prompt pattern which is called question refinement the idea behind this pattern is that when we are new to a topic we might select certain information that would allow us to ask a better question and so we can structure our prompts by saying within scope X suggests a better version of the question and this can then potentially give us a better question which then also might give us a more satisfying answer so in our example we could ask are vectors and matrices the same and we add to this question within the scope of machine learning also provides a better version of this question and prompt me if I want to use this version so first we get our answer and then it prompts me would you like a revised version of this question we do want indeed and in the version suggested by chatgpt it is also asked what is the difference between vectors and matrices but this time it added the context of machine learning and also how they're used in analyzing and processing data and if we want to learn something about machine learning then the different usage for analyzing and processing might be very relevant to us and it could have been something that we would miss if we're new to the area but this example also shows a small downside because the question became more specific so we added the context of machine learning and also the usage for analysis and processing so with this prompt pattern it is possible that the scope becomes too narrow and that we maybe miss the bigger picture what is also interesting here is that the added context of machine learning does not come out of nowhere so in our first question we asked about the important concepts of linear algebra for machine learning and through that we established context so then once we ask the second question which was just about vectors and matrices jgbt already has this context in mind which is of course not a bad thing because probably we want to know how they differ in the context of machine learning but we didn't explicitly write it in our question and so by requesting a better version of the question jcbt shows us actually what kind of context it is considering so the context of machine learning so because the context is now explicitly mentioned it can allow us to better categorize the answers that we get the research paper that we're taking the prom patterns from names The Prompt structure associated with the patterns contextual statements and so we can say that we program large language models through context so the key to getting the desired output is setting up the right context in our example the contextual statement was that we have a certain scope here machine learning and that we want a better version of our question and that we want to be prompted if we want to use the better version and of course we can also exchange the context for this prompt pattern so for example we could exchange our scope now coming back to learning about new topics something we can add to our problems is the sentence explain it like I'm 5 years old so we could write for example explain neural networks like I'm 5 years old and so by adding this phrase chatbt will give very simple analogies that can help us understand if we're new to the topic in this prompt we take only role of a five years old instead of taking a role on ourselves we can also give a role to chatbt and this brings us to your next prompt pattern called Persona pattern in this prompt pattern we give a role to judge GPT and then ask it to carry out a task that a person with this role can perform so we could write for example as a security expert write a python script where users can enter their username and password in a secure manner and so chbt will give us some code here that includes the get credentials function which takes username and password and then also a authenticate function which is just a placeholder so far so let's actually copy this code by clicking up here and then we go to vs codes and copy paste and then let's run the code and first it prompts us for a username we can write admin and then password and now when we enter something it doesn't actually show up and that is because chatbt use the get pass module which will hide the input as it's written so we press enter it says authentication failed because we just entered a random password and authenticate here requires the password to be actually password so we can rerun it and now we enter again admin and then password and now it says authentication successful and so taking on the role of a security expert jgbt made sure that our password gets entered in a secure manner we can take these swapping of roles even further by making use of the flipped interaction pattern in this pattern we state that we want to perform a certain task and that chatgbt should ask ask questions until it is able to perform that task and the motivation behind this pattern is that often judge PT is often no better what kind of knowledge or information it requires to perform certain tasks so this can ensure that our goal is reached faster and more accurately so we can ask for example I want you to write a python script that generates a cool looking plot you should ask me questions before you start this task and only start when you have enough information okay so chaturbitty asked us some questions the first question is what kind of data will the plot represent numerical values categories time series let's say numerical values then seconds do you have any preferences for the style or appearance of the plot let's say I want it to be very colorful then a third how many data points will be included in the plot will they be randomly generated or provided by you let's say they shouldn't be random but you shouldn't make them up and then fourth do you have any specific requirements for the plots such as access labels title or Legends let's say no and then fifth are there any additional features or functionalities you would like to see in the plot let's say I want the plots will look like a cat so he answered all the questions let's see how it goes okay after some initial server problems jgbt finally gave us a response so let's copy the code and then we paste it into vs code and try to run it and this is the plot we get and while it doesn't look like a cat it is very colorful and we have numerical values and also the values are not random but taken from a sine function in the last video we talked about potential issues of language models and so also chatgpt and one of these issues was false information or hallucinations there are two prompt patterns that can help mitigate this issue the first one is the effect checklist in this pattern we prompt HTTP to give us in addition to our question a fact checklist which is a list of facts that if they were false would undermine Chacha BT's answer and the idea behind this pattern is that through this fact checklist we can better assess the truthfulness of Chachi BT's answer so let's try this out we're gonna ask tetrubiti can python code ever be as fast as C code and then also provides a list of facts such that if any of them were wrong it would undermine your answer and so the answer it gives us is that python code is generally slower than equivalent C code due to several factors such as interpretation overheads Dynamic typing and memory management however there are certain scenarios where python codes can approach or achieve comparable performance to C code and although it's a rather short answer it seems to be all correct and now in addition we also get the list of facts so first step is the just in time compilation so python implementations like Pi Pi or number can use just-in-time compilation techniques to optimize coded runtime so that the performance can approach compiled languages such as C so this fact is the basis for the statements that python code can approach or achieve comparable performance to C codes so if you're not an expert in this field we could look up just in time compilation and confirm that this fact is correct then the second fact States python allows developers to write C extensions using modules like siphon or C types which can inference with C libraries directly and this also helps achieve comparable performance to Pure C codes and again this fact is a basis for the statements that python code can approach or achieve comparable performance and there are also some more effects which we will not go through but we can see that this pattern is quite effective at understanding's reasoning by extracting the facts that the answer is based upon and so then by verifying these facts we can verify the answer a closely related prompt pattern is the reflection pattern in this pattern we prompt judge gbt to in addition to the answer also to explain its reasoning and assumptions and so this also helps us verify Church evt's answer and it also has been shown in some cases to improve the answers given by chat CBT so we can write for example our neural networks a good model for predicting the weather and then in addition explain your reasoning and list your assumptions and so here it gives us some points her neural networks can be able to predict the weather and it's also doing an okay job at explaining its reasoning and then if we scroll down we also get a list of assumptions so for example we need sufficient and quality data so again this can help us verify chatgpt's answer and it can also help us better understand the topic okay let's continue with some programming it has been shown that chatgvt performs very well for lead code questions of the difficulty easy but as the difficulty increases to medium and hard performance drops significantly so what we can take from that is that when we want judge EBT to solve a problem it can pay off to break down a hard problem into smaller easier problems and also generally speaking that is a very good mindset to have so what we will try to code using Python and the manim library which can be used for animations is a circle that is filled with small colorful dots and before we get started it's important to read this limitation here because chat gbt's knowledge only goes up until September 2021 so for more recent libraries or libraries that get updated somewhat frequently this limitation is important to have in mind because chatgbt might give us outdated code that we would then have to rewrite or maybe cross check with the library's documentation but now let's get started so first step we set up the context so we write python codes and we want to use the library manner so write Python and manim and we want a big circle so we write create a scene with a big circle this looks good so let's copy the code and then we paste it into vs code and then from here we can run the code and for that we're using the manim side view extension so we click here we select our scene and here we have our Circle but currently this circle is just there so it's not doing anything and so we can go back to chatgbt and ask it to grow the circle from Center this gives us a new code snippet that we can again copy we replace our old code save and rerun the code and now we have a small circle that gets transformed into a bigger Circle and while this definitely doesn't look bad it doesn't exactly grow the circle from the center so Madame actually has a function called grow from Center and touche BT didn't utilize this function but chat gbt is called chat gbt for a reason because usually it pays off to actually chat with it so we can tell it I don't want two circles I just want a single Circle that grows from the center so we get some new code let's try this out and what we can see here is actually that we can see nothing so there's no Circle and nothing growing from the center but at gbt did use the function grow from Center and this highlights one very cool use case for jgbt which is learning about new libraries and their different functions and we don't just have to grow from Center we also have a scale function and it also explains to us what these things do so the intention was we create a small circle at the center and this is actually also really problemized because the radius is zero and zero scaled is still zero so if we change that to 0.5 save and run again then now we have a circle that is growing from the center and this is done by the growth from Center function and we also have this line here where we scale up the circle even more and this is not that useful for us but we could also simply remove it okay so that was chbt's attempts to grow a circle let's try doing the same with GitHub copilot and copilot is always suggesting us a class called test but we will first write a comments saying create scene that grows a circle from the center and then we already get a suggestion for a class called growing Circle we accept by pressing tab the next line and this also looks good and we save and run and this is also not exactly what we want but at least we have the general structure in place so now we can remove the line already circles created and we can write as a comment grow circle from Center and then we actually get the grow from sensor functions adjusted so we save and we run and now the circle is growing from the center so let's make this circle a little bit bigger by giving a radius so create circle with radius 2. we remove the line and we get the suggestion for circle with radius 2. and now we want to fill this big circle with a bunch of colorful smaller circles so we write the comment fill big circle with let's say 10 smaller circles and let's see what we get suggested so we have a for Loop for Iron Range 10. and this is quite a lot of code here so what this does is it plays the following animation curve from Center a circle with radius 0.5 and it moves it to the center of our original Circle so if we accept that and we run then now we get the big circle and a bunch of smaller circles in the sides but that's maybe not exactly what we had in mind because all of these circles are overlapping so we can add the commands the circles shouldn't overlap we remove our old code and the first suggestion we have is to fade out the old Circle and that's not really what we want so let's continue in the next line here we have create 10 circles that sounds good so we get our circles with a list comprehension and then we get a list of colors one for each circle then we can set the color for each circle then the position and then we add each circle to the scene we wait one seconds and that's it so let's try this out and this is almost working so we have our big circle here and a bunch of smaller circles but not all of them are inside the bigger Circle and so what we can take from that is that GitHub copilot can be very helpful to learn about the general structure and functionality of a library so you can see that we can set colors that we can shift objects and that we have to add an object to the scene in order for it to be visible but it's not solving all our problems perfectly but to be fair our comments are also very general so actually copilot had to break down this General description into these smaller steps and it's also something we could have done so for example for the positions we could write for example get 10 positions from inside the circle that are not overlapping and so let's accept this code and from there on copen already knows what to do next so we want to remove these circles to their positions and then add again the circles to the scene and let's save that and actually the code is not running as we can also see here because apparently there's some error and the error is in this line here so let's see what happens so here we're taking the center of the circle and then we get points from the proportion of the circle and this looks like a list comprehension but without the list comprehension brackets so let's add them save and try again and this already looks much better and let's do a little bit more because currently these smaller circles are just appearing out of nowhere so let's write fade in smaller circles and what's happening here doesn't look very promising so let's go back and see if we can get another suggestion and for that we can see at the top here there's two suggestions and with the arrow keys we can go through them so here for the next suggestion we get a for Loop which is a much better option we can also press Ctrl enter to show us all these suggestions so let's accept the first solution and that's of course not enough so let's remove that and then it's suggesting to play the fade and animation for the respective circles and that looks promising so we save and we run and this looks very good so it's fading in all the circles okay so what else can we do with chat chbt and co-pilot another use case can be to optimize code so let's say we want to create a list with increasing integers from 0 to 100 million and so we created this code with co-pilots and what it did in addition is that it added code for measuring the time it takes to create this list and actually that's kind of what we also want because the use case we want to show is the optimization of code so if we run that as it is it takes us about 3.5 what is probably milliseconds which is not that bad but now we'll take this code to Chacha BT paste it in here go to a new line with shift enter and then writes optimize this code and so in the first step it kind of cleans up our code by putting everything in a list comprehension and not this ugly for Loop and then in the Second Step which is also called the first step by the way it uses numpy for efficient array creation and then very interestingly it also gives us a third First Step that talks about the generator expression and that's actually something very useful because if we don't just have time in mind but also memory usage then using generators is a very good thing but currently we have time in mind so we'll copy this block here go to vs code and then put this behind our old code and then run it so our first question but again took 3.6 milliseconds and then the second code snippet optimized by chat gbt took just opened five milliseconds [Music] one thing that we can also do is tell chat gbt to comment our code so let's take this code snippet here and then write comments in this code and so what it did here is not actually comment the code but it just gave us an explanation which is also a very great use case for jgbt so if we're unsure about anything in our codes we can just ask jgbt but what we actually wanted were comments in our code so let's communicate that so we write put this information as comments in the code and there we go we have nicely commented code when we're generating code using chatgpt or copilot we can never be 100 sure that the code is working and of course that's also true for humans so to address the fact that sometimes code can be wrong we can ask your gbt to write us a test so we first read let's put this into a function and then we can say write a test for this function and this function might not have been the best example for testing but of course this can work for any code and usually it's very tedious to write tests so it makes sense to use AI for that but of course we should also check this code to make sure that everything's correct something that can also be quite useful is using chbt to translate code into another programming language so let's take this function here and then let's touch GPT to translate it into C and there we go same function but in C and this translation doesn't just work between programming languages so very often in programming we might encounter pseudocode and so we can also use chatbt to translate pseudocodes to any programming language that we have in mind and of course also the other way around one final use case I want to mention is the debugging of code and what's interesting is that here it has been shown that basic descriptions of debuggy code are making chibi perform worse and that's due to language models having a limited attention span but also it has been shown that if the initial output is incorrect then giving feedback to chat should be T So chatting with it has a high likelihood of improving the next output okay now coming to an end the best way of learning how to use these tools is to try them yourself so when you write some codes you will find out in what cases co-parted or chbt might be useful or in which cases it might make sense to write your own code
Info
Channel: Robin Horn
Views: 4,049
Rating: undefined out of 5
Keywords: ChatGPT, GitHub Copilot, AI, Programming, Python
Id: Qh7F1yftnHg
Channel Id: undefined
Length: 34min 35sec (2075 seconds)
Published: Fri Jul 14 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.