Back to Index

Live coding 2


Chapters

0:0 People intro and questions to address later
3:27 Switch users in Linux
4:48 Introduction to git and Github
8:32 Build a website with github
19:0 Setting up and using ssh keys
39:1 Using tmux for better terminal productivity
48:54 Create a notebook in jupyter lab
54:26 Committing and pushing to git
58:55 Fork a repo
61:31 Installing fastai and fastbook

Transcript

turns out to be complicated so i think i've broken the back of it i think i've basically figured it out does anybody have any um questions or uh areas of interest or anything following our last chat hi yeah i am interested to know more about fast jam generally because i just google and found it very beautifully we will get to that that might be a little while though hi jeremy i'm i'm joe where are you i'm enjoying this from oh just about seven minutes away from where you're at oh you're in the red cliff peninsula somewhere no i'm sorry i thought you were in brisbane i'm in red cliff not too it's about seven minutes away so it's still um question i have um like really impressed with the blogging sort of set up out of jupiter and just i'm curious what your workflow is and how you are able to um do an experiment and be able to vlog about it very easily because i find i've got to move it from this get out to another sort of thing and there may be things in that space and yeah definitely i think yeah i think we've already let me just double check our list of things to cover yeah how to blog is actually number one of our list of things to cover in our walkthroughs topic and i don't think fast jam's there yet so let me add that fast chain there we go um all good questions um i'll uh introduce myself uh i'm matt from britain as well um i uh how do you i would like to um i think um we started looking at setting up jupiter lab last week um from remember correctly and uh so i think we'd installed jupiter lab um pytorch so i even managed to get that working successfully on my let that all work okay yeah it was it works apparently looks like it's working um so and i managed to um install um fast ai as far as i know um so i guess being confident that i can work on that to my machine would be yeah that's actually what we're going to do today i think we're going to focus on uh yep get our own kind of start doing some work on our own machine yep exactly um okay well let's get underway with that um so just to explain something oh um just to explain something you might have seen last time i i have two different users in my wsl installation i don't normally but it's just like i just wanted to mention that in a in in a linux you know distribution you can add multiple users and and switch to them um and uh so uh the way you switch between users is by typing uh pseudo minus u for username and then the username you want then minus i to open up an interactive terminal as that user so that's why you see me doing this sometimes so when i do that you can see it's like said oh welcome jph zero zero and kind of starts from scratch and you can now see before the @ sign it tells me that the only reason i'm doing that is so that i've got like an empty user that doesn't have anything installed or anything set up so i don't accidentally assume something that and um fail to create something um generally speaking there's you won't normally have a reason to create multiple users on your account unless you want to kind of set up something like this it's totally separate um so yeah i thought we could try to like create you know a notebook and python script and put them in a git repository and you know just kind of go through that workflow basically um so i normally create a directory to put my my git repository so what's a git repository a git repository is a folder containing files and potentially subfolders which um uh basically uh to simplify slightly you can easily store somewhere else um and the most commonplace people store it uh is github.com how do they provide free storage of git repositories um and most interestingly git keeps a kind of a copy of every version of your files and you can switch back to any previous version at any time so if you ever mess something up and save it and then realize later oh i messed it up you can you can go back and get an old version so maybe before we create our own github repo we could look at a github repo so we could look at the fastai one so github as i say is just one particular company that stores git repositories for you um you don't have to use them there's also one called git lab um but um i don't know most people use github so i think it's easier to go go you know be where everybody else is and so this is an example of repository um so or the name of the repository is fastai and then that belongs to some particular person or organization in this case it belongs to an organization the organization is called fastai um so if we get rid of the first of those the last of those fastai's this is the organization fastai and you can see the 119 repositories that are in that organization so if i click on one say fast release see how the url's changed this is this is now the fastai's organization's repository called fast release so this pair of things with a slash is basically a unique identifier in git lab for a repository because it has the username or organization and the repository so fastai is an organization my github username is jph00 and then that also has repositories and so i can click on one like tiny pets and you can see this is now the tiny pets repository in jph00 um okay so let's go back to the fastai repository so a repository as i mentioned contains folders and files and then folders can contain folders and files they can contain basically any kind of folder or file any kind of file you like they ask that your files that each individual file is smaller than 50 megabytes they don't particularly enforce that though um so that's what we see here there's a special file which is a file called readme or readme.md and that file is special because in this display it's automatically shown in this repository website so a kind of minimal useful repository is something that just contains a readme.md file and in fact as soon as you have that you have something that you can a website you can show people um so maybe we should start by doing that so if you go to your own github page github.com slash your username you can click repositories and so you might not have any repositories yet which is fine and here you could click new repository so why don't you go ahead and do that click new repository um and so you need to give it a name um walk through three if you want a description not a bad idea to remind yourself of what things are sample repo for walk through three of fast.ai course so you can make it private so nobody else can see it or public um something you'll hear a lot from fast.ai folks the community alumni myself is that the more you can work in public the better the more you can share your your portfolio the better um something which a lot of folks aren't used to and can feel uncomfortable but like here's you know here's a place you could start trying that is to make this public if your default is to always make things private maybe try not doing that this time um okay so we can yeah walk through second please walk through two sorry the second walk through the second walk here sorry yeah thank you i don't know why i imagined that there was another walk through maybe i dreamt it okay i guess it's because it's the weekend it's been a long time so we can say add a readme file now there are some things that you don't want to put in git kind of like temporary files and stuff like that and there's a special file called .gitignore which lists all the kinds of files you don't want to store um so if you click on here and start typing python this will kind of create a list automatically of the kinds of like pythons intermediate files and stuff um so again it's a good idea to use a license that allows other people to use this if you don't then other people can't use your code uh i always use apache license too and the reason for that is that it's like gives users you know really as much flexibility as possible and how they use the code but it also has a clause that minimizes the chance that i'm going to get sued for patent violations or that people would use this to kind of enforce patents in inappropriate ways um so wait can i ask a question of course um sorry my name is mark i'm from toronto i'm representing north america here tonight i think great or this morning so late night for you well it's only nine it's okay uh you're at the of course your west coast i see yeah that you're at east but yeah um the uh sorry can you just go a little bit more into the git ignore and i i didn't quite follow what that yeah let's create the repository and take a look at it um okay so i'm embarrassed i've actually been to toronto and i've completely butchering my geography is this the way you want questions asked or do you want hands put up or something i like yeah i like i like you know as informal a conversation as possible so yeah i'm not even sure i would see if hands go up so here's here's the repo we just created and if i click on git ignore it will show me the contents of that text file and so here is the text file called git ignore with line numbers on it um you can see it without anything else by clicking raw so that's this is just what the text file contains um and you can see for example um in linux a .so file is a compiled c library which is not something you would normally want to save into a repo so star .so star means anything .so so cx c library files would not be stored python has a cache of things that it's pre-compiled which it puts in a dunder pycache directory so this says don't put that in in into your git repo so basically when you when we add stuff to git repos shortly um it will by default not include anything that matches these these patterns does that answer your question mark it does in in the sort of literal sense i guess okay tell me more about what your non-literal sense is well so so i understand that it's um i understand that these are the files that will be excluded but i guess other than just always choosing python for git ignore i don't know how to decide which files to include in which files to oh yeah okay well we'll we'll see that as we go um what one one example that will come up if it's not already in here is um jupiter stores backups uh the most recent backup uh save copy uh in a backup directory called ipy checkpoints you would gen you know and when you go to git add you might say oh it's adding this directory called ipy checkpoints i don't want that and they'll be like oh okay i'll put it in my git ignore so it's generally like if you'll see things that you're like oh i don't need that to be backed up or like oh that's the thing that contains my password i definitely don't want that in my public git repo so those are the two main reasons inside the stuff that doesn't need to be there or stuff that you actively don't want to be there okay so but but choosing the python for git ignore is a generally a good first this is a good start so this is just kind of pre-populated it with a bunch of lines that we'll we'll add to later as we find stuff that we don't want to include okay so you can see it's created a readme.md file and if i click that you can see it's here's its contents and that's the same as the contents down here and so we could like create you know a little website now which is basically having websites better you know i guess it's a website by editing readme.md so if you click that little pencil we can now edit so try editing your readme.md and this is um this is markdown which we use in jupiter we use in readme files it's kind of used pretty much everywhere um and so it's well worth getting used to um so at this stage the markdown file you've got one line that starts with a hash that means this is a level one heading um a level two heading would have two hashes introduction okay and then you just put things um on separate lines of text so this is a sample repo we'll walk through of the fast today i course and then if you want a new paragraph just put an empty line between them this is another paragraph and then you know you can have lists by putting hyphens okay and so forth and maybe another header here okay so if i save that it doesn't say save it says commit um so this is um a concept in git is that you don't just save things but you create um you know a version it's called a commit um which is basically all the changes since last time you saved so commit means save but it means save with version control and so when you save um you need to have some description of what the change was that you made and optionally you can add more details about it so by default it's made a description for me so i can commit my changes and so now if we go to our repo you'll see that we've got more in our readme um you'll also see that this repository now has two commits so if i want to go back and see what it used to look like then i can see here's the initial commit and here's my update readme if i click on this commit code over here it shows me the difference so things with a minus and a red are things i deleted and things and plus and green are things i added and this is called a diff a diff for a difference and so very often people will you know say that they want to have a look at a diff to see like if you've made some changes to their code to see what changes did you make otherwise it's very difficult to know what somebody did so this commit gets automatically gets a little unique name as you see we can see the diff um or you can even click on this little button here browse repository at this point in the history so you can go back and pretend that life was before a minute ago and see exactly what this looked like back then so this is now looking at the state of this repo before i made the change so get get is pretty handy and github is a very useful place to store stuff in git so generally speaking we don't normally edit things directly with the github editor because it's pretty basic i mean i do sometimes you know if i if i just want to make a quick change to a readme i will sometimes click that pencil button but more often i'll do it on my computer so to put it on my computer we need to clone the repository so cloning it means making a kind of a linked copy on our computer so you see this code button here we can clone it we're going to clone it using something called ssh which is something we'll use a lot and ssh is a way of logging into remote computers and also automatically doing stuff with remote computers and copying stuff from remote computers so here is a a url it's not to a website but to a git repository using ssh so i can click here to click copy right so i've copied that so how do i clone it well the first thing i do is like say let's get things organized so i like to have a directory for all my cloned git repos so i'll go make to git cd git and so if i go print working directory you can see i'm in my home and remember that tilde is a shortcut for your home so i can now type so git is a program on your computer and so you can type git clone and then the url so i've just pasted it okay so there's a lot of security stuff built into ssh and one thing is to make sure that you don't accidentally connect to places you didn't mean to you know i don't use that much of the security stuff because i'm not too worried you know for most things i do so in this case it's just saying you sure you want to connect to this new place and i'll just say yes and it's going to save that okay so permission denied all right so i've asked to clone a repository using ssh but i got permission denied and that's because to use ssh you have to use an ssh key so the first thing i mentioned is if you want to clone somebody else's repository you can use http instead of ssh so i can click here http copy and then i could clone that and that works fine that's a perfectly reasonable way to work with other people's code so if i go cd walkthrough 2 here it is and i can edit the readme and then i could go down and i could add something else and the problem is i can't save that back again without logging into github so if i try to commit that i'll explain committing from the command line in a moment but i just want to show you that oh okay so the first next thing to know is if you want to save stuff back to back to github it needs to know your name and email address so it tells you some commands you can use so one approach would be just to paste them in right and obviously that's not the right email and username but things like this in the terminal they basically always create hidden files in your home directory so if i just type cd it takes me to my home directory and you can actually see here there's now a file called .git config and so i could edit that and here we go so info-rap-fast.ai say jeremy howard all right now i'll show you a little trick which most people don't know i want to go back to the directory i was in before i could type cd git slash walkthrough 2 or i could just type cd space hyphen and space cd hyphen means change directory to your most recently used directory so that's very handy one issue with that is if you've like cd three or four times there's no kind of history there so what i would do if i want to come back here later and i'm going all over the place is instead of typing cd you can go push d which is the same as cd but it remembers where you were so if i go push d and change to my home directory i'm now in my home directory i can cd to downloads i can cd to nbs how do i get back to where i were where i was before well i pushed from git walkthrough 2 so i can pop if i type pop d there we go i'm back where i got words originally so there's a couple of good tricks for zipping around in your directory structure it's a bit like pressing the back button i guess almost on on a browser um anyhow if i now try to save my change and the way you do that we'll talk about this more in a moment um is you push um you can see here it's asking for a username and so you obviously can't save things to other people's repositories if you don't have their credentials um it's also annoying to type in your username and password all the time so i never use almost never use HTTP get clone for my own repositories instead i use ssh so let's delete that directory and get clone with ssh so click ssh and copy and let's take a look again at this error we got okay so why do we not have permission that's because it doesn't know who we are and it doesn't know that we have permission to copy and change this repository um ssh is really nifty it doesn't use passwords instead we create a secret key on our computer for the private key and the second thing called the public key which we can give to other people and then anybody who has our public key will be able to accept uh we will be able to log into basically but they can't log into us that's why it's cool it's not like a password it's a one-way thing so we can get into github into our repos but nobody on github could like log in through our computer or anything so we need to create um it's called a key pair a public key and a private key so to do that you type ssh oops dash key gen ssh keygen so that's generate ssh keys and then just hit enter hit enter again hit enter again all right so that's created keys in my home directory n.ssh this one here's the private key and this one here's the public key so we need to tell github about our public key so that we can log in there so to display a file in the terminal without like uh basically show it all at once you can just type cat so if i go cat in my home directory dot sh dot pub there it is now there's no problem with me showing this on a live stream and it being on a video this is not in any way private or secret because this is just something that lets me if it's placed on another computer it lets me log into another computer in fact it's even stored publicly like anyone can access this public key because it's on github yeah so let's put it we're gonna put it on github so let's do that yeah so let's go back to github click on my face and um probably going to be in settings somewhere all right uh here we are ssh and gpg keys there we go um do we not add them here here we go new ssh key title i'll just call this the walkthrough key and paste there we go add maybe add the username i used all right so that is now in my account so i should now be able to rerun that git clone command so remember if you press ctrl r you can type a few letters from a previous command so i'll start typing clone and there it is and so if i hit enter now it's working so i don't have to worry about ever typing in a github password so here we are great um let's make sure i've closed my other jupyter session jeremy i noticed when i did that when i did the ssh key gen yeah i already already had one okay no worries so if you've already got one just use that one yep just use that one there should be a id r r i d rsa or id dsa or something like that that's your private key and the one that ends in pub is the one you'll copy over yep and so you don't need like how did you just how did you just split your terminal like that uh we will learn it's something called tmarks t mux but we'll certainly be covering that one of the best things ever um all right jimmy one thing that i just thought might be interesting for people or just something that can catch people out is making sure that your identity that you set up in your terminal as you showed before and that um the email that you use in github said that that they're consistent sometimes if you are using a different email or especially if you it's probably not a case here but if you have multiple github accounts you can end up um you know having one identity making commits to a repository that you didn't intend to under that identity and back and forth so just um just be careful when you first get started that you're using a consistent email identifier like you know it's not necessarily always important for your public key but certainly for your identity on github and for where you're going to be making commits and things like that um it's often helpful when you get started to make sure they're consistent yeah i mean i don't honestly ever think about that i kind of just chuck in any old email address it doesn't like it's it comes up sometimes but not too often um because it's kind of mainly informational i think this information so that other people can i find i've found it's more down the line if especially if you have a separate github account for personal and a separate one for work then um if you if you have different identities or different emails being so said with it then when you make a commit to a work repo you've accidentally committed it from your personal one which you didn't want to reveal your identity on or whatever so yep okay and somebody else have a question or comment just in the same context like you said the public key even if somebody else knows that they cannot commit to your git is that because the private key is unique only on your computer like just a high level correct the private key is the secret code so if you wanted to be able to um you know log in from another computer you would you would copy the private key over there and then that that computer can log in yep so the private key is the thing that says i i can prove i'm germany howard and the public key is a thing that says anyone who could prove that germany howard can log in here thank you no worries this is something that this this way of authentication is used across many different contexts so github uses it but for instance today i was installing gibuntu server on my local machine and i put points the installation to take my public key from github just to make things easier it grabbed the public key and it set it up so that i can easily connect to my computer without any additional setup steps so there is absolutely no danger given the current state of mathematics you know to making the information public and yeah without that you know going to the HTTPS and password authentication that makes it for such a cumbersome github workflow that this is so so much better yeah yeah ssh is used everywhere so for example i've got a GPU server sitting next to me here which um and then i've set up a um somebody at my door and a tick our doorbell keeps switching itself to a christmas chimes for some reason yeah so i've actually created a profile here for logging into my box which uh as you can see it just calls ssh so and then that's uh attached to control shift three so anytime if i want to log into my GPU box i hit control shift three and here i am i'm now you know typing in just as if i was at my own computer but i'm actually now typing into my GPU server um so ssh is a good thing to learn about properly um okay so we have Jimmy uh with regards to creating repos and committing and i mean what we are practicing right now i guess i'm in the course itself you show how we can deploy an application and sometimes you need to do the same thing having git push to those applications yeah and just wanted to see is it possible to have both github and also pushing a repo communicate with two different destination sources if it makes sense yeah yeah we can do that and we'll be saying that once we start looking at hugging face spaces yep yep you can so um you can have as many repos as you like and each repo kind of has this kind of default destination it's connected to which will normally be github but you can even connect one to multiple destinations um choose which one you're pulling and pushing from and to yeah can i ask one more with regards to the token password that you mentioned that for for that ignore file just wanted to see if that is important only for the public reports or even a private report on github you shouldn't share token passwords so yeah i would tend not to i mean it depends how important it is you know um i mean at least the people on great hub can see it um so you know and yeah i would i would try to avoid putting private stuff onto public websites in in general um particularly things like that where it's like at some point you might decide oh i want to make this repo public and then you forget that somewhere there was a at some point there was a secret file in there and you know one thing to be very aware of is even if i um in fact let me show you um let's create a super secret file and my secret is i don't like bananas i don't want anybody to know this right but let's say you know it was a currently uh um uh private repo pretend and so if we put that into github because it's fine it's all private and then i push that over to github.com and then later on i say oh okay i want to actually make this a public repo so i need to delete this from from from github so i'll get rm that file remove secret and like okay now i make my repo public everything's fine nobody has to know that i don't like bananas and then i can check on my repo and okay my super secret file's not there but remember commits let's go back to the world as it was oh it's here in my history right when you remove things from github it removes it from the current commit but it's not changing history so people could still find out my secret Jeremy i just um i just noticed there as well that was a good example when you looked at those commits of the um the identity issue we were just talking about before because on that commit screen you had some commits that were verified because you will have had an ssh key that was tied to your github email you see you've got those first two commits there are verified and then the latest two aren't that's because you just created a new key so that's the the key you won't have had the same email id as your first one so that's that's an example where especially like if you are trying to make verified commits if that's important to some project you're involved in um yeah that's where that'll check you out so i just saw that i mentioned that never been of interest in my projects i guess i never thought about it but yeah so this one was actually yeah because you know anybody could create a dot get config file that says i'm minus 12 volts and push and it'll say this is a commit from minus 12 volts um it won't say it's verified um yeah yeah um okay so um let's put a a notebook in here so um i can run jupyter lab and i think we created an alias last time jl and i pointed out that at this point it's it's you know this terminal i can't use it anymore because it's busy running jupyter now i could run another terminal session in windows terminal but i actually never do um i actually uh always use um instead something called tmux uh tmux is something which um actually runs inside your terminal so regardless of what operating system you're on and what your term preferred terminal is you'll always be able to use tmux and let me show it to you if you type tmux um well the first thing i'd mention is if you type tmux um it might say command not installed um and if it does say that then in linux you can type sudo and sudo um if you don't say what user to run it is it says run it as an admin it's called root right so so to install software you have to be root say sudo apt install means install linux software or ubuntu software tmux and so that's how you would install tmux if you got that error and so to run stuff as root you have to put in your password and so in my case i already have tmux okay um but yeah so that's that's what you would do on um mac you would normally use brew which unfortunately does not come with mac so if you as it says it's the missing package manager so if you just copy and paste this into your terminal in mac you'll then be able to should be able to do brew install tmux if you double check that it's available yep it is so brew and apt uh equivalence for mac and linux and i remember when i say linux i'm including windows as linux because it's it is linux so once it's installed if you type tmux you'll get a new screen that looks exactly like your old screen but now it's got a green bar on the bottom and this is what tmux looks like and it behaves the same way as usual um you know one thing is if i kind of like go off the end of the screen it's nice i can use my scroll um if you've got this mouse set up um but you know basically just looks like a normal terminal where things get interesting is that i can add additional windows um and so in tmux everything um almost everything you do tmux starts by pressing the uh key the keyboard shortcut ctrl b ctrl b is the tmux shortcut and so let's say i cd into get and i run jupyter lab i always like to run it from the place where i've kind of got my notebooks and repositories and i'm like oh okay what do i do now well i'll create another github window uh sorry another um tmux pane i should call them tmux pane um and i can create another uh either split them horizontally or vertically so if you hold hit hold hold down ctrl press b nothing happens and then press percent so ctrl b percent and you can see what that's done is it's created a second window over here as opposed to ctrl b double inverted commas which creates another window down here a pane and you can close them in the usual way and remember the usual way is ctrl d and each time you close them they just disappear so i pretty much always do that um now then how do you move around between these different panes depending on how your terminal is configured you might be able to click with your mouse i never do um i just press ctrl b and press arrow keys ctrl b right ctrl b up see how my cursor is moving here i am in the bottom right ctrl b left now i'm in the bottom left ctrl b left up now i'm in the top so that's how you can move around between the panes and then another thing to know is um this window looks very small now this pane looks very small i'd like more room please to get more room you zoom with z so ctrl b z so if i press ctrl b z that makes that pane take up the whole screen and once i'm done you know and i don't want the whole the thing to be maximized anymore i just press ctrl b z again and now it goes back okay um yeah Jeremy what how did you get the four by four right so um we got again so it's let me go back to where it was so um i'm going to first of all split vertically so that'll be ctrl b double quotes sorry ctrl b percent and then i'm going to split the one on the right up and down so ctrl b double quotes and then i'll press ctrl b left to go to the left hand tab the pane i should say and then i'll go ctrl b double quote again and there you've got it and you kind of like there are things you can do to make that automatic but after a while you get so used to it that like i show you when i do it i just go ctrl b percent ctrl b double quote ctrl b left ctrl b double quote and i'm done you know it only takes three seconds um and then the other nice thing about tmux is it sits there running in the background for as long as you like so i can actually detach from this tmux session as long as i don't turn on off my computer by pressing ctrl b d for detach and then i'll close down my whole terminal everything's gone okay don't have a terminal running anymore um oh that's going to be annoying to have to set everything up again get to the right directory rerun jupyter notebook blah blah blah but actually i don't because i detached from tmux so no all i have to do is attach to read tmux again um i do have to be the right person so let me go back to my extra account to attach to tmux again you type tmux a a for attach and everything's back so that is one of the very handy things about tmux and so if you yeah if you've got some long running job or something it's totally fine you can detach if you need to and come back to it later obviously if you reboot your computer it won't work otherwise it should be fine i think they're the main yeah yeah just to confirm if you close any of these windows that ends the process that's killed the process no i just closed the window it didn't close the process but i detached first so ctrl b d to detach and i close the part that it's all gone it's closed sure but i mean that at the beginning when you split into the four and then you close the tree and then went back to the original so for example the one with the jupyter if you close if you close a pane yeah so yeah so like the the pane here i can't close it because it's running a program so the only way to close that would be to actually cancel the program this pane's not running anything so i can close it so i can just hit ctrl d and so that just closes that session then if i do ctrl b double quote it just creates a new session a new a new interactive login if you like so each of these windows are totally separate to each other so if i overhear cd and to walk through two you can see none of the other ones you know these are all like separate copies of bash running this one over this copy over here is actually running jupyter all right there'll be one more doubt uh like can we assess it into a different session from uh team at little yeah so um absolutely so i you know i could SSH into my machine into my GPU machine from here um oh i need to be not jph 00 so let me just do that as somebody else yeah so i could uh ssh into another machine no worries you can even run tmux inside tmux if you want to gets a bit crazy um yeah they're all totally separate um okay so let's so i got jupyter running so i can control click on this url to open it up ah that's interesting so that didn't work because you see how it's wrapped to the next line so i didn't get the fa 91 it's kind of not considered part of it um that's why this didn't log in correctly so what i could do is to um zoom in with control bz and then click on it there we go um the other thing you can do is to set a password which isn't a bad idea um but for now we can just use this it's because it's using this so unique token that it auto creates um okay so because i launched um jupyter lab from inside the git directory that's why i'm here inside the git directory so here's walkthrough too so i could now create a notebook um turn that to a markdown cell so um i strongly recommend learning keyboard shortcuts um which what's the easiest way to see that in the lab i'm much more familiar with classic notebook so here's launch classic notebook which is what i normally use in classic notebook you can hit h to bring up the keyboard shortcuts let's see how to do it in jupyter lab jupyter lab keyboard shortcuts advanced settings editor in the settings menu doesn't sound very friendly settings advanced settings okay that's control comma keyboard keyboard keyboard there we go all right um great so anyway the keyboard shortcut to turn a um change a cell to markdown is just to hit m and so this is now markdown as you see um or to switch it back to code you press y and that's now code another useful quick keyboard shortcut is you can just press one two or three to create a first level second level or third level header or change one's one to a header as you can see um so um walk through sample notebook here is how i calculate one plus one put things in back text to say this is to start it as code here is how i calculate so if you hit shift tab after typing a function it'll tell you the parameters and so forth of a function a equals array 1.0 comma pi over two whatever sign a okay um so by default things get called untitled dot i pi nb which is not a great name so you can rename it to sample whatever now if i close that um it's actually running so that that that python session is still in memory most of the time that doesn't matter unless it's something where you're like training a model on a gpu in which case it continues to use your gpu memory so a couple of things you can do one is rather than closing from the x you can click close and shut down notebook which is ctrl shift q or alternatively you can click the x here all right um since we've got a proper terminal um on our computer we don't really need to use it much but if i you know and we will use it later you can create a terminal inside your browser which is identical to the terminals we've seen before and just like before ctrl b will close it all right so we've now got um another file called sample.i pi nb so we would like to put that into our github repo for other people to to share and just so i put a backup and so it's version control and so forth um so everything you want to do in git you first type git so what you'll often do at this point is type git status which tells you what's in git and what's not in git and so it'll give you a list of untrapped files so these are things you haven't yet got in git so to put it into git you have to commit it um so if you type um so if you type git commit um that'll commit anything that you've added to git so first of all you have to say okay what do i want in my next commit i want sample.i pi nb so git add sample.i pi nb i'll zoom in okay so now this is a it's not untrapped it's now a change to be committed is that we've added a file so now we can commit what we've added by saying git commit and then it'll say okay tell me your commit message and so by default it's opening up an editor called nano and we can change this but nano is probably like the easiest editor to get started with so it's not a bad place to start um so let's put in our commit message for people to see what have you done we added sample notebook and you can see down at the bottom that we can accept by pressing control x and it'll say do you want to save and i'll press y for yes and by default just leave the file name as it is so hit enter okay so that has now added the file to my commit so if i now say git status it's now in a third place it's gone from untrapped to do be committed to be committed and it is now committed and that means it is now actually version controlled on your computer so git actually version controls things on your computer even without using github um in fact originally when git was created by liners 12 volts there was no such thing as github and people kind of sent changes to each other directly rather than going through a server but in this case we are connected to a server and it said oh your your branch so your copy of this repo is ahead of the copy the place that you got it from by one commit so use push to to send your commits back to the server so git push there we go um so now if we do git status again there we go so that's the whole cycle and so if we now go back to github there's our notebook and github does have a basic notebook viewer it's not amazing but it does the job most of the time and so there's our notebook and so here's like a really minimal way of like it's not a blog or anything but you know to just like quickly share things with people this is the easiest way to do it you know and you can just say here's here's a repo and you know you can create as many repos as you like so like don't feel like it's in some way inappropriate to create a repo for one or two notebooks you want to share with somebody it's totally fine you know i generally have kind of a repo i put somewhat temporary things into but you know often when we're kind of sharing something with somebody else for example the bug we found we want to show how to recreate the bug we're just like create a repo just to send somebody an example of a bug for instance so yeah so repositories you can create as many as you like um a really good way to use repositories is let's go to the fastbook repository is it would be nice to have your own copy of the book because you would like to run cells edit things stuff like that so if you clone this right you won't be able to do an ssh clone at all because my because your public key is not in my account you can http clone it but you won't be able to save changes back to github so ideally you'd like your own separate copy of this and so you can create your own separate copy of this by clicking fork and so fork's going to create your own copy so you just say create fork there's a fork's a copy and you can experiment with changes without affecting the original and here you go so it looks exactly the same right but now i can the ssh copy this and then cd so cd dot dot means go to the parent directory which in this case is get get clone paste um actually yeah no that's fine yeah so we'll go get clone there we go and so now it downloads the the whole book and so now if we in fact let's do it let's open up a notebook so let's go back to jupiter lab fastbook feminist basics actually you know what would be good would be let's go into the clean version because this is really the one you want to be experimenting with and so i can now start running cells oh can't run fastai fair enough so um at this point we need to install fastai so we can see here it says condor install -c fastchan fastai so i'm going to copy that except for the condor bit because i want to use mamba so -c remember says to bring it from some other channel so this is not coming from the main channel but from a channel called fastchan so fastchan is a channel that fastai provides where we try to put in you know a lot of the kind of pieces of software that data scientists are likely to want to use okay so we can now say yep that all looks fine so fastai relies on the kind of the whole you know kind of ecosystem of python scientific libraries and since this is a brand new user you know things like matplotlib that's used for plotting for example and scikit-learn that's used for classic machine learning then none of those were there so because it relies on all these it it grabs them all downloads them and installs them can i ask a question while it's downloading please um is your i notice you're installing it in the base directory is that usually how you do it that's how i always do it yes yeah you don't create separate virtual environments never never like okay a lot of people do but i strongly dislike them particularly for beginners or unless you've got some very special reason i always put stuff in the base okay and the other thing i noticed was that the notebooks all use pip yes they do but it won't do anything for you because it says here see if there's a this is a bash thing it says see if there's a directory called slash content which there isn't this exists for something called colab which is a free jupiter server environment which doesn't generally have up-to-date things installed in fact i think they still have fastai version one so this cell will on colab install everything because colab uses pip basically um but yeah won't do anything on our computer um oh and we also need fastbook now fastbook i'm not even sure i'm not sure if there is a conda package at the moment for fastbook so i will use well let's check mamba install minus c fast chan fastbook i have a feeling that won't work oh apparently it does work there you go oh that was easy and actually fastbook includes fast fastai so we could have skipped the whole fastai one fastbook is just a it's basically just a list of dependencies of like all the different things we use in the book um it doesn't really have much code at all of its own it's just a kind of quick and easy way to grab all the stuff that you'll need for the book all right so now we should be able to run this okay um that is actually i think a little out of date i think we could use any sentence piece nowadays and i think we might have that in fast gen 2 sentence piece that's something we use in the nlp chapter yep looks good wow that's a slow download that's beating up at last let's try again okay so now we've got a copy of everything we need so this is like a unusually you know big uh kind of set of dependencies because it's a big book that teaches lots and lots of things but the nice thing is once this works um you know you'll generally find everything you need is gonna is gonna work um okay so at this point you know i've started doing things you know maybe i'll make some notes to myself um to install um we have to go remember install basically this is all we'd need would be mamper install minus c fastchan fastbook sentence piece that would actually be all you would need to do um so if i save this and so now you know we've created a note to ourselves in our own copy of the book so we'll close that and if we now cd to fastbook git status you can see it tells us we've modified that file so we would like to save that back to our copy um typing git add and then git minus m and then changing things in the editor is a bit slow so a shortcut is if you type git commit minus am that minus a means add everything that's not committed and this this m here says i'm going to put a message right here on the command line it's got to be in quotes um change m nist uh maybe add install notes so at that point if i type git status you can see now it's gone ahead and added it and committed it and it now says all right we're ready to push so if i take git push that saved that change so that change has not been saved to fastai's copy of the book of course but it has been saved to the jph fork so at this point my fork is one commit ahead of fastai right so that is i've made changes that are not in fastai's copy and so i could see what commits there are and that and here's all the commits that are in the one i forked and here's my addition and here's the change which says that i added this one cell okay i think that's probably about enough for one day does anyone have any questions or comments about that um the only one i found was that sometimes if you sort of we started off creating a repo within github sometimes i've done the reverse where i've created the repo on my computer and then had a few issues trying to get it into github and yeah yeah okay well let's add that promise to things to do in a future session i find it easier to do it in github so i actually always try to do it that way um like literally like because because i find it so easy like i always have to look it up to remind myself how to do it otherwise um so often i'll like i'll create it in github pull it and then copy over things that are on my computer you know like that's the really lazy way to do it um but let's do how to create a git repo locally all right let me pop that all right thanks gang um so we're doing tuesday wednesday thursday friday this week so i hope to see you then, thanks for joining us for Toronto, bye, thanks bye