Getting Started with NLP and spaCy Transcripts
Chapter: Setup
Lecture: Some things about Jupyter

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So definitely feel free to skip this particular video if you are already very familiar with Jupyter.
0:08 But I figured since I'll be using Jupyter a whole lot, I might as well show you how I like to use it.
0:14 This is especially going to be useful if you're less familiar with Jupyter. If you are though, again, definitely feel free to skip.
0:20 The way Jupyter notebooks work is that you have these cells. So you can add cells by clicking, but you can also just type some code in a cell.
0:29 So I'll type 1+1 here, and then what I can do is I can hit Ctrl+Enter to run the code in this one cell.
0:39 But you'll notice that whenever I hit Ctrl+Enter, the cursor doesn't really move.
0:44 The only thing that you really see change is that the number here updates.
0:48 So this is the fifth cell that's running in a way because it's the fifth cell that the interpreter has seen.
0:53 However, what I can also do is I can hit Shift+Enter. And when I do that, you'll notice that the blue line actually moves down,
1:02 which also means that the cursor has moved to a new cell. And that's kind of a thing in Jupyter.
1:08 You will typically think in cells, and that also means that sometimes you're going to want to shift between them.
1:15 And there's also a little concept that's good to be aware of, which is the concept of being in a cell or kind of just outside of it.
1:22 So right now you can see this blue line over here, right? And just let me hit Enter.
1:28 You'll notice that when I do that, the cursor actually moves inside of the cell, and I can start typing.
1:33 But now if I were to hit Escape, you will notice that there's no longer a cursor in this cell.
1:40 And you will also notice that the arrow keys can actually be used now to move between these different cells.
1:46 So again, I can hit Enter to enter a cell, and I can update the code. And I can hit Escape to exit and move around.
1:55 In this case, the orange indicates that the cell is new and hasn't been executed yet, so I can just run that.
2:02 But there is a notion of being in a cell and outside of it. If you want to move around these cells, you've got to be outside of the cell.
2:09 Once you're in, then you can move around within. Now, an extra thing that's just kind of good to know is that cells can be of different types.
2:16 So if I'm outside of a cell, I can hit M to change the cell type to Markdown.
2:24 Note that you can do the same thing by going to this little UI widget over here.
2:30 And I can say, well, I want this to be either a code or I want it to be Markdown. But the shortcuts are pretty easy to remember.
2:37 If you want to turn a cell into Markdown, you just hit M. And the only weird thing is the other shortcut, which is turning it into code.
2:44 The shortcut for that is Y. So again, inside of the cell, you can write code. Outside of the cell, you can move around.
2:53 But you can also change the cell type. You can change it into Markdown, such that you can have a nice heading and some text.
3:00 But if you want to turn the cell into code, you first have to make sure that you're outside of the cell.
3:08 And then you hit Y or you use this little widget over here. So as far as navigation between cells goes, that's about it.
3:18 There is one extra thing that comes to mind, though, that I guess I also want to show. And that is that I can import Python code as you would normally.
3:27 So I'll go ahead and import spaCy here. And then, because I'm dealing with Python objects and modules, there are actually some helpers around as well.
3:38 So one thing that I could do is I could put a question mark in front of this module over here to kind of get some information out.
3:48 And this module has a function called spaCy.load. And by putting this one question mark in front,
3:55 you'll notice that I get some information, like the signature of the function, but I also get the full doc string.
4:01 So this is basically documentation that's at my disposal as well. If you're really eager, what you can also do is you could put two question marks
4:08 in front of a function or an object, run the cell, and then you will also get the implementation.
4:13 So the actual code that's inside of the function is then also something that you can inspect.
4:19 I don't know if we're going to be using this a whole bunch, but it's definitely useful when you're trying to learn a new library.
4:24 There's one final tip, and this is something I won't use in these videos,
4:28 but if you're new and you're learning, this is definitely something that might help out.
4:31 What you can do is you can go to File here and go to New Launcher. And then there's this one tab over here called Show Contextual Help. Let's click it.
4:43 I will close this window over here. And now I will move my cursor over to this spaCy.load over here. Notice what happens to this contextual helper.
4:54 The whole point of this contextual help is to show you the help text of whatever thing your cursor is on over here. And that can be extremely useful,
5:05 because basically it means you'll have access to any docstring as you are working with code.
5:10 And when you're learning a new library, that can be especially helpful. Another thing that you can also do while inspecting new code is
5:17 you can have an open/close bracket, and then you can hit Shift+Tab to also get the signature information.
5:23 And there's also some autocompletion stuff inside of the notebook, but especially when dealing with a new library,
5:28 I found this contextual helper to be this sort of missing feature that more people should maybe know about.
5:33 Anyway, this was my super brief introduction to Jupyter. It should be relatively intuitive as is, but hopefully to people who are new to Jupyter,
5:40 this was a just enough introduction.


Talk Python's Mastodon Michael Kennedy's Mastodon