Introduction to Jupyter Notebooks
In this course, we will program Neural networks, using Python, in Jupyter Notebooks, which some of you might not have extensive experience in. Therefore, the first part of this first exercise will be an introduction to Jupyter Notebooks.
Back-propagation
In the second part of the you will practice further working with Jupyter Notebooks by performing a single forward and backward step for a very simple ffANN.
The Jupyter Notebook is an programming environment that allows you to mix code with formatted text, equations and visualizations. It shares som similarities with Rmarkdown and Rstudio, which some of you mnight be familiar with, but while Rmarkdown was developed focusing on the R language, Jupyter Notebooks was developed focusing on the Pyhton language. (however, both these tools has since further developed to include also other programming languages.) Jupyter notebooks is web-application; you open documents, edit and compile them in a web-browser on your laptop. It is an open-source application that is continuopusly developed. by a large and dynamic community. It can be used to document your daily bioinformatics work, create nice reports or slides for a presentation.
cd
into the nndl folder.nndl_python-yaml
to the nndl folder, e.g.,
curl -o nn_dl_python.yaml https://raw.githubusercontent.com/NBISweden/workshop-neural-nets-and-deep-learning/master/common_assets/conda_envs/nn_dl_python.yaml
or alternatively
wget https://raw.githubusercontent.com/NBISweden/workshop-neural-nets-and-deep-learning/master/common_assets/conda_envs/nn_dl_python.yaml
conda env create -f nndl_python-yaml
(Note! you should already have conda
installed on your laptop, else look at the prerequisite notesXXX)conda activate
The Jupyter Notebook web application is the user interface. It opens local html pages in your browser and allows you to edit and run the code and markdown in your notebook. Your "home page" is the Notebook dashboard window. Let's open this window.
jupyter notebook
The Notebook dashboard contains
The notebook is a file (with suffix .ipynb) that will store the code and markdown you write to fulfil the purpose of the notebook. Notebook files are accessed using the notebook editor. To open a new file in the editor:
new
and select _Python [conda env: nn_dlpython] in the scroll-down menuThe editor window comprise:
We will below just go through a selection of menu or toolbar items. For more details, refer to the Jupyter Notebook documentation. A interactive tour of the user interface can also be started from the Help menu item User Interface Tour.
Note 1! Your terminal will show log messages from thew Jupyter Notebook session and will not be accessible for normal commands -- this is the expectd behaviour and not an error.
Note2! It is convenient to use keyboard shortcuts for many commands. We will below mention some of these, but many of the keyboard shortcuts can be found in the different menus after the relevant command. This teremial is usually kleft as is and new terminals are opened for any required bash commands.
.ipynb
file with an appropriate name, e.g., FantabulousCounter.ipynb
byCmd-s
(Mac) ctrl-s
(PC)A Jupyter notebook consists of a sequence of cells. Code or markdown text is written in the cells, which then can be executed. There are two main type of cell:
enter
to enter edit mode from command mode, or click inside the cellesc
to enter edit mode from edit mode, or click outside a cell.Add some text in the cell, include some markdown formatting if you like (see Markdown cheatsheet, e.g.:
# The phenomenal counting machine
This amazing counting machine will count from 1 to 9
and print the consecutive sum of these numbers... and
that is not all; it will then do it backwards and blindfolded.
Execute the cell by, either
Cmd-enter
(Mac) ctrl-enter
(PC)
This converts the cell to a Compiled cell:To get back to the Edit mode, double-click in the cell:
Try going back and forth between Compiled and Edit mode
+
icon in the toolbar,B
(this only works in Command mode)Ensure that the new cell is a Code cell and in Edit mode, and typesome python code in the cell, e.g.:
print("Look -- no hands!")
sum = 0
for i in range(1,10):
sum += i
print(i,sum)
print("And now, without seeing!")
sum = 0
for i in range(10,1,-1):
sum += i
print("X",sum)
You should see something like:
dd
(this only works in Command mode)Running
tab. It should look something like this:
Terminals
(which usually is empty) and a list of running Notebooks
. FantabulousCounter.ipynb
) is still listed in the running Notebooks
list. Clearly, just closing the browser window does not actually terminate the notebook!Running
tab orFile
tab
of the Notebook dashboard window. Try it!Running
tab of the Notebook dashboard browser window and click
Shutdown
in the row of the notebook, you want to shut down (e.g., FantabulousCounter.ipynb
):FantabulousCounter.ipynb
). You will see a message about Dead kernel...
(this is simply because you killed the kernel in item 5.):Don't restart
and then just close the window. (Note! You can also close the browser window first and then perform item 5.)
Quit
in the upper righ-hand corner:ctrl-c
in the terminal where you started the Jupyter Notebook session.